mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +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 Examples
Example projects demonstrating Mojo - a new programming language that combines Python syntax with systems programming performance.
Why Mojo?
- Python-like syntax - Familiar to Python developers
- Strictly typed - Compile-time type checking
- Systems performance - Comparable to C/C++/Rust
- Python interop - Import and use Python libraries
- SIMD & parallelism - First-class support for vectorization
Requirements
- Mojo SDK (free to download)
Project Structure
mojo/
├── src/
│ └── main.mojo # Main entry point
├── examples/
│ ├── hello.mojo # Hello world
│ ├── structs.mojo # Struct definitions
│ ├── simd.mojo # SIMD operations
│ ├── python_interop.mojo # Python integration
│ └── performance.mojo # Performance comparison
└── mojoproject.toml # Project configuration
Quick Start
# Run hello world
mojo examples/hello.mojo
# Build optimized binary
mojo build src/main.mojo -o main
# Run with Python interop
mojo examples/python_interop.mojo
Key Features Demonstrated
Strict Typing
fn add(x: Int, y: Int) -> Int:
return x + y
Structs with Ownership
struct Point:
var x: Float64
var y: Float64
fn __init__(inout self, x: Float64, y: Float64):
self.x = x
self.y = y
SIMD Operations
from math import sqrt
fn vector_magnitude[width: Int](v: SIMD[DType.float64, width]) -> Float64:
return sqrt((v * v).reduce_add())
Python Interop
from python import Python
fn main() raises:
let np = Python.import_module("numpy")
let arr = np.array([1, 2, 3, 4, 5])
print(arr.mean())