Files
metabuilder/mojo/samples/examples/layouts/basic_layouts.mojo
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

58 lines
1.6 KiB
Mojo

# ===----------------------------------------------------------------------=== #
# Copyright (c) 2025, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# DOC: mojo/docs/manual/layout/layouts.mdx
from layout import IntTuple, Layout, print_layout
fn row_and_column_major():
print("row major and column major")
var l2x4row_major = Layout.row_major(2, 4)
print_layout(l2x4row_major)
print()
var l6x6col_major = Layout.col_major(6, 6)
print_layout(l6x6col_major)
print()
fn coords_to_index():
print("coordinates to index")
var l3x4row_major = Layout.row_major(3, 4)
print_layout(l3x4row_major)
var coords: IntTuple = [1, 1]
var idx = l3x4row_major(coords)
print("index at (1, 1): ", idx)
print("coordinates at index 7:", l3x4row_major.idx2crd(7))
print()
fn nested_modes():
print("nested modes")
var layout_a = Layout([4, 4], [4, 1])
print_layout(layout_a)
print()
var layout_b = Layout(
[[2, 2], [2, 2]],
[[1, 4], [2, 8]],
)
print_layout(layout_b)
print()
def main():
row_and_column_major()
coords_to_index()
nested_modes()