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("result", include_str!("../stdlib/result.seq"));
19    m.insert("map", include_str!("../stdlib/map.seq"));
20    m.insert("list", include_str!("../stdlib/list.seq"));
21    m.insert("son", include_str!("../stdlib/son.seq"));
22    m
23});
24
25/// Get an embedded stdlib module by name
26pub fn get_stdlib(name: &str) -> Option<&'static str> {
27    STDLIB.get(name).copied()
28}
29
30/// Check if a stdlib module exists (embedded)
31pub fn has_stdlib(name: &str) -> bool {
32    STDLIB.contains_key(name)
33}
34
35/// List all available embedded stdlib modules
36pub fn list_stdlib() -> Vec<&'static str> {
37    STDLIB.keys().copied().collect()
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_imath_stdlib_exists() {
46        assert!(has_stdlib("imath"));
47        let content = get_stdlib("imath").unwrap();
48        assert!(content.contains("abs"));
49    }
50
51    #[test]
52    fn test_fmath_stdlib_exists() {
53        assert!(has_stdlib("fmath"));
54        let content = get_stdlib("fmath").unwrap();
55        assert!(content.contains("f.abs"));
56    }
57
58    #[test]
59    fn test_nonexistent_stdlib() {
60        assert!(!has_stdlib("nonexistent"));
61        assert!(get_stdlib("nonexistent").is_none());
62    }
63}