aboutsummaryrefslogtreecommitdiff
path: root/crates/sloth_vm/src/sloth_std/mod.rs
blob: 56e166c21890aed65fbe685de17d5249ccb5c69e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::collections::HashMap;

use once_cell::sync::Lazy;

use crate::native::NativeFunction;

pub mod file;
pub mod rand;
pub mod stdio;
pub mod term;
pub mod time;

pub static NATIVE_LIBRARY: Lazy<HashMap<&'static str, NativeFunction>> = Lazy::new(|| {
    let mut map = HashMap::new();

    // rand
    map.insert("rand$gen", rand::GEN_FUNCTION);
    map.insert("rand$gen_range", rand::GEN_RANGE_FUNCTION);

    // stdio
    map.insert("write", stdio::WRITE_FUNCTION);
    map.insert("writeln", stdio::WRITELN_FUNCTION);
    map.insert("read", stdio::READ_FUNCTION);

    // term
    map.insert("term$clear", term::TERM_CLEAR);
    map.insert("term$setpos", term::TERM_SETPOS);

    // filesystem
    map.insert("file$read", file::FILE_READ);
    map.insert("file$write", file::FILE_WRITE);

    // time
    map.insert("wait", time::WAIT);

    map
});