mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 06:14:59 +00:00
Extracted from modular repo and reorganized: Compiler Implementation: - 21 compiler source files (frontend, semantic, IR, codegen, runtime) - 15 comprehensive test files (lexer, parser, type checker, backend, etc.) - 9 compiler usage example programs Architecture (5 phases): - Frontend: Lexer, parser, AST generation (lexer.mojo, parser.mojo, ast.mojo) - Semantic: Type system, checking, symbol resolution (3 files) - IR: MLIR code generation (mlir_gen.mojo, mojo_dialect.mojo) - Codegen: LLVM backend, optimization passes (llvm_backend.mojo, optimizer.mojo) - Runtime: Memory mgmt, reflection, async support (3 files) File Organization: - mojo/compiler/src/: Compiler implementation (21 files, 952K) - mojo/compiler/tests/: Test suite (15 files) - mojo/compiler/examples/: Usage examples (9 files) - mojo/samples/: Mojo language examples (37 files, moved from examples/) Documentation: - mojo/CLAUDE.md: Project-level guide - mojo/compiler/CLAUDE.md: Detailed architecture documentation - mojo/compiler/README.md: Quick start guide - mojo/samples/README.md: Example programs guide Status: - Compiler architecture complete (Phase 4) - Full test coverage included - Ready for continued development and integration Files tracked: - 45 new compiler files (21 src + 15 tests + 9 examples) - 1 moved existing directory (examples → samples) - 3 documentation files created - 1 root CLAUDE.md updated Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Mojo Compiler
A complete Mojo programming language compiler written in Mojo itself.
Quick Start
Prerequisites
# Install Pixi (package manager)
curl -fsSL https://pixi.sh/install.sh | bash
# Install environment
cd mojo
pixi install
Run Compiler
# Compile and run a Mojo file
pixi run mojo program.mojo
# Format code
pixi run mojo format ./
# Run tests
pixi run test
Architecture
The compiler processes Mojo source code in 5 phases:
- Frontend - Lexing (tokenization) and parsing (AST generation)
- Semantic - Type checking and symbol resolution
- IR - Conversion to MLIR (Multi-Level Intermediate Representation)
- Codegen - LLVM IR generation and optimization
- Runtime - Memory management and runtime support
See CLAUDE.md for detailed architecture documentation.
Directory Structure
src/
├── frontend/ # Lexer, parser, AST
├── semantic/ # Type system, checker
├── ir/ # MLIR generation
├── codegen/ # LLVM backend
└── runtime/ # Runtime support
examples/ # Compiler usage examples
tests/ # Comprehensive test suite
CLAUDE.md # Architecture guide
README.md # This file
Tests
# Run all tests
pixi run test
# Run specific test category
pixi run test -- tests/test_lexer.mojo
pixi run test -- tests/test_type_checker.mojo
# Run integration tests
pixi run test -- tests/test_compiler_pipeline.mojo
Key Features
- ✅ Lexing & Parsing
- ✅ Type inference
- ✅ Trait system
- ✅ Generic types
- ✅ Ownership checking
- ✅ MLIR generation
- ✅ LLVM IR generation
- ✅ Optimization passes
- ✅ GPU kernel support
- ✅ Python interoperability
Development
For detailed development guidelines, see CLAUDE.md.
Adding Features
- Update
src/frontend/ast.mojo(add AST node) - Update
src/frontend/parser.mojo(add parsing rule) - Update
src/semantic/type_checker.mojo(add type checking) - Update
src/ir/mlir_gen.mojo(add IR generation) - Update
src/codegen/llvm_backend.mojo(add code generation) - Add tests to
tests/
Examples
See examples/ directory for:
- Simple programs
- Type system demonstration
- Trait usage
- Generic types
- Async/await
- GPU kernels
Documentation
- Architecture: See
CLAUDE.md - Type System: See
src/semantic/CLAUDE.md(if available) - Error Messages: See
src/frontend/CLAUDE.md(if available)
Status
Phase 4 Complete - Full compiler implementation with:
- Complete lexer and parser
- Type inference and checking
- MLIR and LLVM IR generation
- Optimization passes
- Ownership and borrowing system
Next: Performance optimization, advanced features
Last Updated: January 23, 2026 Source: Modular Inc. Mojo Compiler