How tayadev/luma works
Project Type and Purpose
• Luma is a reference implementation of a programming language. It provides:
• A CLI front-end for running, REPL, type-checking, and compiling scripts.
• A multi-stage compiler pipeline (lexing, parsing, AST, type checking, bytecode IR).
• A virtual machine (VM) runtime with native/FFI modules.
• An LSP server for editor integration.
• A comprehensive test suite (parser tests, type-check tests, runtime tests, etc.).
High-Level Architectural Components
a. CLI Layer
• Commands: run, repl, check, compile, upgrade
• Parses CLI flags, invokes compiler front-end or runtime.
b. Front-End Pipeline
1. Lexer & Parser (src/parser/…)
2. AST Construction (src/ast/…)
3. Diagnostics & Error Recovery (src/diagnostics/…)
4. Type Checker (src/typecheck/…)
c. Middle-End (Bytecode Compiler)
• IR definitions (src/bytecode/ir.rs)
• Compile passes: compile.rs, emit_expr, emit_stmt, helpers
d. Back-End (Virtual Machine)
• Interpreter core (src/vm/interpreter.rs, execute.rs)
• Stack, frames, value representations (src/vm/stack.rs, value.rs)
• Native modules & FFI (src/vm/native/…)
• Module loader (src/vm/modules.rs)
e. LSP Server (src/lsp/mod.rs)
• Language server protocol handlers
• Ties into parser, typechecker, diagnostics
f. Support & Infrastructure
• Build scripts (build.rs, Cargo.toml)
• Tests & Benchmarks (benches/, tests/)
• Documentation site (docs/)
Interactions and Data Flow
• The user invokes CLI →
• “run” / “check” / “compile” → (1) front-end pipeline →
– Parser outputs AST + span metadata →
– Diagnostics module reports errors/warnings →
– Type Checker annotates AST with types →
– On “compile”: Bytecode Compiler emits .lumac →
– On “run”: VM Interpreter executes directly on AST or bytecode
• “repl” spins up an interactive loop using the same pipeline internally
• LSP Server accepts editor requests → uses Parser + Type Checker + Diagnostics → returns diagnostics, completions
Architectural Patterns & Principles
• Pipeline pattern: distinct phases (lexing, parsing, type checking, codegen, runtime)
• Single process, modular Rust crates and modules
• Separation of concerns: AST vs. IR vs. VM data structures
• Dependency inversion: CLI and LSP layers depend on back-end abstractions via public APIs