MoonBit Eval Package
let vm = MoonBitVM::new()
// Basic expressions
inspect(vm.eval("1 + 2 * 3"), content="7")
inspect(vm.eval("\"hello\" + \" world\""), content="hello world")
// Variables and functions
inspect(vm.eval("let x = 42"), content="()")
inspect(vm.eval("fn double(n: Int) -> Int { n * 2 }"), content="(n: Int) -> Int")
inspect(vm.eval("double(x)"), content="84")
// Control flow
inspect(vm.eval("if x > 40 { \"big\" } else { \"small\" }"), content="big")
// Pattern matching
inspect(vm.eval("match (1, 2) { (a, b) => a + b }"), content="3")| Feature | Status | Description | |
|---|---|---|---|
| Core Language | |||
| Basic Types (Int, Bool, String, Double, Char) | â | Full support for primitive types | |
| Expressions (arithmetic, logical, comparison) | â | Complete expression evaluation | |
| Variables (let, let mut) | â | Immutable and mutable variables | |
| Assignment | â | Variable reassignment and shadowing | |
| Control Flow | |||
| If-else | â | Conditional expressions | |
| For loops | â | C-style for loops with continue/break | |
| While loops | â | While loop constructs with else clause | |
| Loop control | â | Continue and break statements | |
| Functions | |||
| Function definitions | â | Named functions with parameters | |
| Named parameters | â | Named and optional parameters | |
| Lambda expressions | â | Anonymous functions (x => x * 2) | |
| Closures | â | Proper closure environment capture | |
| Recursive functions | â | Self-referencing function calls | |
| Currying | â | Higher-order function composition | |
| External functions | â | Integration with external calls | |
| Embedded functions | â | Native function integration | |
| Data Structures | |||
| Arrays | â | Array creation, indexing, assignment | |
| Array methods | â | length, get, push, pop, contains, slice, concat, join | |
| Array boolean methods | â | any, all operations | |
| Tuples | â | Tuple creation, access, destructuring | |
| Structs | â | Custom data types with methods | |
| Mutable struct fields | â | Field mutation support | |
| Nested struct references | â | Reference semantics for nested structures | |
| Pattern Matching | |||
| Basic patterns | â | Constants, variables, wildcards | |
| Tuple patterns | â | Destructuring tuples | |
| Array patterns | â | Array destructuring | |
| Record patterns | â | Struct field matching | |
| Range patterns | â | Range expressions (_..<x, 'a'..='z') | |
| Constructor patterns | â | Constant constructor matching | |
| Or patterns | â | Multiple pattern alternatives | |
| Nested patterns | â | Complex nested pattern matching | |
| Enums and Generics | |||
| Basic enums | â | Simple enumeration types | |
| Enums with data | â | Algebraic data types | |
| Enum pattern matching | â | Pattern matching on enum variants | |
| Generic types | â | Generic enums and functions | |
| Generic functions | â | Polymorphic function definitions | |
| Option Type | |||
| Option basics | â | Some/None construction | |
| Option pattern matching | â | Pattern matching on Option | |
| Option methods | â | unwrap, unwrap_or, is_empty, map, filter | |
| Built-in Methods | |||
| Bool methods | â | compare, default | |
| Int methods | â | Bitwise ops, comparisons, bit manipulation | |
| String methods | â | length, get, unsafe_get, to_string | |
| Double methods | â | compare, to_int64 | |
| Char methods | â | compare, to_int | |
| Advanced Features | |||
| Type system | â | Basic type checking and inference | |
| Static method calls | â | Class::method() syntax | |
| Pipe operator | â | > operator for function chaining | |
| Function aliases | â | Alias support (e.g., not for %bool_not) | |
| Not Yet Supported | |||
| For-in loops | â | Iterator-based loops (commented out in tests) | |
| Traits | â | Interface definitions | |
| Packages | â | Module system | |
| Error handling | â | Result type error handling | |
| Async/await | â | Asynchronous programming |

fn add_embedded_fn(vm : MoonBitVM, name : String, func : (RuntimeFunctionContext) -> RuntimeValue) -> Unitfn add_embedded_method(vm : MoonBitVM, name : String, method_name : String, func : (RuntimeFunctionContext) -> RuntimeValue) -> Unitfn add_extern_fn(vm : MoonBitVM, name : String, func : (RuntimeFunctionContext) -> RuntimeValue) -> Unit