How jdrc6000/forge works
Forge is a Python-based educational compiler and virtual machine. A source file or source string enters through the runner, is tokenized and parsed, checked semantically, optimized, lowered to IR, analyzed as a control-flow graph, register-allocated, and executed by the VM. The README also documents builtins and optimization passes; the tree and excerpts support separate runtime support for methods and module loading. Some pipeline calls are omitted from the excerpts, so those links rely on the documented pipeline rather than sampled call sites.
Main entry points: main.py Compile runner · vm.py Virtual machine · analyser.py Semantic analysis · parser.py Parser
Components 20
Frontend
- Lexer
bootstrap/frontend/lexer.py - Parser
bootstrap/frontend/parser.py - AST nodes
bootstrap/frontend/ast_nodes.py - Semantic analysis
bootstrap/semantic/analyser.py - Symbol table
bootstrap/semantic/symbol_table.py - Diagnostics
bootstrap/exceptions.py
Compiler
- AST optimizer
bootstrap/optimiser/optimiser.py - Optimization passes
bootstrap/optimiser/passes.py - IR generator
bootstrap/ir/generator.py - Instruction IR
bootstrap/ir/ir.py - CFG builder
bootstrap/ir/cfg_builder.py - CFG analysis
bootstrap/ir/liveness.py - Register allocator
bootstrap/runtime/regalloc.py
Runtime
- Virtual machine
bootstrap/runtime/vm.py - Builtin functions
bootstrap/runtime/builtins_registry.py - Member methods
bootstrap/runtime/methods.py
Other components
- Program author
- Compile runner
main.py - Module source files
- Program output
Connections 22
- Program author → Compile runner: provides source
- Compile runner → Lexer: tokenizes
- Lexer → Parser: emits tokens
- Parser → AST nodes: builds tree
- Compile runner → Semantic analysis: checks tree
- Semantic analysis → Symbol table: consults scopes
- Compile runner → AST optimizer: optimizes tree
- AST optimizer → Optimization passes: runs passes
- Compile runner → IR generator: lowers tree
- IR generator → Instruction IR: emits instructions
- Compile runner → CFG builder: builds CFG
- CFG builder → CFG analysis: analyzes blocks
- Compile runner → CFG analysis: prunes and analyzes
- Compile runner → Register allocator: allocates registers
- Compile runner → Virtual machine: loads and runs code
- Virtual machine → Builtin functions: dispatches builtins
- Virtual machine → Member methods: resolves members
- Semantic analysis → Module source files: reads imports
- Virtual machine → Program output: executes program
- Parser → Diagnostics: raises parse errors
- Semantic analysis → Diagnostics: raises compile errors
- Virtual machine → Diagnostics: reports runtime errors