feat(vm): add deterministic gameplay math and domain coverage gates
Intrepid/Prometeu/Runtime/pipeline/pr-master There was a failure building this commit
Intrepid/Prometeu/Runtime/pipeline/pr-master There was a failure building this commit
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
//! Reproducible bit-level probe for independent tooling; not a cartridge dependency.
|
||||
//! stdin: intrinsic hex ID followed by f:bits / i:decimal / l:decimal.
|
||||
//! Arithmetic opcode names ADD/SUB/MUL/DIV execute a validated PBX program.
|
||||
use prometeu_bytecode::{Value, assemble};
|
||||
use prometeu_hal::vm_fault::VmFault;
|
||||
use prometeu_vm::{
|
||||
HostContext, HostReturn, LogicalFrameEndingReason, NativeInterface, VirtualMachine,
|
||||
lookup_intrinsic_by_id,
|
||||
};
|
||||
use std::io::{self, BufRead};
|
||||
struct NoNative;
|
||||
impl NativeInterface for NoNative {
|
||||
fn syscall(
|
||||
&mut self,
|
||||
_: u32,
|
||||
_: &[Value],
|
||||
_: &mut HostReturn,
|
||||
_: &mut HostContext,
|
||||
) -> Result<(), VmFault> {
|
||||
panic!("no native call in numeric probe")
|
||||
}
|
||||
}
|
||||
fn text(value: &Value) -> String {
|
||||
match value {
|
||||
Value::Float(x) => format!("f:{:016x}", x.to_bits()),
|
||||
Value::Int32(x) => format!("i:{x}"),
|
||||
Value::Int64(x) => format!("l:{x}"),
|
||||
_ => panic!("numeric output"),
|
||||
}
|
||||
}
|
||||
fn main() {
|
||||
for line in io::stdin().lock().lines() {
|
||||
let line = line.unwrap();
|
||||
let mut words = line.split_whitespace();
|
||||
let op = words.next().unwrap();
|
||||
let args: Vec<_> = words
|
||||
.map(|s| {
|
||||
let (kind, v) = s.split_once(':').unwrap();
|
||||
match kind {
|
||||
"f" => Value::Float(f64::from_bits(u64::from_str_radix(v, 16).unwrap())),
|
||||
"i" => Value::Int32(v.parse().unwrap()),
|
||||
"l" => Value::Int64(v.parse().unwrap()),
|
||||
_ => panic!("carrier"),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
if !matches!(op, "ADD" | "SUB" | "MUL" | "DIV") {
|
||||
let id = u32::from_str_radix(op, 16).unwrap();
|
||||
let m = lookup_intrinsic_by_id(id).unwrap();
|
||||
match (m.implementation)(&args, &mut HostContext::new(None)) {
|
||||
Ok(v) => println!("{} {}", text(&v[0]), m.cost_cycles),
|
||||
Err(prometeu_vm::IntrinsicExecutionError::Numeric(e)) => {
|
||||
println!("trap:{:x} {}", e.code, m.cost_cycles)
|
||||
}
|
||||
Err(e) => panic!("{e:?}"),
|
||||
}
|
||||
} else {
|
||||
let mut source = String::new();
|
||||
for v in args {
|
||||
source.push_str(&match v {
|
||||
Value::Float(x) => format!("PUSH_F64 f64:0x{:016x}\n", x.to_bits()),
|
||||
Value::Int32(x) => format!("PUSH_I32 {x}\n"),
|
||||
Value::Int64(x) => format!("PUSH_I64 {x}\n"),
|
||||
_ => unreachable!(),
|
||||
});
|
||||
}
|
||||
source.push_str(op);
|
||||
source.push_str("\nHALT");
|
||||
let bytes = prometeu_test_support::program::TestProgram::single(
|
||||
assemble(&source).unwrap(),
|
||||
Default::default(),
|
||||
0,
|
||||
8,
|
||||
)
|
||||
.serialize();
|
||||
let mut vm = VirtualMachine::default();
|
||||
vm.initialize(bytes).unwrap();
|
||||
vm.prepare_call("0").unwrap();
|
||||
let r = vm.run_budget(100, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
match r.reason {
|
||||
LogicalFrameEndingReason::Halted => {
|
||||
println!("{} {}", text(&vm.operand_stack_top(1)[0]), r.cycles_used)
|
||||
}
|
||||
LogicalFrameEndingReason::Trap(e) => {
|
||||
println!("trap:{:x} {}", e.code, r.cycles_used)
|
||||
}
|
||||
e => panic!("{e:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user