pr7.4
This commit is contained in:
@@ -84,6 +84,9 @@ pub struct VirtualMachine {
|
||||
/// Capability flags granted to the currently running program/cart.
|
||||
/// Syscalls are capability-gated using `prometeu_hal::syscalls::SyscallMeta::caps`.
|
||||
pub capabilities: prometeu_hal::syscalls::CapFlags,
|
||||
/// Cooperative scheduler: set to true when `YIELD` opcode is executed.
|
||||
/// The runtime/scheduler should only act on this at safepoints (FRAME_SYNC).
|
||||
pub yield_requested: bool,
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +118,7 @@ impl VirtualMachine {
|
||||
gc_alloc_threshold: 1024, // conservative default; tests may override
|
||||
last_gc_live_count: 0,
|
||||
capabilities: 0,
|
||||
yield_requested: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,6 +412,17 @@ impl VirtualMachine {
|
||||
self.cycles += OpCode::Trap.cycles();
|
||||
return Err(LogicalFrameEndingReason::Breakpoint);
|
||||
}
|
||||
OpCode::Spawn => {
|
||||
// Placeholder: spawning is handled by the system runtime in a later PR.
|
||||
// VM side does not switch; arguments/immediates will be handled when
|
||||
// coroutine objects and ABI are fully wired. For now, it's a no-op here
|
||||
// besides normal cycle accounting at the end of step.
|
||||
}
|
||||
OpCode::Yield => {
|
||||
// Cooperative yield: record intent; actual switching only at FRAME_SYNC.
|
||||
self.yield_requested = true;
|
||||
// Do not end the slice here; we continue executing until a safepoint.
|
||||
}
|
||||
OpCode::MakeClosure => {
|
||||
// Immediate carries (fn_id, capture_count)
|
||||
let (fn_id, cap_count) = instr
|
||||
@@ -1127,6 +1142,8 @@ impl VirtualMachine {
|
||||
}
|
||||
}
|
||||
|
||||
// Clear cooperative yield request at the safepoint boundary.
|
||||
self.yield_requested = false;
|
||||
return Err(LogicalFrameEndingReason::FrameSync);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user