Skip to content

Commit

Permalink
fix: shadow mapping must always allocate new registers
Browse files Browse the repository at this point in the history
  • Loading branch information
sno2 committed Oct 31, 2024
1 parent 90be32e commit 761a639
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 5 additions & 5 deletions examples/shadow.vl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(let ((a 2))
(+ a (let ((a 4))
(+ a (let ((a 6))
a
))
))
(+ (let ((a 4))
(+ (let ((a 6))
a
) a)
) a)
)
15 changes: 9 additions & 6 deletions src/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -589,17 +589,20 @@ fn genExpression(cg: *CodeGen, exe: *Executable, is_tail: bool, comptime is_type
i -= 1;
const let = cg.let_stack.items[i];
const gop = try exe.locals.getOrPut(cg.gpa, let.identifier);
if (!gop.found_existing) {
gop.value_ptr.* = exe.allocLocal();
if (is_typed) try exe.local_types.append(cg.gpa, let.type);
} else if (is_typed) {
exe.local_types.items[gop.value_ptr.*] = let.type;
const old = if (gop.found_existing) gop.value_ptr.* else undefined;
gop.value_ptr.* = exe.allocLocal();
if (is_typed) {
if (!gop.found_existing) {
try exe.local_types.append(cg.gpa, let.type);
} else {
exe.local_types.items[gop.value_ptr.*] = let.type;
}
}
try exe.emit(.move_local, gop.value_ptr.*, null);
if (gop.found_existing or cg.defines.contains(let.identifier)) {
try cg.shadow_stack.append(cg.gpa, .{
.name = let.identifier,
.old_local = if (gop.found_existing) gop.value_ptr.* else null,
.old_local = if (gop.found_existing) old else null,
});
}
}
Expand Down

0 comments on commit 761a639

Please sign in to comment.