Skip to content

wheevu/muninn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Muninn 🐦‍⬛

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

Features

Language

  • Primitive types: Int, Float, Bool, String, Tensor, and Void
  • let bindings with optional local type inference, plus mut for mutable variables
  • Functions with typed parameters and explicit return types
  • Control flow with if, while, expression-valued blocks, and if/else
  • Assignment, function calls, arithmetic, comparison, and logical operators
  • String concatenation with +
  • Tensor arithmetic with broadcasting and matrix multiplication

Runtime

  • Built-in functions for printing and assertions
  • Tensor built-ins for creating, reshaping, multiplying, and reducing tensors

Tooling

  • Type-check source files
  • Compile programs to .mubc bytecode
  • Run source files or precompiled bytecode
  • Hot reload with global preservation at VM safe points

Performance

  • 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.

Resources

License

Stars

Watchers

Forks

Contributors