Expand description
Stack-based bytecode VM for TensorLogic expressions.
This module provides a compiler from TLExpr to a flat BytecodeProgram
and a lightweight virtual machine that executes it. Repeated evaluation of
compiled expressions is faster than recursive interpretation because the
expression tree is only traversed once during compilation; subsequent
executions only walk the flat instruction array.
§Quick Start
use tensorlogic_compiler::bytecode::{compile, execute, VmEnv, VmValue};
use tensorlogic_ir::TLExpr;
// Compile 2.0 + 3.0
let expr = TLExpr::add(TLExpr::Constant(2.0), TLExpr::Constant(3.0));
let program = compile(&expr).unwrap();
let env = VmEnv::new();
let result = execute(&program, &env).unwrap();
assert_eq!(result, VmValue::Num(5.0));Structs§
- Bytecode
Program - A compiled, flat sequence of
Instructions. - VmEnv
- Variable environment passed to the VM at execution time.
- VmStats
- Execution statistics collected during a single VM run.
Enums§
- Compile
Error - Errors that can occur during bytecode compilation.
- Instruction
- Stack-based VM instruction.
- VmError
- Errors that can occur during VM execution.
- VmValue
- A runtime value on the VM stack.
Constants§
- DEFAULT_
MAX_ DEPTH - Default maximum expression depth allowed during compilation.
Functions§
- compile
- Compile a
TLExprto aBytecodeProgram. - compile_
with_ config - Compile a
TLExprto aBytecodeProgramwith an explicit depth limit. - execute
- Execute a
BytecodeProgramand return the top-of-stack value afterHalt. - execute_
with_ stats - Execute a
BytecodeProgramand return both the result and execution statistics.