implemented intrinsecs de input and specs adjustment

This commit is contained in:
2026-03-24 13:40:48 +00:00
parent 1bd921979f
commit 10dfc7bf15
17 changed files with 957 additions and 1089 deletions
@@ -0,0 +1,45 @@
//! Regression test: input is no longer exposed through the syscall registry.
use prometeu_bytecode::isa::core::CoreOpCode as OpCode;
use prometeu_hal::vm_fault::VmFault;
use prometeu_vm::{HostContext, HostReturn, NativeInterface, VirtualMachine};
fn enc_op(op: OpCode) -> [u8; 2] {
(op as u16).to_le_bytes()
}
#[test]
fn vm_rejects_legacy_input_syscall_id() {
// Legacy input syscall id (PadGetUp) must now be rejected as unknown syscall.
let mut rom = Vec::new();
rom.extend_from_slice(&enc_op(OpCode::Syscall));
rom.extend_from_slice(&0x2200u32.to_le_bytes());
rom.extend_from_slice(&enc_op(OpCode::Halt));
struct NoopNative;
impl NativeInterface for NoopNative {
fn syscall(
&mut self,
_id: u32,
_args: &[prometeu_bytecode::Value],
_ret: &mut HostReturn,
_ctx: &mut HostContext,
) -> Result<(), VmFault> {
Ok(())
}
}
let mut vm = VirtualMachine::new(rom, vec![]);
let mut native = NoopNative;
let mut ctx = HostContext::new(None);
vm.prepare_call("0");
vm.set_capabilities(prometeu_hal::syscalls::caps::ALL);
let report = vm.run_budget(100, &mut native, &mut ctx).expect("VM run failed");
match report.reason {
prometeu_vm::LogicalFrameEndingReason::Trap(trap) => {
assert_eq!(trap.code, prometeu_bytecode::TRAP_INVALID_SYSCALL);
assert!(trap.message.contains("Unknown syscall"));
}
other => panic!("Expected invalid syscall trap, got {:?}", other),
}
}
@@ -1,54 +0,0 @@
//! Deterministic tests for multi-return syscalls with the slot-based ABI.
use prometeu_bytecode::Value;
use prometeu_bytecode::isa::core::CoreOpCode as OpCode;
use prometeu_hal::vm_fault::VmFault;
use prometeu_vm::{HostContext, HostReturn, NativeInterface, VirtualMachine};
fn enc_op(op: OpCode) -> [u8; 2] {
(op as u16).to_le_bytes()
}
#[test]
fn vm_syscall_multi_return_stack_contents() {
// Use a real multi-return syscall id with ret_slots = 4: PadGetUp (0x2200)
// ROM: SYSCALL 0x2200; HALT
let mut rom = Vec::new();
rom.extend_from_slice(&enc_op(OpCode::Syscall));
rom.extend_from_slice(&0x2200u32.to_le_bytes());
rom.extend_from_slice(&enc_op(OpCode::Halt));
struct TestNative;
impl NativeInterface for TestNative {
fn syscall(
&mut self,
id: u32,
_args: &[Value],
ret: &mut HostReturn,
_ctx: &mut HostContext,
) -> Result<(), VmFault> {
assert_eq!(id, 0x2200);
// Push exactly 4 results in a known order.
ret.push_int(11);
ret.push_int(22);
ret.push_bool(true);
ret.push_int(7);
Ok(())
}
}
let mut vm = VirtualMachine::new(rom.clone(), vec![]);
let mut native = TestNative;
let mut ctx = HostContext::new(None);
vm.prepare_call("0");
// Grant INPUT capability to pass capability gate for PadGetUp
vm.set_capabilities(prometeu_hal::syscalls::caps::INPUT);
let _ = vm.run_budget(100, &mut native, &mut ctx).expect("VM run failed");
// Verify top-of-stack order: last pushed is on top
let top = vm.operand_stack_top(4);
assert_eq!(
top,
vec![Value::Int64(7), Value::Boolean(true), Value::Int64(22), Value::Int64(11),]
);
}