How kokinf/minicompiler works
MiniCompiler is a Go compiler for MiniLang that emits NASM x86-64 assembly. The principal workflow takes a source file through tokenization, parsing, semantic checks, intermediate representation, and native-code generation; the CLI also exposes inspection and diagnostics modes. The README documents the language’s arrays, C externals, and optimization capabilities. Connections for unsampled implementation details are omitted or shown as documented workflow; source excerpts do not expose all pipeline calls.
Main entry points: main.go Compiler CLI · x86_generator.go x86-64 Generator · analyzer.go Semantic Analyzer · scanner.go Lexer
Components 22
Language Front End
- Lexer
src/internal/lexer/scanner.go - Token Model
src/internal/token/token.go - Parser
src/internal/parser/parser.go - AST
src/internal/ast/ast.go - AST Printers
src/internal/ast/printer.go
Analysis and IR
- Semantic Analyzer
src/internal/semantic/analyzer.go - Symbol Table
src/internal/semantic/symbol_table.go - Type System
src/internal/semantic/type_system.go - IR Generator
src/internal/ir/generator.go - IR Optimizer
src/internal/ir/optimizer.go - IR Model
src/internal/ir/instruction.go
Native Backend
- x86-64 Generator
src/internal/codegen/x86_generator.go - Expression Codegen
src/internal/codegen/expression_generator.go - Codegen Optimizations
src/internal/codegen/optimization_passes.go - C Call Support
src/internal/codegen/external_calls.go - C Library Declarations
src/libc/stdlib.h - Runtime Assembly
src/runtime/runtime.asm
CLI and Diagnostics
- Compiler CLI
src/cmd/compiler/main.go - Error Formatting
src/internal/utils/error_formatter.go - Warning Controls
src/internal/utils/warnings.go
Other components
- MiniLang Developer
- NASM Assembly
Connections 23
- MiniLang Developer → Compiler CLI: invokes
README.md - Compiler CLI → Lexer: tokenizes
README.md - Lexer → Token Model: creates tokens
src/internal/lexer/scanner.go - Compiler CLI → Parser: parses source
README.md - Parser → AST: builds AST
README.md - Compiler CLI → Semantic Analyzer: checks program
src/cmd/compiler/main.go - Semantic Analyzer → Symbol Table: tracks symbols
src/internal/semantic/analyzer.go - Semantic Analyzer → Type System: checks types
- Compiler CLI → IR Generator: generates IR
README.md - IR Generator → IR Model: emits instructions
README.md - Compiler CLI → IR Optimizer: optimizes IR
README.md - IR Optimizer → IR Model: rewrites IR
- Compiler CLI → x86-64 Generator: generates assembly
README.md - x86-64 Generator → Expression Codegen: delegates expressions
- x86-64 Generator → Codegen Optimizations: applies passes
- x86-64 Generator → NASM Assembly: emits NASM
README.md - Compiler CLI → AST Printers: prints AST
README.md - MiniLang Developer → Error Formatting: selects format
README.md - Compiler CLI → Error Formatting: reports errors
src/cmd/compiler/main.go - Compiler CLI → Warning Controls: configures warnings
README.md - x86-64 Generator → C Call Support: handles C calls
- C Call Support → C Library Declarations: uses declarations
- NASM Assembly → Runtime Assembly: links runtime
README.md