glados-0.1.0.0
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Compiler.ASM.AstToAsm

Description

 
Synopsis

Documentation

astIntToAsm :: IntValue -> CompilerMonad () Source #

Pushes an Integer AST value directly to the stack.

@args - val: The IntValue from the AST.

@details Since the AST construction (Parser) already uses fitInteger to determine the optimal storage size (I8, I16, etc.), we simply wrap the value in an ImmInt and emit the PUSH instruction.

@return Unit value wrapped in CompilerMonad.

astBoolToAsm :: Bool -> CompilerMonad () Source #

Converts a native Haskell Bool to a PUSH instruction.

@args - b: The boolean to convert.

@details Emits a Push instruction with an immediate boolean value.

@return Unit value wrapped in CompilerMonad.

astSymbolToAsm :: Text -> CompilerMonad () Source #

Converts a symbol (variable) to a LOAD instruction.

@args - name: The name of the symbol.

@details Looks up the symbol in the csSymbols table. Based on the associated ScopeType, it emits either LoadGlobal, LoadLocal, or LoadCapture with the correct index. Returns an error if the symbol is undefined.

@return Unit value wrapped in CompilerMonad.

astListToAsm :: (Ast -> CompilerMonad ()) -> [Ast] -> CompilerMonad () Source #

Converts a literal AST list to assembly instructions.

@args - compileFn: The recursive compilation function. - elements: The list of AST nodes to compile.

@details Compiles each element pushing them onto the stack, then calls the builtin "list" function to construct the list object.

@return Unit value wrapped in CompilerMonad.

astCallToAsm :: (Ast -> CompilerMonad ()) -> Ast -> [Ast] -> CompilerMonad () Source #

Compiles a function call (Builtin or User-defined).

@args - compileFn: The recursive compilation function. - callee: The AST representing the function being called. - args: The list of argument ASTs.

@details If the callee is a known builtin, emits the specific instruction. Otherwise, emits a CallLabel to the named function. (Higher-order calls are explicitly not supported in this version).

@return Unit value wrapped in CompilerMonad.

builtinMap :: Map Text Instruction Source #

Mapping of builtin operator names to their VM instructions.