Skip to main content

Module bytecode

Module bytecode 

Source
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§

BytecodeProgram
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§

CompileError
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 TLExpr to a BytecodeProgram.
compile_with_config
Compile a TLExpr to a BytecodeProgram with an explicit depth limit.
execute
Execute a BytecodeProgram and return the top-of-stack value after Halt.
execute_with_stats
Execute a BytecodeProgram and return both the result and execution statistics.