Skip to main content

wolf_std/
lib.rs

1//! The declarations of the standard library (spec chapter 7).
2//!
3//! The std modules are ordinary `.wolf` files compiled into the compiler. Functions, methods and
4//! types marked `intrinsic` have no body; the backends implement them.
5
6/// One module of the standard library.
7#[derive(Clone, Copy, Debug)]
8pub struct StdModule {
9    /// The module path, for example `std.io`.
10    pub path: &'static str,
11    /// The name shown in diagnostics, for example `<std>/io.wolf`.
12    pub file_name: &'static str,
13    /// The source text.
14    pub source: &'static str,
15}
16
17/// The path of the prelude module. It cannot be imported; its public names (except `Never`)
18/// are visible everywhere (spec chapter 6, section 3.3).
19pub const PRELUDE: &str = "std.prelude";
20
21/// Names of the prelude module that are not visible to users.
22pub const HIDDEN_PRELUDE_NAMES: &[&str] = &["Never"];
23
24macro_rules! module {
25    ($path:literal, $file:literal) => {
26        StdModule {
27            path: $path,
28            file_name: concat!("<std>/", $file),
29            source: include_str!(concat!("../std/", $file)),
30        }
31    };
32}
33
34/// Every std module, in a fixed order.
35pub const MODULES: &[StdModule] = &[
36    module!("std.prelude", "prelude.wolf"),
37    module!("std.io", "io.wolf"),
38    module!("std.string", "string.wolf"),
39    module!("std.list", "list.wolf"),
40    module!("std.map", "map.wolf"),
41    module!("std.math", "math.wolf"),
42    module!("std.fs", "fs.wolf"),
43    module!("std.process", "process.wolf"),
44];