pub struct Compiler { /* private fields */ }Expand description
Compiler state for generating bytecode from AST nodes.
Implementations§
Source§impl Compiler
impl Compiler
Sourcepub fn with_state(symbols_table: SymbolsTable, constants: Vec<Value>) -> Self
pub fn with_state(symbols_table: SymbolsTable, constants: Vec<Value>) -> Self
Creates a compiler with existing symbols table and constants.
This enables REPL sessions where variable definitions and constants persist across multiple compilation passes.
Sourcepub fn symbols_table_mut(&mut self) -> &mut SymbolsTable
pub fn symbols_table_mut(&mut self) -> &mut SymbolsTable
Returns a mutable reference to the compiler’s symbols table.
Used by the module pipeline to define imported symbols before compilation, so that cross-module references resolve correctly.
Sourcepub fn register_type(&mut self, typedef: TypeDef)
pub fn register_type(&mut self, typedef: TypeDef)
Registers a type definition (struct or enum) in the type registry.
Used by the module pipeline to register imported type definitions so that construction and field access work across module boundaries.
Sourcepub fn bytecode(self) -> Result<Bytecode>
pub fn bytecode(self) -> Result<Bytecode>
Extracts the compiled bytecode and constants.
§Errors
Returns CompileError::ScopeUnderflow if the scope stack is empty,
which indicates an internal compiler invariant violation.
Sourcepub fn symbols_table(&self) -> &SymbolsTable
pub fn symbols_table(&self) -> &SymbolsTable
Returns a reference to the compiler’s symbols table.
Used for state persistence in REPL sessions where symbol definitions must carry over across compilation passes.
Sourcepub fn compile(&mut self, node: &Node) -> Result<()>
pub fn compile(&mut self, node: &Node) -> Result<()>
Compiles an AST node into bytecode.
This recursively traverses the AST, emitting instructions for each node. Returns an error if an unsupported node type or operator is encountered.
Sourcepub fn compile_program(&mut self, program: &Program) -> Result<()>
pub fn compile_program(&mut self, program: &Program) -> Result<()>
Compiles a program node (list of statements).