Muninn is a small statically typed scripting language implemented in Rust.
- Primitive types:
Int,Float,Bool,String,Tensor,Void letbindings with optional local type inference- Mutable bindings via
mut - Top-level functions with typed parameters and explicit return types
ifstatements andwhileloops- Expression-valued blocks and
if/else - Assignment and function calls
- Arithmetic, comparison, and logical operators
- String concatenation with
+ - Tensor arithmetic with broadcasting and matrix multiplication
- Native runtime functions:
print,assert,tensor_zeros,tensor_fill,tensor_reshape,tensor_matmul,tensor_sum - Bytecode toolchain: compile to
.mubcand execute withrun-bc - Hot reload support that preserves globals at VM safe points
- Capacity reservation mode for allocation-free interpreter hot paths
fn abs_int(value: Int) -> Int {
if (value < 0) {
return -value;
}
return value;
}
fn gcd(a: Int, b: Int) -> Int {
let mut x: Int = abs_int(a);
let mut y: Int = abs_int(b);
while (y != 0) {
let quotient: Int = x / y;
let remainder: Int = x - quotient * y;
x = y;
y = remainder;
}
return x;
}
fn lcm(a: Int, b: Int) -> Int {
let divisor: Int = gcd(a, b);
return (a / divisor) * b;
}
let divisor: Int = gcd(84, 30);
let multiple: Int = lcm(84, 30);
assert(divisor == 6);
assert(multiple == 420);
print(divisor);
print(multiple);
divisor;
Run demo:
cargo runRun a file:
cargo run -- run examples/dsa_euclid.munType-check a file:
cargo run -- check examples/dsa_euclid.munCompile a source file to bytecode:
cargo run -- build examples/dsa_euclid.mun -o examples/dsa_euclid.mubcRun a precompiled bytecode artifact:
cargo run -- run-bc examples/dsa_euclid.mubcRun tests:
cargo test --workspaceRun benchmarks:
cargo bench --bench runtime