fix compiler issues
This commit is contained in:
@@ -259,7 +259,8 @@ mod tests {
|
||||
00BE GateRelease
|
||||
00C0 GetLocal U32(2)
|
||||
00C6 GateRelease
|
||||
00C8 Ret
|
||||
00C8 PushConst U32(0)
|
||||
00CE Ret
|
||||
"#;
|
||||
|
||||
assert_eq!(disasm_text, expected_disasm);
|
||||
|
||||
@@ -146,7 +146,7 @@ mod tests {
|
||||
assert_eq!(func.name, "start");
|
||||
assert_eq!(func.id, FunctionId(10));
|
||||
|
||||
assert_eq!(func.body.len(), 3);
|
||||
assert_eq!(func.body.len(), 4);
|
||||
match &func.body[0].kind {
|
||||
InstrKind::Label(Label(l)) => assert!(l.contains("block_0")),
|
||||
_ => panic!("Expected label"),
|
||||
@@ -156,6 +156,10 @@ mod tests {
|
||||
_ => panic!("Expected PushConst"),
|
||||
}
|
||||
match &func.body[2].kind {
|
||||
InstrKind::PushNull => (),
|
||||
_ => panic!("Expected PushNull"),
|
||||
}
|
||||
match &func.body[3].kind {
|
||||
InstrKind::Ret => (),
|
||||
_ => panic!("Expected Ret"),
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ fn test_hip_conformance_core_to_vm_to_bytecode() {
|
||||
0x02, 0x00, 0x00, 0x00, // CP Count: 2
|
||||
0x00, // CP[0]: Null
|
||||
0x01, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // CP[1]: Int64(42)
|
||||
0x66, 0x00, 0x00, 0x00, // ROM Size: 102
|
||||
0x6c, 0x00, 0x00, 0x00, // ROM Size: 108
|
||||
// Instructions:
|
||||
0x60, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // Alloc { tid: 10, slots: 2 }
|
||||
0x43, 0x00, 0x00, 0x00, 0x00, 0x00, // SetLocal 0
|
||||
@@ -118,6 +118,7 @@ fn test_hip_conformance_core_to_vm_to_bytecode() {
|
||||
0x11, 0x00, // Pop
|
||||
0x42, 0x00, 0x00, 0x00, 0x00, 0x00, // GetLocal 0 (cleanup)
|
||||
0x6a, 0x00, // GateRelease
|
||||
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // PushConst 0 (Null return)
|
||||
0x51, 0x00, // Ret
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user