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