1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! Embedded standard-library sources for the v1 core (`core.*`).
//!
//! The Bock core standard library ships *embedded in the `bock` binary* as
//! Bock source. Each core module is plain Bock source (its public surface),
//! compiled through the exact same multi-file pipeline as user code: the CLI
//! commands (`check`, `build`, `run`) prepend the parsed core sources to the
//! parsed-files set before the user-file loop, so a core module's
//! `module core.<name>` declaration lands in the
//! [`bock_air::registry::ModuleRegistry`] before any user module resolves
//! `use core.<name>.{...}` against it — with no special-casing in the name
//! resolver or type checker.
//!
//! # Embedding
//!
//! The embedded set is produced at compile time by the crate's `build.rs`,
//! which walks `stdlib/core/**/*.bock` and emits a `&[(logical_path, source)]`
//! table baked into the binary via `include_str!`. As a result a built `bock`
//! resolves `core.*` with no filesystem access — from any working directory,
//! inside or outside the repo. To add a core module, drop its source under
//! `stdlib/core/<name>/<name>.bock`; the build script picks it up automatically.
//!
//! # `$BOCK_STDLIB` override (dev-only)
//!
//! When the `BOCK_STDLIB` environment variable is set, [`core_sources`] reads
//! the core sources from that directory on disk (walking `<dir>/**/*.bock`)
//! instead of using the embedded copy. This lets compiler developers iterate
//! on stdlib sources without a rebuild. The override is intentionally
//! undocumented for end users.
use ;
/// One embedded core-stdlib source: its logical (repo-relative) path and the
/// source text itself.
/// The embedded core sources, generated by `build.rs` from `stdlib/core/**`.
///
/// Each entry is `(logical_path, source_text)`. The logical path is the
/// repo-relative `stdlib/core/...` path (for diagnostic rendering); the source
/// text is baked in via `include_str!`.
const EMBEDDED: & = include!;
/// Returns every embedded core-stdlib source, in a deterministic order.
///
/// When `BOCK_STDLIB` is set, the sources are read from that directory on disk
/// instead (dev-only override); see the module docs. Each returned
/// [`StdlibSource`] flows through the same parse -> dependency-sort -> compile
/// pipeline as user files, landing in the registry before user modules.
/// Reads the core sources from a `$BOCK_STDLIB` directory on disk.
///
/// Walks `<dir>/**/*.bock` and assigns each file a logical path of
/// `stdlib/<relative-to-dir>` so diagnostics render against a stable,
/// repo-shaped location. Sources are returned in sorted order for determinism.
/// Recursively collect `*.bock` files under `dir`, recording each as
/// `(path_relative_to_root, absolute_path)`.