Files
prometeu-runtime/crates/dev/prometeu-test-support/src/program.rs
T
bquarkz a4bec5bc45
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
feat(host): expose memcard controls and qualify process persistence
2026-10-30 10:10:07 +00:00

92 lines
2.8 KiB
Rust

//! Explicit typed test producers. All bytes use the official bounded v1 writer;
//! executable tests still go through ValidatedProgramImage::load.
use prometeu_bytecode::{
load_limits::LoadBudget,
model::{ConstantPoolEntry, DebugInfo, Export, SyscallDecl},
registry::*,
registry_codec::PbxModule,
};
#[derive(Default)]
pub struct TestProgram {
pub const_pool: Vec<ConstantPoolEntry>,
pub functions: Vec<FunctionDecl>,
pub code: Vec<u8>,
pub debug_info: Option<DebugInfo>,
pub exports: Vec<Export>,
pub syscalls: Vec<SyscallDecl>,
}
/// Scalar Int64 signatures for tests that explicitly choose this carrier.
/// Other carriers and multi-slot logical values must declare their own TypeIds.
pub fn int64_signature(parameters: usize, results: usize) -> Signature {
Signature {
parameters: (0..parameters).map(|_| NamedType { type_id: TypeId(0), name: None }).collect(),
results: vec![TypeId(0); results],
}
}
pub fn scalar_catalog() -> Vec<TypeDecl> {
[
BuiltinId::INT64,
BuiltinId::INT32,
BuiltinId::FLOAT,
BuiltinId::BOOL,
BuiltinId::STRING,
BuiltinId::DYNAMIC,
BuiltinId::VEC2,
BuiltinId::PIXEL,
BuiltinId::COLOR,
]
.into_iter()
.map(|id| TypeDecl { name: None, kind: TypeKind::Builtin(id) })
.collect()
}
impl TestProgram {
pub fn single(
code: Vec<u8>,
signature: Signature,
local_slots: u32,
max_stack_slots: u32,
) -> Self {
Self {
functions: vec![FunctionDecl {
lifecycle_role: Default::default(),
name: None,
signature,
captures: vec![],
code_offset: 0,
code_len: code.len() as u32,
local_slots,
max_stack_slots,
}],
code,
..Self::default()
}
}
pub fn serialize(&self) -> Vec<u8> {
self.serialize_with_types(scalar_catalog())
}
pub fn serialize_with_types(&self, types: Vec<TypeDecl>) -> Vec<u8> {
let mut budget = LoadBudget::new(Default::default());
let registry = Registry::resolve(
RegistryDeclarations {
types,
functions: self.functions.clone(),
implementations: vec![],
},
self.code.len(),
&mut budget,
)
.expect("typed test declarations");
PbxModule {
registry: &registry,
constants: &self.const_pool,
code: &self.code,
debug: self.debug_info.as_ref(),
exports: &self.exports,
syscalls: &self.syscalls,
}
.serialize(&mut budget)
.expect("official bounded v1 writer")
}
}