Files
prometeu-runtime/crates/console/prometeu-vm/tests/producer_handoff.rs
T
bquarkz ec84a6bba5
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
feat(vm)!: implement typed callables and single-context execution
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.
2026-10-09 05:47:24 +01:00

94 lines
3.7 KiB
Rust

use prometeu_bytecode::load_limits::LoadBudget;
use prometeu_bytecode::registry::{
BuiltinId, FunctionDecl, NamedType, Registry, RegistryDeclarations, Signature, TypeDecl,
TypeId, TypeKind,
};
use prometeu_bytecode::registry_codec::PbxModule;
use prometeu_bytecode::{Value, assemble};
use prometeu_hal::{HostContext, HostReturn, NativeInterface, syscalls::caps, vm_fault::VmFault};
use prometeu_vm::{
LogicalFrameEndingReason, ValidatedProgramImage, VirtualMachine, resource_budget::RuntimeLimits,
};
struct NoNative;
impl NativeInterface for NoNative {
fn syscall(
&mut self,
_id: u32,
_args: &[Value],
_ret: &mut HostReturn,
_ctx: &mut HostContext,
) -> Result<(), VmFault> {
panic!("oracle has no native calls")
}
}
#[test]
fn named_arguments_preserve_source_effect_order_and_call_in_signature_order_without_debug() {
// Frontend oracle: combine(y: effectY(20), x: effectX(10)).
// Trace appends Y=2 before X=1; combine(x,y) computes x*100+y.
let bodies=[
assemble("PUSH_I32 0\nSET_GLOBAL 0\nCALL 2\nSET_LOCAL 0\nCALL 1\nSET_LOCAL 1\nGET_LOCAL 1\nGET_LOCAL 0\nCALL 3\nSET_GLOBAL 1\nGET_GLOBAL 0\nGET_GLOBAL 1\nHALT").unwrap(),
assemble("GET_GLOBAL 0\nPUSH_I32 10\nMUL\nPUSH_I32 1\nADD\nSET_GLOBAL 0\nPUSH_I32 10\nRET").unwrap(),
assemble("GET_GLOBAL 0\nPUSH_I32 10\nMUL\nPUSH_I32 2\nADD\nSET_GLOBAL 0\nPUSH_I32 20\nRET").unwrap(),
assemble("GET_LOCAL 0\nPUSH_I32 100\nMUL\nGET_LOCAL 1\nADD\nRET").unwrap(),
];
let mut code = vec![];
let mut functions = vec![];
for (index, body) in bodies.iter().enumerate() {
let parameters = if index == 3 {
vec![
NamedType { type_id: TypeId(0), name: Some("x".into()) },
NamedType { type_id: TypeId(0), name: Some("y".into()) },
]
} else {
vec![]
};
functions.push(FunctionDecl {
captures: vec![],
name: Some(["main", "effectX", "effectY", "combine"][index].into()),
signature: Signature {
parameters,
results: if index == 0 { vec![] } else { vec![TypeId(0)] },
},
code_offset: code.len() as u32,
code_len: body.len() as u32,
local_slots: if index == 0 { 2 } else { 0 },
max_stack_slots: 2,
});
code.extend_from_slice(body);
}
let registry = Registry::resolve(
RegistryDeclarations {
types: vec![TypeDecl { name: None, kind: TypeKind::Builtin(BuiltinId::INT32) }],
functions,
..Default::default()
},
code.len(),
&mut LoadBudget::new(Default::default()),
)
.unwrap();
let bytes = PbxModule {
registry: &registry,
code: &code,
constants: &[],
debug: None,
exports: &[],
syscalls: &[],
}
.serialize(&mut LoadBudget::new(Default::default()))
.unwrap();
let image =
ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(Default::default()), caps::NONE)
.unwrap();
assert!(image.debug().is_none());
let parameters = &image.registry().declarations().functions[3].signature.parameters;
assert_eq!(parameters[0].name.as_deref(), Some("x"));
assert_eq!(parameters[1].name.as_deref(), Some("y"));
let mut vm = VirtualMachine::from_image(image, RuntimeLimits::default());
vm.prepare_boot_call().unwrap();
let report = vm.run_budget(10_000, &mut NoNative, &mut HostContext::new(None)).unwrap();
assert_eq!(report.reason, LogicalFrameEndingReason::Halted);
assert_eq!(vm.operand_stack_top(2), vec![Value::Int32(1020), Value::Int32(21)]);
}