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.
86 lines
3.0 KiB
Rust
86 lines
3.0 KiB
Rust
use prometeu_bytecode::registry::FunctionDecl;
|
|
use prometeu_test_support::program::{TestProgram, int64_signature};
|
|
use std::fs;
|
|
use std::hint::black_box;
|
|
use std::path::{Path, PathBuf};
|
|
use std::time::{Instant, SystemTime, UNIX_EPOCH};
|
|
|
|
use prometeu_bytecode::SourceSpan;
|
|
use prometeu_bytecode::assembler::assemble;
|
|
use prometeu_bytecode::model::{DebugInfo, Export};
|
|
use prometeu_host_headless::{AdvanceFramesStop, HeadlessHost};
|
|
|
|
const SAMPLE_FRAMES: u64 = 300;
|
|
const SAMPLE_COUNT: u32 = 10;
|
|
|
|
fn main() {
|
|
let cartridge = benchmark_cartridge();
|
|
let mut samples = Vec::with_capacity(SAMPLE_COUNT as usize);
|
|
|
|
for _ in 0..SAMPLE_COUNT {
|
|
let mut host = HeadlessHost::new();
|
|
host.boot(cartridge.to_string_lossy()).expect("boot benchmark cartridge");
|
|
|
|
let started = Instant::now();
|
|
let outcome =
|
|
black_box(host.advance_frames(SAMPLE_FRAMES)).expect("advance benchmark frames");
|
|
let elapsed = started.elapsed();
|
|
|
|
assert_eq!(outcome.completed, SAMPLE_FRAMES);
|
|
assert_eq!(outcome.stop, AdvanceFramesStop::Completed);
|
|
samples.push(elapsed.as_secs_f64());
|
|
}
|
|
|
|
samples.sort_by(f64::total_cmp);
|
|
let median_seconds = samples[samples.len() / 2];
|
|
let frames_per_second = SAMPLE_FRAMES as f64 / median_seconds;
|
|
println!(
|
|
"headless advance_frames: median={median_seconds:.6}s frames={SAMPLE_FRAMES} throughput={frames_per_second:.2} frames/s samples={SAMPLE_COUNT}"
|
|
);
|
|
|
|
fs::remove_dir_all(&cartridge).expect("remove benchmark cartridge");
|
|
}
|
|
|
|
fn benchmark_cartridge() -> PathBuf {
|
|
let directory = std::env::temp_dir().join(format!(
|
|
"prometeu-headless-benchmark-{}-{}",
|
|
std::process::id(),
|
|
SystemTime::now().duration_since(UNIX_EPOCH).expect("system clock").as_nanos()
|
|
));
|
|
fs::create_dir_all(&directory).expect("create benchmark cartridge");
|
|
|
|
let code = assemble("RET\n").expect("assemble benchmark program");
|
|
let module = TestProgram {
|
|
const_pool: vec![],
|
|
functions: vec![FunctionDecl {
|
|
code_offset: 0,
|
|
code_len: code.len() as u32,
|
|
local_slots: 0,
|
|
max_stack_slots: 1,
|
|
signature: int64_signature(0, 0),
|
|
captures: vec![],
|
|
name: None,
|
|
}],
|
|
code,
|
|
debug_info: Some(DebugInfo {
|
|
pc_to_span: vec![(0, SourceSpan { file_id: 1, start: 0, end: 10 })],
|
|
function_names: vec![(0, "main".into())],
|
|
}),
|
|
exports: vec![Export { symbol: "main".into(), func_idx: 0 }],
|
|
syscalls: vec![],
|
|
}
|
|
.serialize();
|
|
|
|
fs::write(directory.join("program.pbx"), module).expect("write benchmark program");
|
|
write_manifest(&directory);
|
|
directory
|
|
}
|
|
|
|
fn write_manifest(directory: &Path) {
|
|
fs::write(
|
|
directory.join("manifest.json"),
|
|
"{\n \"magic\": \"PMTU\",\n \"cartridge_version\": 1,\n \"app_id\": 90,\n \"title\": \"Headless Temporal Benchmark\",\n \"app_version\": \"0.1.0\",\n \"app_mode\": \"Game\",\n \"capabilities\": []\n}\n",
|
|
)
|
|
.expect("write benchmark manifest");
|
|
}
|