Repository navigation
Compiler Architecture
The L++ compiler is written in Rust and is organized as a classic native compiler pipeline.
.lpp source
-> lexer
-> parser / AST
-> semantic analysis
-> type checking
-> escape analysis
-> MIR lowering
-> MIR optimization passes
-> Cranelift codegen
-> object file
-> host linker or lpp-link
-> executable
Files:
src/frontend/lexer.rssrc/frontend/parser.rssrc/frontend/ast.rs
The lexer handles indentation tokens, comments, literals, keywords, operators, f-strings, multiline strings, hex/binary literals, and underscore digit separators.
The parser is recursive descent and builds the AST.
Top-level AST declarations:
FunctionStructEnumImportConstTypeAlias
File:
src/analysis/semantic.rs
Responsibilities:
- lexical scopes
- binding IDs
- variable/function resolution
- mutability checks
- import resolution
- match-binding scope setup
File:
src/analysis/typecheck.rs
Key type representations:
TypeRef::Int
TypeRef::Float
TypeRef::Str
TypeRef::Bool
TypeRef::Void
TypeRef::Custom(StructTypeId)
TypeRef::Generic(String, Vec<TypeRef>)
TypeRef::TypeParam(String)
TypeRef::Unresolved(String)Generics phase 1 is implemented through type parameters and erasure to i64 at codegen.
File:
src/analysis/escape.rs
Classifies values as:
- stack
- ARC heap
- arena / rejected cycle
This is where ownership safety is enforced before code generation.
Files:
src/mir/lower.rssrc/mir/ir.rssrc/mir/pass_*.rs
MIR lowering desugars high-level syntax:
-
p.method()->method(p) -
x += y->x = x + y -
s[i]->str_substr(s, i, 1) - list indexing ->
list_get -
?-> branch + early return - match -> tag tests + branches
- short-circuit
&&and||-> control-flow branches
Optimization passes include ARC insertion, closure lifting, constant propagation, DCE, branch simplification, peephole optimization, and inlining.
Files:
src/backend/cranelift/compiler.rssrc/backend/cranelift/lower.rssrc/backend/cranelift/types.rs
The backend lowers MIR to Cranelift IR and emits native object files.
File:
src/bin/lpp-link.rs
The direct linker supports:
- Linux ELF
- Windows PE/COFF
- macOS Mach-O
Most language features never touch lpp-link. Builtins usually require runtime work, not linker work.