muni2wasm
A compiler that turns Muni source code into WebAssembly.
- Written in Python, ships with a CLI
- No system tools required — uses the Python WABT package to assemble
- Optional: run the resulting
.wasmwith Wasmtime (Python binding)
Table of contents
Installation
pip install muni2wasm
Python 3.10+ recommended.
Quick start
# Compile .mun → .wasm
muni2wasm compile hello.mun out.wasm
# Run .wasm (requires wasmtime)
muni2wasm run out.wasm
Use --debug to see full Python tracebacks on errors.
The Muni language
Types
- Primitives:
int,boolean,char - Special:
void(functions that don’t return a value) - Generic array:
array<T> - User types:
structure(fields + methods, can be generic)
Internally targets WebAssembly i32 for now.
Structures & generics
structure List<T> {
T element;
List<T> next;
List<T>(T element) { # constructor
this.element = element;
this.next = null;
}
void append(T element) {
List<T> cur = this;
while (cur.next != null) {
cur = cur.next;
}
cur.next = List<T>(element);
}
}
void main() {
List<int> xs = List<int>(3);
xs.append(4);
}
Type aliases
alias numbers = array<int>;
alias index<T> = pair<int, T>;
Control flow
if / elsefor (init; cond; post) { ... }while (cond) { ... }until (cond) { ... }do <X> { ... } <while (cond)>
Operators
- Arithmetic:
+ - * / %(ints) - Comparisons:
> < >= <= == !=(mostly ints) - Logical:
&& || ! - Unary:
-(negate),!(not)
Literals
123
true / false
'x' # char
"hello!\n" # string
[1, 2, 3] # array literal
null
Imports
- File imports (inlines another
.munfile; path is relative):
import <vector.mun>;
- Library imports (inlines a library file)
import <math.lib>; # imports the math.mun lib
- Host imports (declare a host function available at runtime):
import env.write_int(int) -> void;
import env.write_chr(int) -> void;
Strings
string is an alias for vec<char> (and char is just an alias for int).
vec<T>is structure that represents a growable vector aroundarray<T>withsize,capacity,get,set,push_back, …array<T>layout is{ length, buffer_ptr }in linear memory.
The standard helpers live in lib/std.mun (e.g., the definition of vec, a print(string) that calls the host env.write_chr per character).
CLI
muni2wasm compile <input.mun> <output.(wat|wasm)> [--debug]
muni2wasm run <module.wasm> [--debug]
-
compileemits.wator.wasm(based on the output suffix), assembling via Python WABT. -
runloads the module with Wasmtime and wires a minimal host environment:env.write_int(i32)— print integerenv.write_chr(i32)— print a single character code (ASCII/UTF-8 byte)
You can define your own host imports and call them from Muni via
import module.name(...) -> ...;.
Notes
- Currently uses i32 only (no floats yet).
charis anintunder the hood; escape sequences like'\n'are supported.- Strings are
vec<char>; printing strings typically iterates chars and callswrite_chr. - Type aliases are expanded before type-checking; generic arity is validated.
- Diagnostics include
file:line:col.
Contributing
PRs and discussions welcome! Ideas & roadmap:
- Add
f32 - Better diagnostics
- More stdlib (strings, I/O helpers)
- JS/Web runner
- Lambdas / closures (and lambda lifting)
- More tests
License
MIT
Metadata
Release files for muni2wasm 0.1.3.post2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| muni2wasm-0.1.3.post2.tar.gz | 40.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| muni2wasm-0.1.3.post2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 82.7 kB
Release files / muni2wasm-0.1.3.post2.tar.gz
| Download URL | muni2wasm-0.1.3.post2.tar.gz |
|---|---|
| Size | 40.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f87ea6812be5b1028ff93200abaa1cb37db9a2d714bde2c8a0fa311dbfb59503
|
|
BLAKE2b-256 checksum How to use checksums |
6e4e5b6a8bcc1d280ef18c11b3ba90f3eb6603e752651561616069c8a7af9390
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Release files / muni2wasm-0.1.3.post2-py3-none-any.whl
| Download URL | muni2wasm-0.1.3.post2-py3-none-any.whl |
|---|---|
| Size | 42.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36e5c2871793a50b881fd46312ca0c79024b704a42722243bb9402aff745ce57
|
|
BLAKE2b-256 checksum How to use checksums |
db4a15d4f1892ef1bffc8274b4110f48d350d0227979a1b0fa02a1429f8310e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|