From a8309ffa30e9f2a9432d9bf3d9fea5d954b1e462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Sat, 30 Jan 2021 09:57:50 +0100 Subject: fix closures in closure bug --- src/compiler.rs | 5 ++++- src/vm.rs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index 347abe6..92bf3fc 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -472,6 +472,9 @@ impl Compiler { let mut return_type = Type::Void; let mut function_block = Block::new(&name, &self.current_file, self.line()); + let block_id = self.blocks.len(); + self.blocks.push(Rc::new(RefCell::new(Block::new(&name, &self.current_file, self.line())))); + let _ret = push_frame!(self, function_block, { loop { match self.peek() { @@ -538,8 +541,8 @@ impl Compiler { let func = Op::Constant(Value::Function(Vec::new(), Rc::clone(&function_block))); + self.blocks[block_id] = function_block; block.add(func, self.line()); - self.blocks.push(function_block); } fn variable_expression(&mut self, block: &mut Block) { diff --git a/src/vm.rs b/src/vm.rs index 849aaa1..e2b9e57 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -470,9 +470,9 @@ impl VM { self.stack.push(Value::Function(Vec::new(), block.clone())); let mut types = Vec::new(); - for (slot, is_up, _) in block.borrow().ups.iter() { + for (slot, is_up, ty) in block.borrow().ups.iter() { if *is_up { - types.push(Type::Void); + types.push(ty.clone()); } else { types.push(self.stack[*slot].as_type()); } -- cgit v1.2.1