This commit is contained in:
Nilton Constantino
2026-01-30 16:07:45 +00:00
parent ca3a5d4d3f
commit c797be9287
6 changed files with 173 additions and 108 deletions
@@ -161,19 +161,23 @@ impl<'a> BytecodeEmitter<'a> {
asm_instrs.push(Asm::Op(OpCode::Syscall, vec![Operand::U32(*id)]));
}
InstrKind::FrameSync => asm_instrs.push(Asm::Op(OpCode::FrameSync, vec![])),
InstrKind::Alloc { .. } => asm_instrs.push(Asm::Op(OpCode::Alloc, vec![])),
InstrKind::Alloc { type_id, slots } => {
asm_instrs.push(Asm::Op(OpCode::Alloc, vec![Operand::U32(type_id.0), Operand::U32(*slots)]));
}
InstrKind::GateLoad { offset } => {
asm_instrs.push(Asm::Op(OpCode::LoadRef, vec![Operand::U32(*offset)]));
asm_instrs.push(Asm::Op(OpCode::GateLoad, vec![Operand::U32(*offset)]));
}
InstrKind::GateStore { offset } => {
asm_instrs.push(Asm::Op(OpCode::StoreRef, vec![Operand::U32(*offset)]));
}
InstrKind::GateBeginPeek | InstrKind::GateEndPeek |
InstrKind::GateBeginBorrow | InstrKind::GateEndBorrow |
InstrKind::GateBeginMutate | InstrKind::GateEndMutate |
InstrKind::GateRetain | InstrKind::GateRelease => {
asm_instrs.push(Asm::Op(OpCode::Nop, vec![]));
asm_instrs.push(Asm::Op(OpCode::GateStore, vec![Operand::U32(*offset)]));
}
InstrKind::GateBeginPeek => asm_instrs.push(Asm::Op(OpCode::GateBeginPeek, vec![])),
InstrKind::GateEndPeek => asm_instrs.push(Asm::Op(OpCode::GateEndPeek, vec![])),
InstrKind::GateBeginBorrow => asm_instrs.push(Asm::Op(OpCode::GateBeginBorrow, vec![])),
InstrKind::GateEndBorrow => asm_instrs.push(Asm::Op(OpCode::GateEndBorrow, vec![])),
InstrKind::GateBeginMutate => asm_instrs.push(Asm::Op(OpCode::GateBeginMutate, vec![])),
InstrKind::GateEndMutate => asm_instrs.push(Asm::Op(OpCode::GateEndMutate, vec![])),
InstrKind::GateRetain => asm_instrs.push(Asm::Op(OpCode::GateRetain, vec![])),
InstrKind::GateRelease => asm_instrs.push(Asm::Op(OpCode::GateRelease, vec![])),
}
let end_idx = asm_instrs.len();
+23 -23
View File
@@ -158,10 +158,10 @@ mod tests {
let opcodes: Vec<_> = instrs.iter().map(|i| i.opcode).collect();
assert!(opcodes.contains(&OpCode::Alloc));
assert!(opcodes.contains(&OpCode::LoadRef));
// After PR-05, BeginMutate/EndMutate map to GateLoad/Nop for now
// because VM is feature-frozen. StoreRef is removed from lowering.
assert!(opcodes.contains(&OpCode::Nop));
assert!(opcodes.contains(&OpCode::GateLoad));
// After PR-09, BeginMutate/EndMutate map to their respective opcodes
assert!(opcodes.contains(&OpCode::GateBeginMutate));
assert!(opcodes.contains(&OpCode::GateEndMutate));
assert!(opcodes.contains(&OpCode::Add));
assert!(opcodes.contains(&OpCode::Ret));
}
@@ -237,25 +237,25 @@ mod tests {
0052 SetLocal U32(1)
0058 Jmp U32(100)
005E Jmp U32(100)
0064 Alloc
0066 SetLocal U32(1)
006C GetLocal U32(1)
0072 Nop
0074 SetLocal U32(2)
007A Nop
007C GetLocal U32(2)
0082 LoadRef U32(0)
0088 SetLocal U32(3)
008E GetLocal U32(3)
0094 PushConst U32(5)
009A Add
009C SetLocal U32(4)
00A2 Nop
00A4 GetLocal U32(1)
00AA Nop
00AC GetLocal U32(2)
00B2 Nop
00B4 Ret
0064 Alloc U32(2) U32(1)
006E SetLocal U32(1)
0074 GetLocal U32(1)
007A GateRetain
007C SetLocal U32(2)
0082 GateBeginMutate
0084 GetLocal U32(2)
008A GateLoad U32(0)
0090 SetLocal U32(3)
0096 GetLocal U32(3)
009C PushConst U32(5)
00A2 Add
00A4 SetLocal U32(4)
00AA GateEndMutate
00AC GetLocal U32(1)
00B2 GateRelease
00B4 GetLocal U32(2)
00BA GateRelease
00BC Ret
"#;
assert_eq!(disasm_text, expected_disasm);