diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-18 19:51:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-18 19:51:59 +0100 |
| commit | f7bf054ac41f6bc31f1f6c4229357cca36f1d708 (patch) | |
| tree | d6cc2e077c96ce0cfb683c0e3e0c2ab3fe4b997c /src/vm.rs | |
| parent | 6bb72c7bbe2bbb1b627809d4b52f44a77bdb4b33 (diff) | |
| parent | 75b2027c7b545b9827607f17ea7444f67622999d (diff) | |
| download | sylt-f7bf054ac41f6bc31f1f6c4229357cca36f1d708.tar.gz | |
Merge pull request #70 from FredTheDino/fix-constant-bug
Fix constant bug
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().needs_linking() { + 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().link(); + } 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(); } @@ -833,7 +840,7 @@ mod tests { i() } f", - [ErrorKind::TypeError(_, _)]); + [ErrorKind::InvalidProgram]); test_string!(wrong_params, " f : fn -> int = fn a: int -> int {} |
