Skip to main content

seqc/
stdlib_embed.rs

1//! Embedded Standard Library
2//!
3//! Contains stdlib modules embedded at compile time.
4//! This makes seqc fully self-contained - no need for external stdlib files.
5
6use std::collections::HashMap;
7use std::sync::LazyLock;
8
9/// Embedded stdlib files (name -> content)
10static STDLIB: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
11    let mut m = HashMap::new();
12    m.insert("imath", include_str!("../stdlib/imath.seq"));
13    m.insert("fmath", include_str!("../stdlib/fmath.seq"));
14    m.insert("json", include_str!("../stdlib/json.seq"));
15    m.insert("yaml", include_str!("../stdlib/yaml.seq"));
16    m.insert("http", include_str!("../stdlib/http.seq"));
17    m.insert("stack-utils", include_str!("../stdlib/stack-utils.seq"));
18    m.insert("map", include_str!("../stdlib/map.seq"));
19    m.insert("list", include_str!("../stdlib/list.seq"));
20    m.insert("son", include_str!("../stdlib/son.seq"));
21    m.insert("signal", include_str!("../stdlib/signal.seq"));
22    m.insert("zipper", include_str!("../stdlib/zipper.seq"));
23    m
24});
25
26/// Get an embedded stdlib module by name
27pub fn get_stdlib(name: &str) -> Option<&'static str> {
28    STDLIB.get(name).copied()
29}
30
31/// Check if a stdlib module exists (embedded)
32pub fn has_stdlib(name: &str) -> bool {
33    STDLIB.contains_key(name)
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn test_imath_stdlib_exists() {
42        assert!(has_stdlib("imath"));
43        let content = get_stdlib("imath").unwrap();
44        assert!(content.contains("abs"));
45    }
46
47    #[test]
48    fn test_fmath_stdlib_exists() {
49        assert!(has_stdlib("fmath"));
50        let content = get_stdlib("fmath").unwrap();
51        assert!(content.contains("f.abs"));
52    }
53
54    #[test]
55    fn test_nonexistent_stdlib() {
56        assert!(!has_stdlib("nonexistent"));
57        assert!(get_stdlib("nonexistent").is_none());
58    }
59}