mvm - a fast virtual machine for Go

mvm - a fast virtual machine for Go

mvm - a fast virtual machine for Go and beyond. Run programs directly from source. Embed a full Go interpreter. Dynamically extend your apps. Batteries included. mvm —— 一个适用于 Go 及更多场景的高性能虚拟机。支持直接从源码运行程序,嵌入完整的 Go 解释器,动态扩展你的应用程序,且内置了丰富的功能。

Try it in the browser → View on GitHub 在浏览器中尝试 → 在 GitHub 上查看

go install github.com/mvm-sh/mvm@latest go install github.com/mvm-sh/mvm@latest

Fast bytecode VM Portable, stack-based virtual machine designed for low overhead. 高性能字节码虚拟机 一个可移植的、基于栈的虚拟机,专为低开销而设计。

Go-compatible Aims to be fully compatible with Go — the same source, no compiler. Go 兼容 旨在与 Go 完全兼容——使用相同的源码,无需编译器。

Embeddable Drop into Go, C, or other host applications. See the examples. 可嵌入 可轻松嵌入到 Go、C 或其他宿主应用程序中。查看示例。

REPL & debugger Integrated interactive REPL, debugger, and test engine. REPL 与调试器 集成了交互式 REPL、调试器和测试引擎。

Batteries included One single static binary, with the full standard library bundled in. 内置丰富功能 单个静态二进制文件,捆绑了完整的标准库。


A quick taste

快速上手

package main

import "iter"

func squares(n int) iter.Seq[int] {
    return func(yield func(int) bool) {
        for i := 1; i <= n; i++ {
            if !yield(i * i) {
                return
            }
        }
    }
}

func main() {
    sum := 0
    for v := range squares(4) {
        sum += v
    }
    println(sum)
}

Open in playground → Run it 在 Playground 中打开 → 运行它

mvm Start the REPL 启动 REPL

mvm _samples/fib.go Run a Go source file 运行 Go 源码文件

mvm run -e “fmt.Println(1+2)” Evaluate an inline expression 执行内联表达式

mvm test ./pkg Run TestX functions in a package 运行包中的 TestX 函数

mvm help List subcommands 列出子命令


Learn more Documentation — entry point Architecture — pipeline, memory model, key design decisions Contributing

了解更多 文档 —— 入门指南 架构 —— 流水线、内存模型、关键设计决策 贡献指南