wazero

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LoggerFuncs = []funcs{
	{
		"println",
		[]parm{i32, i32},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			message := readStringFromStack(mod, stack[0:])
			length := uint32(stack[1])
			call := wasm.FromContext(ctx)

			if call.ReachedLogsMaxByteCount() {

				return
			}

			if length > wasm.MaxLogByteCount {
				panic(fmt.Errorf("message to log is too big, max size is %s", humanize.IBytes(uint64(length))))
			}

			if tracer.Enabled() {
				zlog.Debug(message, zap.String("module_name", call.ModuleName), zap.String("log_source", "wasm"))
			}
			call.AppendLog(message)
		}),
	},
}
View Source
var RustBasedSauce = runtimeSauce{"alloc", "dealloc"}
View Source
var StateFuncs = []funcs{
	{
		"set",
		[]parm{i64, i32, i32, i32, i32},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := readBytesFromStack(mod, stack[3:])
			call := wasm.FromContext(ctx)

			call.DoSet(ord, key, value)
		}),
	},
	{
		"set_if_not_exists",
		[]parm{i64, i32, i32, i32, i32},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := readBytesFromStack(mod, stack[3:])
			call := wasm.FromContext(ctx)

			call.DoSetIfNotExists(ord, key, value)
		}),
	},
	{
		"append",
		[]parm{i64, i32, i32, i32, i32},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := readBytesFromStack(mod, stack[3:])
			call := wasm.FromContext(ctx)

			call.DoAppend(ord, key, value)
		}),
	},
	{
		"delete_prefix",
		[]parm{i64, i32, i32},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			prefix := readStringFromStack(mod, stack[1:])
			call := wasm.FromContext(ctx)

			call.DoDeletePrefix(ord, prefix)
		}),
	},
	{
		"add_bigint",
		[]parm{i64, i32, i32, i32, i32},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := readStringFromStack(mod, stack[3:])
			call := wasm.FromContext(ctx)

			call.DoAddBigInt(ord, key, value)
		}),
	},
	{
		"add_bigdecimal",
		[]parm{i64, i32, i32, i32, i32},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := readStringFromStack(mod, stack[3:])
			call := wasm.FromContext(ctx)

			call.DoAddBigDecimal(ord, key, value)
		}),
	},
	{
		"add_int64",
		[]parm{i64, i32, i32, i64},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := int64(stack[3])
			call := wasm.FromContext(ctx)

			call.DoAddInt64(ord, key, value)
		}),
	},
	{
		"add_float64",
		[]parm{i64, i32, i32, f64},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := api.DecodeF64(stack[3])
			call := wasm.FromContext(ctx)

			call.DoAddFloat64(ord, key, value)
		}),
	},
	{
		"set_min_int64",
		[]parm{i64, i32, i32, i64},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := int64(stack[3])
			call := wasm.FromContext(ctx)

			call.DoSetMinInt64(ord, key, value)
		}),
	},
	{
		"set_min_bigint",
		[]parm{i64, i32, i32, i32, i32},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := readStringFromStack(mod, stack[3:])
			call := wasm.FromContext(ctx)

			call.DoSetMinBigInt(ord, key, value)
		}),
	},
	{
		"set_min_float64",
		[]parm{i64, i32, i32, f64},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := api.DecodeF64(stack[3])
			call := wasm.FromContext(ctx)

			call.DoSetMinFloat64(ord, key, value)
		}),
	},
	{
		"set_min_bigdecimal",
		[]parm{i64, i32, i32, i32, i32},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := readStringFromStack(mod, stack[3:])
			call := wasm.FromContext(ctx)

			call.DoSetMinBigDecimal(ord, key, value)
		}),
	},

	{
		"set_max_int64",
		[]parm{i64, i32, i32, i64},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := int64(stack[3])
			call := wasm.FromContext(ctx)

			call.DoSetMaxInt64(ord, key, value)
		}),
	},
	{
		"set_max_bigint",
		[]parm{i64, i32, i32, i32, i32},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := readStringFromStack(mod, stack[3:])
			call := wasm.FromContext(ctx)

			call.DoSetMaxBigInt(ord, key, value)
		}),
	},
	{
		"set_max_float64",
		[]parm{i64, i32, i32, f64},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := api.DecodeF64(stack[3])
			call := wasm.FromContext(ctx)

			call.DoSetMaxFloat64(ord, key, value)
		}),
	},
	{
		"set_max_bigdecimal",
		[]parm{i64, i32, i32, i32, i32},
		[]parm{},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			ord := stack[0]
			key := readStringFromStack(mod, stack[1:])
			value := readStringFromStack(mod, stack[3:])
			call := wasm.FromContext(ctx)

			call.DoSetMaxBigDecimal(ord, key, value)
		}),
	},

	{
		"get_at",
		[]parm{i32, i64, i32, i32, i32},
		[]parm{i32},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			storeIndex := uint32(stack[0])
			ord := stack[1]
			key := readStringFromStack(mod, stack[2:])
			outputPtr := uint32(stack[4])
			call := wasm.FromContext(ctx)
			inst := instanceFromContext(ctx)

			value, found := call.DoGetAt(int(storeIndex), ord, key)
			setStackAndOutput(ctx, stack, call, found, inst, outputPtr, value)
		}),
	},
	{
		"has_at",
		[]parm{i32, i64, i32, i32},
		[]parm{i32},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			storeIndex := uint32(stack[0])
			ord := stack[1]
			key := readStringFromStack(mod, stack[2:])
			call := wasm.FromContext(ctx)

			found := call.DoHasAt(int(storeIndex), ord, key)
			setStack0Bool(stack, found)
		}),
	},
	{
		"get_first",
		[]parm{i32, i32, i32, i32},
		[]parm{i32},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			storeIndex := uint32(stack[0])
			key := readStringFromStack(mod, stack[1:])
			outputPtr := uint32(stack[3])
			call := wasm.FromContext(ctx)
			inst := instanceFromContext(ctx)

			value, found := call.DoGetFirst(int(storeIndex), key)
			setStackAndOutput(ctx, stack, call, found, inst, outputPtr, value)
		}),
	},
	{
		"has_first",
		[]parm{i32, i32, i32},
		[]parm{i32},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			storeIndex := uint32(stack[0])
			key := readStringFromStack(mod, stack[1:])
			call := wasm.FromContext(ctx)

			found := call.DoHasFirst(int(storeIndex), key)
			setStack0Bool(stack, found)
		}),
	},
	{
		"get_last",
		[]parm{i32, i32, i32, i32},
		[]parm{i32},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			storeIndex := uint32(stack[0])
			key := readStringFromStack(mod, stack[1:])
			outputPtr := uint32(stack[3])
			call := wasm.FromContext(ctx)
			inst := instanceFromContext(ctx)

			value, found := call.DoGetLast(int(storeIndex), key)
			setStackAndOutput(ctx, stack, call, found, inst, outputPtr, value)
		}),
	},
	{
		"has_last",
		[]parm{i32, i32, i32},
		[]parm{i32},
		api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
			storeIndex := uint32(stack[0])
			key := readStringFromStack(mod, stack[1:])
			call := wasm.FromContext(ctx)

			found := call.DoHasLast(int(storeIndex), key)
			setStack0Bool(stack, found)
		}),
	},
}
View Source
var TinyGoSauce = runtimeSauce{"malloc", "free"}

