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/compiler.rs | |
| parent | 07de510d83f62e5fa10f9b801fe4f0ed943f9469 (diff) | |
| download | sylt-b205748bde51c551468a8dc89123f85b67c660dd.tar.gz | |
solve edge case for constants
Diffstat (limited to 'src/compiler.rs')
| -rw-r--r-- | src/compiler.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index 6607c7f..c0dacec 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -914,12 +914,19 @@ 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] { + let needs_linking = block.borrow().upvalues.len() != 0; + block.borrow_mut().constant = needs_linking; + } else { + unreachable!(); } return; } |
