diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-17 21:01:12 +0100 |
|---|---|---|
| committer | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-17 21:01:12 +0100 |
| commit | b205748bde51c551468a8dc89123f85b67c660dd (patch) | |
| tree | ee27f9fd8f02c20a05227b350956f549acf28978 /src/vm.rs | |
| parent | 07de510d83f62e5fa10f9b801fe4f0ed943f9469 (diff) | |
| download | sylt-b205748bde51c551468a8dc89123f85b67c660dd.tar.gz | |
solve edge case for constants
Diffstat (limited to 'src/vm.rs')
| -rw-r--r-- | src/vm.rs | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -557,6 +557,13 @@ impl VM { Value::Function(_, block) => { self.push(Value::Function(Vec::new(), block.clone())); + if block.borrow().constant && !block.borrow().linked { + error!(self, + ErrorKind::InvalidProgram, + format!("Calling function '{}' before all captured variables are declared.", + block.borrow().name)); + } + let mut types = Vec::new(); for (slot, is_up, ty) in block.borrow().upvalues.iter() { if *is_up { @@ -667,10 +674,10 @@ impl VM { } Op::Link(slot) => { - println!("{:?}", self.constants); - println!("{:?} - {}", self.constant(slot), slot); match self.constant(slot).clone() { - Value::Function(_, _) => {} + Value::Function(_, block) => { + block.borrow_mut().linked = true; + } value => { error!(self, ErrorKind::TypeError(op, vec![Type::from(&value)]), @@ -733,7 +740,7 @@ impl VM { } _ => { error!(self, - ErrorKind::TypeError(op, vec![Type::from(&self.stack[new_base])]), + ErrorKind::InvalidProgram, format!("Tried to call non-function {:?}", self.stack[new_base])); } } @@ -773,7 +780,7 @@ impl VM { }); if self.print_blocks { - println!("\n [[{}]]\n", "TYPECHECK".purple()); + println!("\n [[{} - {}]]\n", "TYPECHECKING".purple(), self.frame().block.borrow().name); self.frame().block.borrow().debug_print(); } @@ -832,7 +839,7 @@ mod tests { f := fn i: int { i() }", - [ErrorKind::TypeError(_, _)]); + [ErrorKind::InvalidProgram]); test_string!(wrong_params, " f : fn -> int = fn a: int -> int {}", |
