xvm/runtime/go/runtime.go
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
package gowasm
import (
"time"
"github.com/xuperchain/xuperunion/xvm/debug"
"github.com/xuperchain/xuperunion/xvm/exec"
"github.com/xuperchain/xuperunion/xvm/runtime/go/js"
"github.com/xuperchain/xuperunion/xvm/runtime/go/js/fs"
)
const (
goRuntimeKey = "goruntime"
)
// Runtime implements the runtime needed to run wasm code compiled by go toolchain
type Runtime struct {
exitcode int32
exited bool
global *js.Global
jsvm *js.VM
ctx exec.Context
timeOrigin time.Time
}
// RegisterRuntime 用于向exec.Context里面注册一个初始化好的js Runtime
func RegisterRuntime(ctx exec.Context) *Runtime {
rt := &Runtime{
global: js.NewGlobal(),
timeOrigin: time.Now(),
ctx: ctx,
}
ctx.SetUserData(goRuntimeKey, rt)
jsmem := js.NewMemory(func() []byte {
return rt.ctx.Memory()
})
rt.jsvm = js.NewVM(&js.VMConfig{
Memory: jsmem,
Global: rt.global,
})
rt.global.Register("Fs", fs.NewFS())
return rt
}
func (rt *Runtime) wasmExit(code int32) {
rt.exitcode = code
rt.exited = true
}
func (rt *Runtime) wasmWrite(fd int64, p int64, n int32) {
codec := exec.NewCodec(rt.ctx)
if fd == 1 || fd == 2 {
debug.Write(rt.ctx, codec.Bytes(uint32(p), uint32(n)))
}
}
func (rt *Runtime) nanotime() int64 {
return 1
后面还有 96 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
