Skip to content

wheevu/muninn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Muninn 🐦‍⬛

Muninn is a small statically typed scripting language implemented in Rust.

Features

  • Primitive types: Int, Float, Bool, String, Tensor, Void
  • let bindings with optional local type inference
  • Mutable bindings via mut
  • Top-level functions with typed parameters and explicit return types
  • if statements and while loops
  • 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 .mubc and execute with run-bc
  • Hot reload support that preserves globals at VM safe points
  • Capacity reservation mode for allocation-free interpreter hot paths

Example

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;

Commands

Run demo:

cargo run

Run a file:

cargo run -- run examples/dsa_euclid.mun

Type-check a file:

cargo run -- check examples/dsa_euclid.mun

Compile a source file to bytecode:

cargo run -- build examples/dsa_euclid.mun -o examples/dsa_euclid.mubc

Run a precompiled bytecode artifact:

cargo run -- run-bc examples/dsa_euclid.mubc

Run tests:

cargo test --workspace

Run benchmarks:

cargo bench --bench runtime

About

A statically typed, expression-oriented language that compiles to bytecode and runs on a stack VM.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors