Skip to content

Commit 6d3bd9a

Browse files
Fix(parser): Destructure 4-tuple in finalize_prev_slots function recursion.
1 parent eac621c commit 6d3bd9a

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

compiler/src/modules/parser/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ impl<'src, I: Iterator<Item = Token>> Parser<'src, I> {
267267
}
268268

269269
self.chunk.emit(OpCode::ReturnValue, 0);
270+
self.chunk.finalize_prev_slots();
270271
(self.chunk, self.errors)
271272
}
272273
}

compiler/src/modules/parser/types.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,26 @@ impl SSAChunk {
131131
self.name_index.insert(n.to_string(), i);
132132
i
133133
}
134+
135+
pub fn finalize_prev_slots(&mut self) {
136+
let mut ps: Vec<Option<u16>> = vec![None; self.names.len()];
137+
for (i, name) in self.names.iter().enumerate() {
138+
if let Some(pos) = name.rfind('_') {
139+
if let Ok(ver) = name[pos+1..].parse::<u32>() {
140+
if ver > 0 {
141+
let prev = format!("{}_{}", &name[..pos], ver - 1);
142+
if let Some(&j) = self.name_index.get(&prev) {
143+
ps[i] = Some(j);
144+
}
145+
}
146+
}
147+
}
148+
}
149+
self.prev_slots = ps;
150+
for (_, body, _, _) in &mut self.functions {
151+
body.finalize_prev_slots();
152+
}
153+
}
134154
}
135155

136156
/*

compiler/src/modules/vm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'a> VM<'a> {
235235
let v = self.pop()?;
236236
let slot = op as usize;
237237
slots[slot] = Some(v);
238-
if let Some(prev) = prev_slots[slot] { slots[prev] = Some(v); }
238+
if let Some(prev) = prev_slots[slot] { slots[prev as usize] = Some(v); }
239239

240240
if self.heap.needs_gc() {
241241
self.collect(slots); // Garbage collector safepoint; store is the only opcode that grows the heap unboundedly

0 commit comments

Comments
 (0)