aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-01-30 09:57:50 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-01-30 17:10:57 +0100
commita8309ffa30e9f2a9432d9bf3d9fea5d954b1e462 (patch)
tree642c9f72e24cc727e5e99b1a9bbf5e260fb4340d /src
parent52042f3cd5e44cffc4d6badc28ff98ea310f050c (diff)
downloadsylt-a8309ffa30e9f2a9432d9bf3d9fea5d954b1e462.tar.gz
fix closures in closure bug
Diffstat (limited to 'src')
-rw-r--r--src/compiler.rs5
-rw-r--r--src/vm.rs4
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());
}