Skip to content

Commit

Permalink
interp/wazero: add memory debugging and correct Halt() implementation
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Mar 29, 2024
1 parent e770a95 commit e16cdae
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions interp/wazero/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"

"github.com/hybridgroup/mechanoid"
"github.com/hybridgroup/mechanoid/engine"
"github.com/orsinium-labs/wypes"
"github.com/tetratelabs/wazero"
Expand All @@ -23,6 +24,8 @@ func (i *Interpreter) Name() string {
}

func (i *Interpreter) Init() error {
mechanoid.DebugMemory("Interpreter Init")

ctx := context.Background()
conf := wazero.NewRuntimeConfigInterpreter()
conf = conf.WithDebugInfoEnabled(false)
Expand All @@ -32,6 +35,8 @@ func (i *Interpreter) Init() error {
}

func (i *Interpreter) SetModules(modules wypes.Modules) error {
mechanoid.Log("Registering host modules...")

if i.modules == nil {
i.modules = modules
return nil
Expand All @@ -50,6 +55,8 @@ func (i *Interpreter) SetModules(modules wypes.Modules) error {
}

func (i *Interpreter) Load(code engine.Reader) error {
mechanoid.DebugMemory("Interpreter Load")

err := i.defineModules()
if err != nil {
return fmt.Errorf("register wazero host modules: %v", err)
Expand Down Expand Up @@ -115,6 +122,8 @@ func wazeroAdaptHostFunc(hf wypes.HostFunc, refs wypes.Refs) api.GoModuleFunctio
}

func (i *Interpreter) Run() (engine.Instance, error) {
mechanoid.DebugMemory("Interpreter Run")

var err error
ctx := context.Background()
init := i.module.ExportedFunction("_initialize")
Expand All @@ -128,9 +137,11 @@ func (i *Interpreter) Run() (engine.Instance, error) {
}

func (i *Interpreter) Halt() error {
mechanoid.DebugMemory("Interpreter Halt")

ctx := context.Background()
err := i.runtime.Close(ctx)
i.runtime = nil
err := i.module.Close(ctx)
i.module = nil
return err
}

Expand Down

0 comments on commit e16cdae

Please sign in to comment.