package goarch

import "github.com/tetratelabs/wazero/internal/gojs/goarch"

Package goarch isolates code from runtime.GOARCH=wasm in a way that avoids cyclic dependencies when re-used from other packages.

Index

Functions

func GetSP

func GetSP(mod api.Module) uint32

GetSP gets the stack pointer, which is needed prior to storing a value when in an operation that can trigger a Go event handler.

See https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L210-L213

func NewFunc

func NewFunc(name string, goFunc Func) *wasm.HostFunc

func StubFunction

func StubFunction(name string) *wasm.HostFunc

StubFunction stubs functions not used in Go's main source tree. This traps (unreachable opcode) to ensure the function is never called.

Types

type Func

type Func func(context.Context, api.Module, Stack)

type Stack

type Stack interface {
	// Name is the function name being invoked.
	Name() string

	Param(i int) uint64

	// ParamBytes reads a byte slice, given its memory offset and length (stack
	// positions i, i+1)
	ParamBytes(mem api.Memory, i int) []byte

	// ParamString reads a string, given its memory offset and length (stack
	// positions i, i+1)
	ParamString(mem api.Memory, i int) string

	ParamInt32(i int) int32

	ParamUint32(i int) uint32

	// Refresh the stack from the current stack pointer (SP).
	//
	// Note: This is needed prior to storing a value when in an operation that
	// can trigger a Go event handler.
	Refresh(api.Module)

	SetResult(i int, v uint64)

	SetResultBool(i int, v bool)

	SetResultI32(i int, v int32)

	SetResultI64(i int, v int64)

	SetResultUint32(i int, v uint32)
}

func NewStack

func NewStack(name string, mem api.Memory, sp uint32) Stack

Source Files

wasm.go

Version
v1.6.0
Published
Dec 22, 2023
Platform
linux/amd64
Imports
6 packages
Last checked
11 minutes ago

Tools for package owners.