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>
Introduction to Mojo tutorial solution
This directory contains a complete solution for the Get started with Mojo tutorial project, which is an implementation of Conway's Game of Life cellular automation.
Files
This directory contains the following files:
-
The source files
lifev1.mojoandgridv1.mojoprovide an initial version of the project, with aGridstruct representing the grid of cells as aList[List[Int]]. -
The source files
lifev2.mojoandgridv2.mojoprovide a subsequent version of the project, with aGridstruct representing the grid of cells as a block of memory managed byUnsafePointer. -
The source files
lifev3.mojoandgridv3.mojoprovide a subsequent version of the project to parallelize the evolution of rows across available CPU cores. -
The
benchmark.mojofile performs a simple performance benchmark of the three versions by running 1,000 evolutions of eachGridimplementation using a 1,024 x 1,024 grid. -
The
testdirectory contains unit tests for eachGridimplementation using the Mojo testing framework. -
The
pixi.tomlfile is a Pixi project file containing the project dependencies and task definitions.
Run the code
If you have Pixi installed, you can execute version 1 of the program by running the following command:
pixi run lifev1
This displays a window that shows an initial random state for the grid and then
automatically updates it with subsequent generations. Quit the program by
pressing the q or <Escape> key or by closing the window.
You can execute version 2 or version 3 of the program by running one of the following two commands:
pixi run lifev2
pixi run lifev3
Just like for version 1, this displays a window that shows an initial random
state for the grid and then automatically updates it with subsequent
generations. Quit the program by pressing the q or <Escape> key or by
closing the window.
You can execute the benchmark program by running the following command:
pixi run benchmark
You can run the unit tests by running the following command:
pixi run test
Dependencies
This project includes an example of using a Python package, pygame-ce, from Mojo. Building the program does not embed pygame or a Python runtime in the resulting executable. Therefore, to run this program your environment must have both a compatible Python runtime (Python 3.12) and the pygame package installed.
The easiest way to ensure that the runtime dependencies are met is to run the
program with pixi, which manages a virtual
environment for the project as defined by the pixi.toml file.