diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-01-29 21:01:29 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-01-29 21:01:29 +0100 |
| commit | 674695d7e28f03218aa5a3facd933b87d508ea7d (patch) | |
| tree | 582118c95770f2834b802f58bb3c834d7fd0f2e9 /src/vm.rs | |
| parent | 1d4916ed80ceac20a7dac4e500a200e0e03574e7 (diff) | |
| download | sylt-674695d7e28f03218aa5a3facd933b87d508ea7d.tar.gz | |
??
Diffstat (limited to 'src/vm.rs')
| -rw-r--r-- | src/vm.rs | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -295,6 +295,7 @@ pub struct VM { print_ops: bool, extern_functions: Vec<RustFunction>, + } enum OpResult { @@ -303,7 +304,7 @@ enum OpResult { } impl VM { - pub fn new(functions: &[(String, RustFunction)]) -> Self { + pub fn new() -> Self { Self { upvalues: HashMap::new(), @@ -313,7 +314,7 @@ impl VM { print_blocks: false, print_ops: false, - extern_functions: functions.iter().map(|(_, f)| *f).collect() + extern_functions: Vec::new() } } @@ -627,7 +628,7 @@ impl VM { return Ok(OpResult::Continue); } Value::ExternFunction(slot) => { - let extern_func = self.extern_functions[*slot]; + let extern_func = self.extern_functions[slot]; let res = extern_func(&self.stack[new_base+1..]); self.stack.truncate(new_base); self.stack.push(res); @@ -682,6 +683,7 @@ impl VM { pub fn run(&mut self, prog: &Prog) -> Result<(), Error>{ let block = Rc::clone(&prog.blocks[0]); self.blobs = prog.blobs.clone(); + self.extern_functions = prog.functions.clone(); self.stack.clear(); self.frames.clear(); @@ -941,6 +943,7 @@ impl VM { let mut errors = Vec::new(); self.blobs = prog.blobs.clone(); + self.extern_functions = prog.functions.clone(); for block in prog.blocks.iter() { errors.append(&mut self.typecheck_block(Rc::clone(block))); } |
