June 2025 (v0.2.8)
Welcome to the June 2025 release of Mochi. This update introduces code generation, broader distribution support, built-in tools, and performance improvements. As always, the focus remains on stability, usability, and developer productivity.
Go Code Generation with mochi build
The mochi build command can now compile Mochi programs to native Go applications.
fun main() {
print("Hello from Mochi!")
}
Running the following:
$ mochi build main.mochi -o hello
produces a standalone hello binary, compiled via the Go toolchain. This backend offers fast startup times and compatibility with existing Go infrastructure. Compiler output is verified with golden tests to ensure consistent and reproducible results. While this approach introduces a dependency on the Go compiler, it enables easy embedding and integration into Go-based systems.
Running Mochi via npx
Mochi is now published on npm as an executable package. This allows users to run Mochi programs without installing the runtime globally:
$ npx @mochilang/mochi run examples/hello.mochi
Hello, Mochi!
This is especially useful for trying out the language, sharing examples, or running scripts in CI environments. Note that each invocation triggers a fresh package fetch unless cached by the environment. A new make publish-npm target has been added to streamline version updates for maintainers.
Built-in MCP Server Tools
Two lightweight utilities, mochi_eval and mochi_cheatsheet, are now included in the distribution. These replace the previous reliance on the external mcp-go service for basic evaluation and lookup features.
$ echo '1 + 2' | mochi_eval
3
These tools are intended for integration into chat-driven or REPL-based environments and can operate without network access. While they cover most typical use cases, more advanced features (e.g., file I/O or plugin execution) provided by mcp-go are not currently supported in the built-in implementation.
Performance Improvements and Benchmarking Support
This release introduces a new internal representation for runtime values based on tagged unions. This change improves interpreter throughput in numeric and control-heavy programs:
let start = now()
let sum = 0
for i in 0..1_000_000 {
sum = sum + i
}
print(now() - start)
Performance benchmarks can now be run using the make bench target. These compare Mochi performance directly against equivalent Go implementations. While runtime memory usage per value has slightly increased due to tagging overhead, overall execution speed has improved significantly.
Improved Diagnostics and Robustness
Error messages during runtime are now more descriptive. For example:
let xs = [1, 2]
print(xs[5])
will produce:
slice index 5 out of range (len=2)
This makes it easier to locate and fix mistakes during development. Internally, this is backed by enhanced checks in the interpreter and runtime, with expanded test coverage across the parser, type checker, and evaluator components. These checks introduce a minor performance cost but significantly reduce unexpected failures during program execution.