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
use smpl::ModuleId;
use smpl::prelude::ParsedModule;

use crate::vm_i::BuiltinFn;

pub struct VmModule {
    pub parsed: ParsedModule,
    pub builtins: Vec<(String, BuiltinFn)>,
}

impl VmModule {
    pub fn new(m: ParsedModule) -> VmModule {
        VmModule::with_builtins(m, Vec::new())
    }

    pub fn with_builtins(m: ParsedModule, v: Vec<(String, BuiltinFn)>) -> VmModule {
        VmModule {
            parsed: m,
            builtins: v,
        }
    }

    pub fn add_builtin(mut self, fn_name: &str, builtin: BuiltinFn) -> VmModule {
        self.builtins.push((fn_name.to_string(), builtin));
        self
    }

    pub fn id(&self) -> ModuleId {
        self.parsed.id()
    }
}