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.
71 lines
2.5 KiB
Rust
71 lines
2.5 KiB
Rust
use prometeu_bytecode::isa::core::{CoreOpCode, CoreOpCodeSpecExt};
|
|
use prometeu_hal::{HostContext, HostReturn, NativeInterface, SyscallId};
|
|
use prometeu_vm::{BudgetReport, LogicalFrameEndingReason, VirtualMachine};
|
|
|
|
#[test]
|
|
fn single_context_frame_continuation_is_deterministic() {
|
|
// Black-box determinism: run a tiny program twice and ensure it yields the same sequence
|
|
// of LogicalFrameEndingReason for identical budgets.
|
|
|
|
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: &[prometeu_bytecode::Value],
|
|
_ret: &mut HostReturn,
|
|
_ctx: &mut HostContext,
|
|
) -> Result<(), prometeu_hal::vm_fault::VmFault> {
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
// Program: FRAME_SYNC; HALT
|
|
let mut rom = Vec::new();
|
|
emit(CoreOpCode::FrameSync, None, &mut rom);
|
|
emit(CoreOpCode::Halt, None, &mut rom);
|
|
|
|
let run_once = || -> Vec<LogicalFrameEndingReason> {
|
|
let bytes = prometeu_test_support::program::TestProgram::single(
|
|
rom.clone(),
|
|
Default::default(),
|
|
0,
|
|
4,
|
|
)
|
|
.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);
|
|
let mut reasons = Vec::new();
|
|
let r1: BudgetReport = vm.run_budget(10, &mut native, &mut ctx).unwrap();
|
|
reasons.push(r1.reason);
|
|
let r2: BudgetReport = vm.run_budget(10, &mut native, &mut ctx).unwrap();
|
|
reasons.push(r2.reason);
|
|
reasons
|
|
};
|
|
|
|
let a = run_once();
|
|
let b = run_once();
|
|
assert_eq!(a, b, "execution reasons must be deterministic");
|
|
}
|