Expand description
Component execution, composite metadata, and observation machinery.
The nondefault typed-declarations feature enables experimental typed
execution and capability contracts, including derive support. It decouples
the Component/Composite markers from HasInstructionSet; Cargo unification
selects that contract for the shared runtime package instance. Declaration
macros provide complete dialect/component capabilities and typed composite
fields. Feature-off execution retains the existing declarations. The two
declaration modes require separate Cargo feature graphs.
The nondefault program-image-execution feature implies typed-declarations
and adds PopFromStack, PushToStack, typed stack access, and capability-
gated message preparation. A #[program] device supplies program access and
operand-storage wiring. Composite authors implement Steps and choose effect
handling; program execution lives in stdlib.
With typed-declarations, #[dialect] gives public runtime instruction
structs syntax parsers. Operand types retain their authored scope. Only
immediate marked nongeneric unit/tuple structs belong to a dialect. Differing
annotated operands generate a phase parameter defaulting to Runtime.
Composite syntax aggregates lower through instruction-owned Lower
implementations; unchanged instructions receive identity lowering.
use vihaco_runtime::{dialect, Parse, chumsky::Parser};
#[dialect]
pub mod arithmetic {
#[instruction]
pub struct Add(pub i64);
#[instruction]
#[pattern = "'stop"]
pub struct Halt;
}
let source = arithmetic::Add::parser().parse("add -3")
.into_result().unwrap();
assert_eq!(source, arithmetic::Add(-3));
let runtime = source;
assert_eq!(runtime.0, -3);The attribute consumes instruction and pattern helpers, preserves module
and field visibility, and supplies Clone/Debug/PartialEq without duplicating
those authored derives. Named fields, generic or raw leaf names, conditional
membership, and generated-name collisions are rejected. Gate the entire
module with cfg/cfg_attr. Unannotated pattern bindings use their runtime
field’s parser. A binding such as $0:u64 retains that syntax operand type;
differing runtime types require explicit lowering. Parser annotations retain
ordinary Rust type scope.
Re-exports§
pub use crate as runtime;pub use chumsky;
Modules§
Macros§
- field
- Name a composite field or nested route as a marker type.
Structs§
- Bytecode
Section View - A lightweight view into a parsed bytecode section.
- Composite
Metadata - NoMessage
- Execution input for instructions that need no runtime-supplied message.
- PopFrom
Stack - Copied operands prepared for an instruction, distinct from its payload.
- Push
ToStack - Results to insert during the framework’s effect-application phase.
- Runtime
- Executable operands, after instruction lowering.
- SstSection
View - A lightweight view into a parsed SST section.
- Stack
Batch - Owned operands in their original stack order.
- Stack
Batch Into Iter - Consuming iterator over a
StackBatch, without materializing another buffer. - Syntax
- Retained source operands, before instruction lowering.
Enums§
- Effects
- Input
Count - Where a homogeneous batch’s operand count is obtained.
Traits§
- Apply
- Framework hook to apply one effect during
crate::Step. - Build
Message - Build execution input for one composite field route and instruction type.
- Component
- An execution-capable device, independent of its executable instruction set.
- Composite
- A machine assembled from device fields, independent of executable selection.
- Dispatch
- Dispatch a composite instruction to its destination’s
crate::Step. - Effect
Sink - Execute
- Execute one instruction type with runtime-supplied input.
- Field
- Access a composite field route and describe its child type and source spellings.
- Generated
Component - HasInstruction
Set - The instruction types exposed by a device to its two execution layers.
- HasOperand
Stack - Framework wiring from composite instruction preparation to operand storage.
- HasProgram
- Access to the composite’s execution-state device, supplied by
#[program]. This selects mutable invocation state; the runner borrows program data separately. Instruction selection and PC management remain internal to stdlib execution. - Lower
- Lower an instruction using the capabilities supplied by a program loader.
- Member
Of - Membership of a type in a group identified by the marker type
G. - Message
- Observe
- Parse
- A parser whose input is
&'src str(char stream) and whose error type isSimple<char>. - PopStack
- Low-level typed operand access, excluding protected frame locals.
- Push
Stack - Low-level typed insertion into logical stack storage.
- Reset
- Stack
Input Count - Count metadata for a component/instruction pair using
crate::StackBatch. - Stack
Value - One copied logical stack value and its storage-representation conversions.
- Step
- Execution behavior for one composite field route and instruction type.
- Surface
Instruction - Marker for enums whose pattern-derived parser represents instruction syntax.
Functions§
Attribute Macros§
- component
- Declare a component’s complete dialect capabilities.
- composite
- Declare device fields and complete child capabilities.
- dialect
- Declare instructions with retained syntax operands and capability-based lowering.
- dispatch
- Adapt an authored execute method to the generated component runtime interface.
- machine
- Preserve the annotated item as the compatibility machine marker.
- observe
- Generate effect observer implementations from the annotated methods.
Derive Macros§
- Instruction
- Derive the bytecode-instruction traits (
OpCode,FromBytesWithOpcode,WriteBytes) for an instruction enum. - Message
- Mark a runtime-supplied message type with the Message trait.
- Parse