emscripten

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const FunctionNotifyMemoryGrowth = "emscripten_notify_memory_growth"
View Source
const FunctionThrowLongjmp = "_emscripten_throw_longjmp"

Emscripten uses this host method to throw an error that can then be caught in the dynamic invoke functions. Emscripten uses this to allow for setjmp/longjmp support. When this error is seen in the invoke handler, it ignores the error and does not act on it.

View Source
const InvokePrefix = "invoke_"

InvokePrefix is the naming convention of Emscripten dynamic functions.

All `invoke_` functions have an initial "index" parameter of api.ValueTypeI32. This is the index of the desired funcref in the only table in the module. The type of the funcref is via naming convention. The first character after `invoke_` decides the result type: 'v' for no result or 'i' for api.ValueTypeI32. Any count of 'i' following that are api.ValueTypeI32 parameters.

For example, the function `invoke_iiiii` signature has five parameters, but also five i's. The five 'i's mean there are four parameters

(import "env" "invoke_iiiii" (func $invoke_iiiii
	(param i32 i32 i32 i32 i32) (result i32))))

So, the above function if invoked `invoke_iiiii(1234, 1, 2, 3, 4)` would look up the funcref at table index 1234, which has a type i32i32i3232_i32 and invoke it with the remaining parameters.

Variables

View Source
var (
	ThrowLongjmpError = errors.New("_emscripten_throw_longjmp")
	ThrowLongjmp      = &wasm.HostFunc{
		ExportName: FunctionThrowLongjmp,
		Name:       FunctionThrowLongjmp,
		ParamTypes: []wasm.ValueType{},
		ParamNames: []string{},
		Code: wasm.Code{GoFunc: api.GoModuleFunc(func(context.Context, api.Module, []uint64) {
			panic(ThrowLongjmpError)
		})},
	}
)
View Source
var NotifyMemoryGrowth = &wasm.HostFunc{
	ExportName: FunctionNotifyMemoryGrowth,
	Name:       FunctionNotifyMemoryGrowth,
	ParamTypes: []wasm.ValueType{wasm.ValueTypeI32},
	ParamNames: []string{"memory_index"},
	Code:       wasm.Code{GoFunc: api.GoModuleFunc(func(context.Context, api.Module, []uint64) {})},
}

Functions

func NewInvokeFunc

func NewInvokeFunc(importName string, params, results []api.ValueType) *wasm.HostFunc

Types

type InvokeFunc

type InvokeFunc struct {
	*wasm.FunctionType
}

func (*InvokeFunc) Call

func (v *InvokeFunc) Call(ctx context.Context, mod api.Module, stack []uint64)

Call implements api.GoModuleFunction by special casing dynamic calls needed for emscripten `invoke_` functions such as `invoke_ii` or `invoke_v`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL