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
@@ -544,15 +544,16 @@ impl VirtualMachine {
self.operand_stack.truncate(frame.scope_stack_base);
}
OpCode::Alloc => {
// Allocates 'size' values on the heap and pushes a reference to the stack
let size = self.read_u32()? as usize;
// Allocates 'slots' values on the heap and pushes a reference to the stack
let _type_id = self.read_u32()?;
let slots = self.read_u32()? as usize;
let ref_idx = self.heap.len();
for _ in 0..size {
for _ in 0..slots {
self.heap.push(Value::Null);
}
self.push(Value::Ref(ref_idx));
}
OpCode::LoadRef => {
OpCode::GateLoad => {
// Reads a value from a heap reference at a specific offset
let offset = self.read_u32()? as usize;
let ref_val = self.pop()?;
@@ -560,10 +561,10 @@ impl VirtualMachine {
let val = self.heap.get(base + offset).cloned().ok_or("Invalid heap access")?;
self.push(val);
} else {
return Err("Expected reference for LOAD_REF".into());
return Err("Expected reference for GATE_LOAD".into());
}
}
OpCode::StoreRef => {
OpCode::GateStore => {
// Writes a value to a heap reference at a specific offset
let offset = self.read_u32()? as usize;
let val = self.pop()?;
@@ -574,9 +575,18 @@ impl VirtualMachine {
}
self.heap[base + offset] = val;
} else {
return Err("Expected reference for STORE_REF".into());
return Err("Expected reference for GATE_STORE".into());
}
}
OpCode::GateBeginPeek | OpCode::GateEndPeek |
OpCode::GateBeginBorrow | OpCode::GateEndBorrow |
OpCode::GateBeginMutate | OpCode::GateEndMutate |
OpCode::GateRetain => {
// These are no-ops in v0, but they preserve the gate on the stack.
}
OpCode::GateRelease => {
self.pop()?;
}
OpCode::Syscall => {
// Calls a native function implemented by the Firmware/OS.
// ABI Rule: Arguments are pushed in call order (LIFO).