Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions recipes/mojo2wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Mojo2Wasm

An experimental, self-hosted compiler frontend written **entirely in Mojo** to compile Mojo source code into WebAssembly (Wasm).

The goal of this project is to bridge the gap between Mojo's high-performance systems programming capabilities and the web/edge ecosystem.

## Why Mojo2Wasm?

While official WebAssembly support is still maturing in the core toolchain, `mojo2wasm` takes a grassroots, native approach. By building the compiler in Mojo itself, this project dogfoods the language's strict memory management, powerful `struct` system, and performance capabilities to generate optimized Wasm binaries.

## How It Works (Architecture)

The compiler bypasses heavy toolchain dependencies by implementing a custom compilation pipeline:

1. **Lexing & Parsing:** Scans native Mojo source code and converts it into a structured Abstract Syntax Tree (AST) using highly efficient Mojo data structures.
2. **Type Checking & Lowering:** (In Progress) Maps Mojo's strict type system and object model down to WebAssembly primitives.
3. **Code Generation:** Translates the valid AST nodes directly into WebAssembly format, utilizing Wasm's linear memory model.

## 📁 Repository Structure

* `/src`: Core compiler source code (Lexer, Parser, AST structures, and Code Generator).
* `/examples`: Sample Mojo files intended to be compiled to Wasm.
* `/tests`: Test suites verifying AST generation and Wasm output compliance.
* `main.mojo`: The primary entry point for the CLI tool.

## 🚧 Current Project Status

This project is a **Work in Progress (WIP)**.

### Roadmap:
- [x] Lexer & Tokenizer for basic Mojo syntax
- [ ] AST Node definitions for variables, functions, and control flow
- [ ] WebAssembly Text Format (`.wat`) emitter
- [ ] WebAssembly Binary Format (`.wasm`) encoder
- [ ] Memory allocator mapping (Mojo pointers to Wasm linear memory)
- [ ] Support for Mojo `fn` and `struct` definitions

## 📄 License

This project is licensed under the MIT License - see the LICENSE file for details.
Binary file added recipes/mojo2wasm/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions recipes/mojo2wasm/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
schema_version: 1

context:
version: 0.1.1
mojo_version: "=0.26.1"

package:
name: mojo2wasm
version: ${{ version }}

source:
git: https://github.com/ravioli67/mojo2wasm.git
tag: v${{ version }}

build:
number: 0
script:
- mkdir -p $PREFIX/lib/mojo
- mojo package src -o $PREFIX/lib/mojo/mojo2wasm.mojopkg

requirements:
build:
- mojo-compiler ${{ mojo_version }}
host:
- mojo-compiler ${{ mojo_version }}
run:
- ${{ pin_compatible('mojo-compiler') }}

tests:
- package_contents:
files:
- lib/mojo/mojo2wasm.mojopkg

about:
homepage: https://github.com/ravioli67/mojo2wasm
license: MIT
license_file: LICENSE
summary: A library to convert Mojo to WebAssembly
description: |
An experimental, self-hosted compiler frontend written entirely
in Mojo to compile Mojo source code into WebAssembly (Wasm).

The goal of this project is to bridge the gap between Mojo's
high-performance systems programming capabilities and the web/edge
ecosystem.
documentation: https://github.com/ravioli67/mojo2wasm/blob/main/README.md
repository: https://github.com/ravioli67/mojo2wasm

extra:
recipe-maintainers:
- ravioli67