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/// List all available embedded stdlib modules
37pub fn list_stdlib() -> Vec<&'static str> {
38    STDLIB.keys().copied().collect()
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_imath_stdlib_exists() {
47        assert!(has_stdlib("imath"));
48        let content = get_stdlib("imath").unwrap();
49        assert!(content.contains("abs"));
50    }
51
52    #[test]
53    fn test_fmath_stdlib_exists() {
54        assert!(has_stdlib("fmath"));
55        let content = get_stdlib("fmath").unwrap();
56        assert!(content.contains("f.abs"));
57    }
58
59    #[test]
60    fn test_nonexistent_stdlib() {
61        assert!(!has_stdlib("nonexistent"));
62        assert!(get_stdlib("nonexistent").is_none());
63    }
64}