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/compiler.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/compiler.rs')
| -rw-r--r-- | src/compiler.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index 6bb749c..7b9fd9a 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -796,10 +796,10 @@ impl Compiler { let mut args = Vec::new(); let mut return_type = Type::Void; - let mut function_block = Block::new(&name, &self.current_file, self.line()); + let mut function_block = Block::new(&name, &self.current_file); let block_id = self.blocks.len(); - let temp_block = Block::new(&name, &self.current_file, self.line()); + let temp_block = Block::new(&name, &self.current_file); self.blocks.push(Rc::new(RefCell::new(temp_block))); let _ret = push_frame!(self, function_block, { @@ -961,12 +961,18 @@ impl Compiler { // Remove the function, since it's a constant and we already // added it. block.ops.pop().unwrap(); - if let Entry::Occupied(entry) = self.unknown.entry(String::from(name)) { + let slot = if let Entry::Occupied(entry) = self.unknown.entry(String::from(name)) { let (_, (slot, _)) = entry.remove_entry(); self.constants[slot] = self.constants.pop().unwrap(); - add_op(self, block, Op::Link(slot)); + slot } else { - add_op(self, block, Op::Link(self.constants.len() - 1)); + self.constants.len() - 1 + }; + add_op(self, block, Op::Link(slot)); + if let Value::Function(_, block) = &self.constants[slot] { + block.borrow_mut().mark_constant(); + } else { + unreachable!(); } return; } @@ -1428,7 +1434,7 @@ impl Compiler { let main = Variable::new("/main/", false, Type::Void); let _ = self.define(main); - let mut block = Block::new(name, file, 0); + let mut block = Block::new(name, file); while self.peek() != Token::EOF { self.statement(&mut block); expect!(self, Token::Newline | Token::EOF, |
