Skip to main content

Module interpreter

Module interpreter 

Source
Expand description

Tree-walking interpreter for LOGOS imperative code.

This module provides runtime execution of parsed LOGOS programs by walking the AST and executing statements/expressions directly. The interpreter is async-capable to support VFS operations.

§Architecture

LOGOS AST
    │
    ▼
┌────────────┐
│ Interpreter│ ──▶ Evaluate expressions
│            │ ──▶ Execute statements
│            │ ──▶ Manage scopes
└────────────┘
    │
    ▼
RuntimeValue results

§Runtime Values

The interpreter uses RuntimeValue to represent all values at runtime:

  • Primitives: Int, Float, Bool, Text, Char
  • Collections: List, Tuple, Set, Map
  • User types: Struct, Inductive (kernel-defined types)

§Async Support

The interpreter is async to support VFS file operations (OPFS on WASM, tokio::fs on native). All statement execution is async fn.

Structs§

ActionRef
Where a callback runs: the instance that owns the action, and which action it is.
ClosureValue
First-class closure value (boxed to reduce enum size).
FuelHandles
The shared fuel cell for one budgeted run, and its structured verdict.
FunctionDef
Stored function definition for user-defined functions.
InductiveValue
Kernel inductive value (boxed to reduce enum size).
Interpreter
InterpreterResult
Result from program interpretation.
QuantityValue
The payload of a RuntimeValue::Quantity: the physical quantity (magnitude in SI base + dimension) plus the unit it should be displayed in. Equality/hashing are by physical value (SI magnitude + dimension) — the display unit is presentation only, so 2 inches equals 5.08 centimetres.
StructValue
Runtime values during LOGOS interpretation.

Enums§

ClosureBodyRef
Side-table entry storing a closure body AST reference. The index into the closure_bodies Vec on the interpreter is stored in ClosureValue::body_index.
ControlFlow
Control flow signals returned from statement execution.
ListRepr
The List payload behind RuntimeValue::List: homogeneous all-Int and all-Float lists store UNBOXED vectors (cache-dense, and the JIT can pin a raw pointer to them); anything else boxes. The repr lives INSIDE the Rc<RefCell<…>>, so promotion re-tags the payload in place and every alias observes it — reference semantics and Rc identity are untouched. An EMPTY list is vacuously Ints and re-tags freely on its first push.
RuntimeValue

Constants§

SESSION_STACK_BYTES
The stack a tree-walker session runs on.

Functions§

active_fuel
The fuel currently armed on this thread, if any.
clear_fuel
Disarm the thread’s fuel (always paired with install_fuel).
crdt_for_declared_type
A fresh, empty CRDT replica for a declared CRDT type name, or None for a type that is not one.
default_for_declared_type
The value a declared type starts at, when a slot names a type and supplies no value of its own.
install_fuel
Arm a step budget for every engine started on this thread until clear_fuel. Returns the handles the caller reads after the run.
interp_nanos
RUN-ONLY tree-walking-interpreter timing — the interpreter analog of crate::vm::run_nanos. Executes the SAME statements the register-bytecode VM and the FPGA soft-core run, returning the MIN wall-time in nanoseconds over iters runs (a fresh Interpreter each run, symmetric with run_nanos building a fresh Vm). Interpreter::new is light (interned-symbol lookups only, no stdlib-prelude load), so this is a clean run-only number — the slowest tier of the cross-tier speed table (benchmarks/silicon/benchmark_timing.json): tree-walk (this) → bytecode VM (run_nanos) → native silicon (the on-chip cycle counter).
is_counter_type
Whether a declared type name is a COUNTER CRDT — one whose readable value is an Int total.
needs_async
on_session_stack
Run one tree-walker session on a thread whose stack holds the full call depth (SESSION_STACK_BYTES), and hand its result back.

Type Aliases§

MapStorage
The Map payload behind RuntimeValue::Map. INSERTION-ORDERED (IndexMap): iteration, display, and marshaling follow the order keys were first inserted — the LOGOS Map contract, identical across the tree-walker, the VM, the AOT LogosMap, and the direct-WASM linear map. FxHash instead of the standard library’s SipHash: map-heavy programs hash on every get/insert, and the keys here are small values (ints, short texts) where Fx is several times faster — with no DoS-resistance requirement (a single-program interpreter hashing its own program’s keys). NOTE: removal must go through shift_remove (order-preserving), never swap_remove.
OutputCallback
Callback type for streaming output from the interpreter. Called each time Show executes with the output line.