fix compiler issues

This commit is contained in:
Nilton Constantino
2026-01-30 17:28:04 +00:00
parent 926ad2a807
commit e2a5a08bf2
12 changed files with 137 additions and 37 deletions
@@ -313,6 +313,13 @@ pub fn lower_function(
vm_func.body.push(ir_vm::Instruction::new(ir_vm::InstrKind::GateRelease, None));
}
}
// If the function is Void, we must push a Null value to satisfy the VM's RET instruction.
// The VM always pops one value from the stack to be the return value.
if vm_func.return_type == ir_vm::Type::Void {
vm_func.body.push(ir_vm::Instruction::new(ir_vm::InstrKind::PushNull, None));
}
vm_func.body.push(ir_vm::Instruction::new(ir_vm::InstrKind::Ret, None));
}
ir_core::Terminator::Jump(target) => {
@@ -422,7 +429,7 @@ mod tests {
let func = &vm_module.functions[0];
assert_eq!(func.name, "main");
assert_eq!(func.body.len(), 7);
assert_eq!(func.body.len(), 8);
match &func.body[0].kind {
InstrKind::Label(Label(l)) => assert_eq!(l, "block_0"),
@@ -452,6 +459,10 @@ mod tests {
_ => panic!("Expected HostCall 42"),
}
match &func.body[6].kind {
InstrKind::PushNull => (),
_ => panic!("Expected PushNull"),
}
match &func.body[7].kind {
InstrKind::Ret => (),
_ => panic!("Expected Ret"),
}
@@ -500,7 +511,7 @@ mod tests {
// GateStore 100 (offset)
// Ret
assert_eq!(func.body.len(), 9);
assert_eq!(func.body.len(), 10);
match &func.body[1].kind {
ir_vm::InstrKind::LocalLoad { slot } => assert_eq!(*slot, 0),
_ => panic!("Expected LocalLoad 0"),
@@ -517,6 +528,14 @@ mod tests {
ir_vm::InstrKind::GateStore { offset } => assert_eq!(*offset, 100),
_ => panic!("Expected GateStore 100"),
}
match &func.body[8].kind {
ir_vm::InstrKind::PushNull => (),
_ => panic!("Expected PushNull"),
}
match &func.body[9].kind {
ir_vm::InstrKind::Ret => (),
_ => panic!("Expected Ret"),
}
}
#[test]
@@ -609,10 +628,10 @@ mod tests {
assert!(found_overwrite, "Should have emitted release-then-store sequence for overwrite");
// Check Ret cleanup:
// LocalLoad 1, GateRelease, Ret
// LocalLoad 1, GateRelease, PushNull, Ret
let mut found_cleanup = false;
for i in 0..kinds.len() - 2 {
if let (InstrKind::LocalLoad { slot: 1 }, InstrKind::GateRelease, InstrKind::Ret) = (kinds[i], kinds[i+1], kinds[i+2]) {
for i in 0..kinds.len() - 3 {
if let (InstrKind::LocalLoad { slot: 1 }, InstrKind::GateRelease, InstrKind::PushNull, InstrKind::Ret) = (kinds[i], kinds[i+1], kinds[i+2], kinds[i+3]) {
found_cleanup = true;
break;
}