Functions

func AddHostFunctions added in v1.6.0

func AddHostFunctions(ctx context.Context, runtime wazero.Runtime, moduleName string, funcs []funcs) (wazero.CompiledModule, error)

func WithInstanceContext added in v1.6.0

func WithInstanceContext(ctx context.Context, inst *Instance) context.Context

Types

type Instance added in v1.6.0

type Instance struct {
	api.Module
	// contains filtered or unexported fields
}

func NewInstance added in v1.6.0

func NewInstance(mod api.Module, memFuncs runtimeSauce) *Instance

func (*Instance) Cleanup added in v1.6.0

func (i *Instance) Cleanup(ctx context.Context) error

func (*Instance) Close added in v1.6.0

func (i *Instance) Close(ctx context.Context) error

type Module

type Module struct {
	sync.Mutex
	// contains filtered or unexported fields
}

A Module represents a wazero.Runtime that clears and is destroyed upon completion of a request. It has the pre-compiled `env` host module, as well as pre-compiled WASM code provided by the user

func (*Module) Close

func (m *Module) Close(ctx context.Context) error

func (*Module) ExecuteNewCall

func (m *Module) ExecuteNewCall(ctx context.Context, call *wasm.Call, cachedInstance wasm.Instance, arguments []wasm.Argument) (out wasm.Instance, err error)

func (*Module) NewInstance added in v1.1.9

func (m *Module) NewInstance(ctx context.Context) (out wasm.Instance, err error)

Jump to

Keyboard shortcuts

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