Expand description
Checked word-stack CPU component.
Enable vihaco-cpu/typed-declarations to use the cpu runtime dialect and
per-instruction Execute implementations. This forwards to the lower runtime
crates; facade applications can instead enable vihaco/typed-declarations.
Feature-off use retains the legacy instruction enums and CPUMessage.
The nondefault program-image-execution feature implies typed-declarations
and switches CPU handlers to typed operands and stack result effects.
vihaco_stdlib::ExecutionState owns locals, operands, frames, and the program
counter. Heap storage remains on CPU and uses the same typed transfers.
With this feature, program instructions and their lowering helpers live in
vihaco_stdlib::program; CPU exposes only computation and heap instructions.
The following syntax description and example describe the typed-only route.
Typed instruction syntax retains readable literals until explicit lowering
encodes them into runtime Word payloads. Branch and call targets accept
numeric addresses or @name symbols; function references accept numeric
indices or function symbols. String constants accept indices or quoted text.
Loaders supply lower::LabelLookup, lower::FunctionLookup, and
lower::StringIntern to resolve them. vihaco_stdlib::ProgramImage implements
string interning using its section string table. Heap references remain numeric.
For explicit metadata, vihaco_module::loader::MetadataLoweringContext implements
all three lookup capabilities and rejects strings absent from the supplied
table. It works with ParsedModule::lower_with_metadata in vihaco-syntax.
label @name is retained in the parsed function’s label metadata without an
executable slot. Labels, function_start, and function_end have no runtime
instruction leaves.
Composite source uses device::dialect::mnemonic, for example
host::cpu::const_i64 -42. Generated aggregate bytecode codecs are separate work.
use vihaco_runtime::{Execute, NoMessage, Lower, Parse, Syntax, chumsky::Parser as _};
use vihaco_module::host::StackMemory;
use vihaco_cpu::{CPU, cpu, encode_i64, StepOutcome};
let instruction = cpu::ConstI64::<Syntax>::parser().parse("const_i64 -42")
.into_result().unwrap();
let instruction = instruction.lower(&mut ()).unwrap();
assert_eq!(instruction, cpu::ConstI64(encode_i64(-42)));
let mut cpu = CPU::default();
assert_eq!(cpu.execute(&instruction, NoMessage::new()).unwrap(), StepOutcome::Continue);
assert_eq!(cpu.stack(), &[encode_i64(-42)]);Modules§
Structs§
Functions§
- decode_
bool - Decodes a boolean word. Zero is false and every nonzero word is true.
- decode_
f32 - Decodes an
f32from its IEEE-754 representation in the low 32 bits. - decode_
f64 - Decodes an
f64from its IEEE-754 representation. - decode_
function_ ref - Decodes a numeric function reference.
- decode_
heap_ ref - Decodes a numeric heap reference.
- decode_
i32 - Decodes an
i32from the low 32 bits of a word. - decode_
i64 - Decodes an
i64without changing its bit pattern. - decode_
string_ id - Decodes an interned string identifier.
- decode_
u32 - Decodes a
u32from the low 32 bits of a word. - decode_
u64 - Decodes a
u64without changing its bit pattern. - encode_
bool - Encodes a boolean as its canonical word representation,
0or1. - encode_
f32 - Encodes an
f32using its IEEE-754 representation in the low 32 bits. - encode_
f64 - Encodes an
f64using its IEEE-754 representation. - encode_
function_ ref - Encodes a numeric function reference.
- encode_
heap_ ref - Encodes a numeric heap reference.
- encode_
i32 - Encodes an
i32in the low 32 bits of a word. - encode_
i64 - Encodes an
i64without changing its bit pattern. - encode_
string_ id - Encodes an interned string identifier.
- encode_
u32 - Encodes a
u32in the low 32 bits of a word. - encode_
u64 - Encodes a
u64without changing its bit pattern.
Type Aliases§
- Word
- One raw value in word-backed execution storage.