Compilation Pipeline

Here’s how the compilation process works:

  • Lexing: Source code is tokenized into symbols.
  • Parsing: Tokens are parsed into an AST (Abstract Syntax Tree).
  • Semantic Analysis: Types and scopes are resolved.
  • Code Generation: The AST is translated into Go code.
  • Go Compilation: Go code is compiled with go build.
  +------------------+
  |  .luma Source    |
  +--------+---------+
           |
           v
+----------------------+
|     Lexer            |  ← Tokens (e.g., IDENT, NUMBER, etc.)
+----------------------+
           |
           v
+----------------------+
|     Parser           |  ← AST (Abstract Syntax Tree)
+----------------------+
           |
           v
+----------------------+
|   Type Resolver      |  ← Type info (int, float, str, etc.)
+----------------------+
           |
           v
+----------------------+
|  Go Code Generator   |  ← `main_temp.go`
+----------------------+
           |
           v
+----------------------+
|     go build         |  ← Native binary
+----------------------+

Output Structure

Every Luma program gets compiled into a single Go main() file with:

  • All user code translated into idiomatic Go.
  • Core utilities from the Luma standard library injected at the top (e.g. _luma_print, to_int()).
  • Optional func main() includes REPL or CLI interface, depending on the mode.
Last updated on