Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
Add structural Fn signatures, typed capture environments, indirect calls and Trait dispatch while preserving logical parameter and result groups, ownership and budgets. Remove guest coroutine execution and legacy loading. Activate bounded sealed PBX v1 with mandatory capture metadata, preserve frame continuations and root return results, and migrate producers and shipped cartridges. Publish coordinated specs, handoffs and the completed runtime lesson. Validation: 880 workspace tests passed, 9 existing tests ignored; both cartridges completed six production-host frames.
68 lines
2.5 KiB
Rust
68 lines
2.5 KiB
Rust
use prometeu_bytecode::isa::core::{CoreOpCode, CoreOpCodeSpecExt};
|
|
use prometeu_bytecode::Value;
|
|
use prometeu_hal::{HostContext, HostReturn, NativeInterface, SyscallId};
|
|
use prometeu_vm::{BudgetReport, LogicalFrameEndingReason, VirtualMachine};
|
|
|
|
fn emit(op: CoreOpCode, imm: Option<&[u8]>, out: &mut Vec<u8>) {
|
|
out.extend_from_slice(&(op as u16).to_le_bytes());
|
|
let need = op.spec().imm_bytes as usize;
|
|
match (need, imm) {
|
|
(0, None) => {}
|
|
(n, Some(bytes)) if bytes.len() == n => out.extend_from_slice(bytes),
|
|
(n, Some(bytes)) => {
|
|
panic!("imm size mismatch for {:?}: need {}, got {}", op, n, bytes.len())
|
|
}
|
|
(n, None) => panic!("missing imm for {:?}: need {} bytes", op, n),
|
|
}
|
|
}
|
|
|
|
struct NoopNative;
|
|
impl NativeInterface for NoopNative {
|
|
fn syscall(
|
|
&mut self,
|
|
_id: SyscallId,
|
|
_args: &[Value],
|
|
_ret: &mut HostReturn,
|
|
_ctx: &mut HostContext,
|
|
) -> Result<(), prometeu_hal::vm_fault::VmFault> {
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn vm_executes_valid_program_in_slices() {
|
|
// Program: PUSH_I32 2; PUSH_I32 3; ADD; FRAME_SYNC; HALT
|
|
let mut rom = Vec::new();
|
|
emit(CoreOpCode::PushI32, Some(&2i32.to_le_bytes()), &mut rom);
|
|
emit(CoreOpCode::PushI32, Some(&3i32.to_le_bytes()), &mut rom);
|
|
emit(CoreOpCode::Add, None, &mut rom);
|
|
emit(CoreOpCode::SetGlobal, Some(&0u32.to_le_bytes()), &mut rom);
|
|
emit(CoreOpCode::FrameSync, None, &mut rom);
|
|
emit(CoreOpCode::GetGlobal, Some(&0u32.to_le_bytes()), &mut rom);
|
|
emit(CoreOpCode::Halt, None, &mut rom);
|
|
|
|
let bytes = prometeu_test_support::program::TestProgram::single(rom, Default::default(), 0, 8)
|
|
.serialize();
|
|
let image = prometeu_vm::ValidatedProgramImage::load(
|
|
&bytes,
|
|
&mut prometeu_bytecode::load_limits::LoadBudget::new(Default::default()),
|
|
0,
|
|
)
|
|
.unwrap();
|
|
let mut vm = VirtualMachine::from_image(image, Default::default());
|
|
vm.prepare_call("0").expect("prepare entry call");
|
|
|
|
let mut native = NoopNative;
|
|
let mut ctx = HostContext::new(None);
|
|
|
|
// First slice should stop at FRAME_SYNC deterministically.
|
|
let report: BudgetReport = vm.run_budget(100, &mut native, &mut ctx).expect("run ok");
|
|
assert_eq!(report.reason, LogicalFrameEndingReason::FrameSync);
|
|
assert!(!vm.is_halted());
|
|
|
|
// Second slice proceeds to HALT.
|
|
let report2: BudgetReport = vm.run_budget(100, &mut native, &mut ctx).expect("run ok");
|
|
assert_eq!(report2.reason, LogicalFrameEndingReason::Halted);
|
|
assert!(vm.is_halted());
|
|
}
|