Skip to content

Commit 03b292a

Browse files
committed
Create separate prim-constants crate
1 parent b941d24 commit 03b292a

File tree

14 files changed

+41
-22
lines changed

14 files changed

+41
-22
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler-core/building/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ lock_api = "0.4.13"
1313
lowering = { version = "0.1.0", path = "../lowering" }
1414
parking_lot = "0.12.4"
1515
parsing = { version = "0.1.0", path = "../parsing" }
16+
prim-constants = { version = "0.1.0", path = "../prim-constants" }
1617
resolving = { version = "0.1.0", path = "../resolving" }
1718
rustc-hash = "2.1.1"
1819
stabilizing = { version = "0.1.0", path = "../stabilizing" }

compiler-core/building/src/prim.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,20 @@
11
use std::{fs::File, io::Write, sync::LazyLock};
22

33
use files::Files;
4+
use prim_constants::MODULE_MAP;
45
use tempfile::{Builder, TempDir};
56
use url::Url;
67

78
use crate::QueryEngine;
89

910
pub const SCHEME: &str = "prim";
10-
pub const PRIM: &str = include_str!("prim/Prim.purs");
11-
pub const PRIM_BOOLEAN: &str = include_str!("prim/Prim.Boolean.purs");
12-
pub const PRIM_COERCE: &str = include_str!("prim/Prim.Coerce.purs");
13-
pub const PRIM_INT: &str = include_str!("prim/Prim.Int.purs");
14-
pub const PRIM_ORDERING: &str = include_str!("prim/Prim.Ordering.purs");
15-
pub const PRIM_ROW: &str = include_str!("prim/Prim.Row.purs");
16-
pub const PRIM_ROW_LIST: &str = include_str!("prim/Prim.RowList.purs");
17-
pub const PRIM_SYMBOL: &str = include_str!("prim/Prim.Symbol.purs");
18-
pub const PRIM_TYPE_ERROR: &str = include_str!("prim/Prim.TypeError.purs");
1911

2012
pub fn configure(engine: &mut QueryEngine, files: &mut Files) {
21-
for (name, content) in [
22-
("Prim", PRIM),
23-
("Prim.Boolean", PRIM_BOOLEAN),
24-
("Prim.Coerce", PRIM_COERCE),
25-
("Prim.Int", PRIM_INT),
26-
("Prim.Ordering", PRIM_ORDERING),
27-
("Prim.Row", PRIM_ROW),
28-
("Prim.RowList", PRIM_ROW_LIST),
29-
("Prim.Symbol", PRIM_SYMBOL),
30-
("Prim.TypeError", PRIM_TYPE_ERROR),
31-
] {
13+
for (name, content) in MODULE_MAP {
3214
let path = format!("{SCHEME}://localhost/{name}.purs");
33-
let id = files.insert(path, content);
15+
let id = files.insert(path, *content);
3416

35-
engine.set_content(id, content);
17+
engine.set_content(id, *content);
3618
engine.set_module_file(name, id);
3719
}
3820
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "prim-constants"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
macro_rules! define {
2+
($($const:ident, $path:expr, $name:expr $(;)?)+) => {
3+
$(
4+
pub const $const: &str = include_str!($path);
5+
)+
6+
7+
pub const MODULE_MAP: &[(&str, &str)] = &[
8+
$(
9+
($name, $const),
10+
)+
11+
];
12+
};
13+
}
14+
15+
define!(
16+
PRIM, "prim/Prim.purs", "Prim";
17+
PRIM_BOOLEAN, "prim/Prim.Boolean.purs", "Prim.Boolean";
18+
PRIM_COERCE, "prim/Prim.Coerce.purs", "Prim.Coerce";
19+
PRIM_INT, "prim/Prim.Int.purs", "Prim.Int";
20+
PRIM_ORDERING, "prim/Prim.Ordering.purs", "Prim.Ordering";
21+
PRIM_ROW, "prim/Prim.Row.purs", "Prim.Row";
22+
PRIM_ROW_LIST, "prim/Prim.RowList.purs", "Prim.RowList";
23+
PRIM_SYMBOL, "prim/Prim.Symbol.purs", "Prim.Symbol";
24+
PRIM_TYPE_ERROR, "prim/Prim.TypeError.purs", "Prim.TypeError";
25+
);

0 commit comments

Comments
 (0)