Files
metabuilder/mojo/samples/examples
johndoe6345789 83f1533bce feat(mojo): integrate Modular Mojo compiler implementation
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>
2026-01-23 19:05:44 +00:00
..

Mojo code examples

This directory contains a collection of sample programs written in the Mojo programming language.

Getting started

You can use git to clone the repository containing all of these sample programs:

git clone https://github.com/modular/modular.git

For the most reliable experience building and running these examples, we recommend using Pixi. It's both a package manager and virtual environment manager—which alone makes development a lot easier—but it's also fast, language agnostic, and provides lock files for package dependencies. For more help with it, see our Pixi basics guide.

Each subdirectory of this directory is a self-contained project that demonstrates features of the Mojo programming language and its standard library. Each contains a README.md file and a pixi.toml file that specifies the required dependencies. Simply follow the instructions in each README.md file to use pixi to download and install the dependencies for the project and to build and run the examples.

For more information on system requirements, installing Mojo and the Mojo extension for VS Code, and getting started with Mojo programming, see the Install Mojo section of the Mojo Manual.

Example subdirectories

  • life/: The Get started with Mojo tutorial solution. A complete implementation of Conway's Game of Life cellular automaton, demonstrating Mojo basics including structs, modules, and Python interoperability.

  • gpu-intro/: The Get started with GPU programming tutorial solution. An introduction to GPU programming in Mojo with a simple vector addition kernel.

  • gpu-functions/: GPU kernel implementations including vector addition, grayscale conversion, matrix multiplication, Mandelbrot set calculation, and reduction operations.

  • gpu-block-and-warp/: Advanced GPU programming demonstrating block-level and warp-level synchronization and operations.

  • python-interop/: Calling Mojo functions from Python code, enabling progressive migration of Python hotspots to Mojo.

  • layouts/: Using Mojo's layout package for working with dense multidimensional arrays.

  • layout_tensor/: Companion code for Using LayoutTensor

  • operators/: Implementing operators for a custom Mojo type.

  • testing/: Writing and running unit tests using the Mojo testing framework.

License

The Mojo examples in this repository are licensed under the Apache License v2.0 with LLVM Exceptions (see the LLVM License).

Contributing

As a contributor, your efforts and expertise are invaluable in driving the evolution of the Mojo programming language. The Mojo contributor guide provides all the information necessary to make meaningful contributions—from understanding the submission process to adhering to best practices.