Documentation
¶
Overview ¶
Package wasm provides the generic components used to build wazero plugins.
Index ¶
- Constants
- Variables
- func Build[T Module](runtime wazero.Runtime, mod HostModule[T], decorators ...Decorator[T]) wazero.HostModuleBuilder
- func Configure[T any](value T, options ...Option[T])
- func Instantiate[T Module](ctx *InstantiationContext, compiled *CompiledModule[T], opts ...Option[T]) (api.Module, error)
- func NewCallContext(ctx context.Context, ins *InstantiationContext) context.Context
- func Read(memory api.Memory, offset, length uint32) []byte
- func WithCallContext[T Module](ctx context.Context, mod HostModule[T], opts ...Option[T]) (context.Context, func())
- type Array
- func (arg Array[T]) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Array[T]) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Array[T]) LoadObject(memory api.Memory, object []byte) Array[T]
- func (arg Array[T]) LoadValue(memory api.Memory, stack []uint64) Array[T]
- func (arg Array[T]) ObjectSize() int
- func (arg Array[T]) StoreObject(memory api.Memory, object []byte)
- func (arg Array[T]) ValueTypes() []api.ValueType
- type Bytes
- func (arg Bytes) Format(w io.Writer)
- func (arg Bytes) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Bytes) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Bytes) LoadObject(memory api.Memory, object []byte) Bytes
- func (arg Bytes) LoadValue(memory api.Memory, stack []uint64) Bytes
- func (arg Bytes) ObjectSize() int
- func (arg Bytes) StoreObject(memory api.Memory, object []byte)
- func (arg Bytes) ValueTypes() []api.ValueType
- type CompilationContext
- type CompiledModule
- type Decorator
- type Errno
- type Error
- type Float32
- func (arg Float32) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Float32) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Float32) LoadObject(memory api.Memory, object []byte) Float32
- func (arg Float32) LoadValue(memory api.Memory, stack []uint64) Float32
- func (arg Float32) ObjectSize() int
- func (arg Float32) StoreObject(memory api.Memory, object []byte)
- func (arg Float32) StoreValue(memory api.Memory, stack []uint64)
- func (arg Float32) ValueTypes() []api.ValueType
- type Float64
- func (arg Float64) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Float64) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Float64) LoadObject(memory api.Memory, object []byte) Float64
- func (arg Float64) LoadValue(memory api.Memory, stack []uint64) Float64
- func (arg Float64) ObjectSize() int
- func (arg Float64) StoreObject(memory api.Memory, object []byte)
- func (arg Float64) StoreValue(memory api.Memory, stack []uint64)
- func (arg Float64) ValueTypes() []api.ValueType
- type Function
- func F0[T any, R Result](fn func(T, context.Context) R) Function[T]
- func F1[T any, P Param[P], R Result](fn func(T, context.Context, P) R) Function[T]
- func F2[T any, P1 Param[P1], P2 Param[P2], R Result](fn func(T, context.Context, P1, P2) R) Function[T]
- func F3[T any, P1 Param[P1], P2 Param[P2], P3 Param[P3], R Result](fn func(T, context.Context, P1, P2, P3) R) Function[T]
- func F4[T any, P1 Param[P1], P2 Param[P2], P3 Param[P3], P4 Param[P4], R Result](fn func(T, context.Context, P1, P2, P3, P4) R) Function[T]
- func F5[T any, P1 Param[P1], P2 Param[P2], P3 Param[P3], P4 Param[P4], P5 Param[P5], ...](fn func(T, context.Context, P1, P2, P3, P4, P5) R) Function[T]
- func F6[T any, P1 Param[P1], P2 Param[P2], P3 Param[P3], P4 Param[P4], P5 Param[P5], ...](fn func(T, context.Context, P1, P2, P3, P4, P5, P6) R) Function[T]
- func F7[T any, P1 Param[P1], P2 Param[P2], P3 Param[P3], P4 Param[P4], P5 Param[P5], ...](fn func(T, context.Context, P1, P2, P3, P4, P5, P6, P7) R) Function[T]
- func F8[T any, P1 Param[P1], P2 Param[P2], P3 Param[P3], P4 Param[P4], P5 Param[P5], ...](fn func(T, context.Context, P1, P2, P3, P4, P5, P6, P7, P8) R) Function[T]
- type Functions
- type HostModule
- type InstantiationContext
- type Int16
- func (arg Int16) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Int16) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Int16) LoadObject(memory api.Memory, object []byte) Int16
- func (arg Int16) LoadValue(memory api.Memory, stack []uint64) Int16
- func (arg Int16) ObjectSize() int
- func (arg Int16) StoreObject(memory api.Memory, object []byte)
- func (arg Int16) StoreValue(memory api.Memory, stack []uint64)
- func (arg Int16) ValueTypes() []api.ValueType
- type Int32
- func (arg Int32) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Int32) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Int32) LoadObject(memory api.Memory, object []byte) Int32
- func (arg Int32) LoadValue(memory api.Memory, stack []uint64) Int32
- func (arg Int32) ObjectSize() int
- func (arg Int32) StoreObject(memory api.Memory, object []byte)
- func (arg Int32) StoreValue(memory api.Memory, stack []uint64)
- func (arg Int32) ValueTypes() []api.ValueType
- type Int64
- func (arg Int64) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Int64) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Int64) LoadObject(memory api.Memory, object []byte) Int64
- func (arg Int64) LoadValue(memory api.Memory, stack []uint64) Int64
- func (arg Int64) ObjectSize() int
- func (arg Int64) StoreObject(memory api.Memory, object []byte)
- func (arg Int64) StoreValue(memory api.Memory, stack []uint64)
- func (arg Int64) ValueTypes() []api.ValueType
- type Int8
- func (arg Int8) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Int8) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Int8) LoadObject(memory api.Memory, object []byte) Int8
- func (arg Int8) LoadValue(memory api.Memory, stack []uint64) Int8
- func (arg Int8) ObjectSize() int
- func (arg Int8) StoreObject(memory api.Memory, object []byte)
- func (arg Int8) StoreValue(memory api.Memory, stack []uint64)
- func (arg Int8) ValueTypes() []api.ValueType
- type List
- func (arg List[T]) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg List[T]) Index(index int) T
- func (arg List[T]) Len() int
- func (arg List[T]) LoadValue(memory api.Memory, stack []uint64) List[T]
- func (arg List[T]) Range(fn func(int, T) bool)
- func (arg List[T]) ValueTypes() []api.ValueType
- type Memory
- func (mem Memory) Definition() api.MemoryDefinition
- func (mem Memory) Grow(uint32) (uint32, bool)
- func (mem Memory) Read(offset, length uint32) ([]byte, bool)
- func (mem Memory) ReadByte(offset uint32) (byte, bool)
- func (mem Memory) ReadFloat32Le(offset uint32) (float32, bool)
- func (mem Memory) ReadFloat64Le(offset uint32) (float64, bool)
- func (mem Memory) ReadUint16Le(offset uint32) (uint16, bool)
- func (mem Memory) ReadUint32Le(offset uint32) (uint32, bool)
- func (mem Memory) ReadUint64Le(offset uint32) (uint64, bool)
- func (mem Memory) Size() uint32
- func (mem Memory) Write(offset uint32, value []byte) bool
- func (mem Memory) WriteByte(offset uint32, value byte) bool
- func (mem Memory) WriteFloat32Le(offset uint32, value float32) bool
- func (mem Memory) WriteFloat64Le(offset uint32, value float64) bool
- func (mem Memory) WriteString(offset uint32, value string) bool
- func (mem Memory) WriteUint16Le(offset uint32, value uint16) bool
- func (mem Memory) WriteUint32Le(offset uint32, value uint32) bool
- func (mem Memory) WriteUint64Le(offset uint32, value uint64) bool
- type Module
- type None
- func (None) FormatObject(w io.Writer, _ api.Memory, _ []byte)
- func (None) FormatValue(w io.Writer, _ api.Memory, _ []uint64)
- func (None) LoadObject(api.Memory, []byte) (none None)
- func (None) LoadValue(api.Memory, []uint64) (none None)
- func (None) ObjectSize() int
- func (None) StoreObject(api.Memory, []byte)
- func (None) StoreValue(api.Memory, []uint64)
- func (None) ValueTypes() []api.ValueType
- type Object
- type Option
- type Optional
- func (opt Optional[T]) Error() error
- func (opt Optional[T]) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (opt Optional[T]) LoadValue(memory api.Memory, stack []uint64) Optional[T]
- func (opt Optional[T]) Result() T
- func (opt Optional[T]) StoreValue(memory api.Memory, stack []uint64)
- func (opt Optional[T]) ValueTypes() []api.ValueType
- type Param
- type ParamResult
- type Pointer
- func (arg Pointer[T]) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Pointer[T]) Index(index int) Pointer[T]
- func (arg Pointer[T]) Load() (value T)
- func (arg Pointer[T]) LoadValue(memory api.Memory, stack []uint64) Pointer[T]
- func (arg Pointer[T]) Memory() api.Memory
- func (arg Pointer[T]) Object() []byte
- func (arg Pointer[T]) Offset() uint32
- func (arg Pointer[T]) Store(value T)
- func (arg Pointer[T]) ValueTypes() []api.ValueType
- type Result
- type SEGFAULT
- type String
- type Uint16
- func (arg Uint16) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Uint16) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Uint16) LoadObject(memory api.Memory, object []byte) Uint16
- func (arg Uint16) LoadValue(memory api.Memory, stack []uint64) Uint16
- func (arg Uint16) ObjectSize() int
- func (arg Uint16) StoreObject(memory api.Memory, object []byte)
- func (arg Uint16) StoreValue(memory api.Memory, stack []uint64)
- func (arg Uint16) ValueTypes() []api.ValueType
- type Uint32
- func (arg Uint32) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Uint32) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Uint32) LoadObject(memory api.Memory, object []byte) Uint32
- func (arg Uint32) LoadValue(memory api.Memory, stack []uint64) Uint32
- func (arg Uint32) ObjectSize() int
- func (arg Uint32) StoreObject(memory api.Memory, object []byte)
- func (arg Uint32) StoreValue(memory api.Memory, stack []uint64)
- func (arg Uint32) ValueTypes() []api.ValueType
- type Uint64
- func (arg Uint64) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Uint64) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Uint64) LoadObject(memory api.Memory, object []byte) Uint64
- func (arg Uint64) LoadValue(memory api.Memory, stack []uint64) Uint64
- func (arg Uint64) ObjectSize() int
- func (arg Uint64) StoreObject(memory api.Memory, object []byte)
- func (arg Uint64) StoreValue(memory api.Memory, stack []uint64)
- func (arg Uint64) ValueTypes() []api.ValueType
- type Uint8
- func (arg Uint8) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Uint8) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Uint8) LoadObject(memory api.Memory, object []byte) Uint8
- func (arg Uint8) LoadValue(memory api.Memory, stack []uint64) Uint8
- func (arg Uint8) ObjectSize() int
- func (arg Uint8) StoreObject(memory api.Memory, object []byte)
- func (arg Uint8) StoreValue(memory api.Memory, stack []uint64)
- func (arg Uint8) ValueTypes() []api.ValueType
- type Value
Constants ¶
const PageSize = 64 * 1024
PageSize is the size of memory pages in WebAssembly programs (64 KiB).
Variables ¶
var ( // ErrNoRuntime is an error returned when attempting to compile a host // module in a context which has no wazero runtime. ErrNoRuntime = errors.New("compilation context contains no wazero runtime") )
Functions ¶
func Build ¶
func Build[T Module](runtime wazero.Runtime, mod HostModule[T], decorators ...Decorator[T]) wazero.HostModuleBuilder
Build builds the host module p in the wazero runtime r, returning the instance of HostModuleBuilder that was created. This is a low level function which is only exposed for certain advanced use cases where a program might not be able to leverage Compile/Instantiate, most application should not need to use this function.
func Instantiate ¶
func Instantiate[T Module](ctx *InstantiationContext, compiled *CompiledModule[T], opts ...Option[T]) (api.Module, error)
Instantiate creates an module instance for the given compiled wazero host module. The list of options is used to pass configuration to the module instance.
The function returns the wazero module instance that was created from the underlying compiled module. The returned module is bound to the instantiation context. If the module is closed, its state is automatically removed from the parent context, as well as removed from the parent wazero runtime like any other module instance closed by the application.
func NewCallContext ¶
func NewCallContext(ctx context.Context, ins *InstantiationContext) context.Context
NewCallContext returns a Go context inheriting from ctx and containing the state needed for module instantiated from wazero host module to properly bind their methods to their receiver (e.g. the module instance).
Use this function when calling methods of an instantiated WebAssenbly module which may invoke exported functions of a wazero host module, for example:
// The program first creates the instantiation context and uses it to // instantiate compiled host module (not shown here). instiation := wasm.NewInstantiationContext(...) ... // In this example the parent is the background context, but it might be any // other Go context relevant to the application. ctx = wasm.NewCallContext(context.Background(), instantiation) start := module.ExportedFunction("_start") r, err := start.Call(ctx) if err != nil { ... }
func Read ¶
Read returns a byte slice from a module memory. The function calls Read on the given memory and panics if offset/length are beyond the range of memory.
func WithCallContext ¶
func WithCallContext[T Module](ctx context.Context, mod HostModule[T], opts ...Option[T]) (context.Context, func())
WithCallContext returns a Go context inheriting from ctx and containig the necessary state to be used in calls to exported functions of the given wazero host modul. This function is rarely used by applications, it is often more useful in tests to setup the test state without constructing the entire compilation and instantiation contexts (see NewCallContext instead).
Types ¶
type Array ¶
type Array[T primitive] []T
Array is a type representing a sequence of contiguous items in memory. Array values are composed of a pair of pointer and number of items. The item size is determined by the size of the type T.
Arrays only satisfy the Param interface, they cannot be used as return value of functions.
At this time, arrays may only be composed of primitive Go types, but this restriction may be relaxed in a future version. Use List to laod sequences of complex types.
func (Array[T]) FormatObject ¶
func (Array[T]) FormatValue ¶
func (Array[T]) LoadObject ¶
func (Array[T]) ObjectSize ¶
func (Array[T]) ValueTypes ¶
type Bytes ¶
Bytes is a type alias for arrays of bytes, which is a common use case (e.g. I/O functions working on a byte buffer).
func (Bytes) FormatObject ¶
func (Bytes) FormatValue ¶
func (Bytes) ObjectSize ¶
func (Bytes) ValueTypes ¶
type CompilationContext ¶
type CompilationContext struct {
// contains filtered or unexported fields
}
CompilationContext is a type carrying the state needed to perform the compilation of wazero host modules.
func NewCompilationContext ¶
func NewCompilationContext(ctx context.Context, rt wazero.Runtime) *CompilationContext
NewCompilationContext constructs a new wazero host module compilation context. The newly created instance captures the context and wazero runtime passed as arguments.
type CompiledModule ¶ added in v0.2.0
type CompiledModule[T Module] struct { HostModule HostModule[T] wazero.CompiledModule }
CompiledModule represents a compiled version of a wazero host module.
func Compile ¶
func Compile[T Module](ctx *CompilationContext, mod HostModule[T], decorators ...Decorator[T]) (*CompiledModule[T], error)
Compile compiles a wazero host module within the given context.
type Decorator ¶
Decorator is an interface type which applies a transformation to a function.
func DecoratorFunc ¶
DecoratorFunc is a helper used to create decorators from functions using type inference to keep the syntax simple.
type Errno ¶
type Errno int32
Errno is an error type representing error codes that are often returned by WebAssembly module functions.
This type is employed when converting Go errors embedded into optional values to WebAssembly error codes. Go errors are converted to Errno values by unwrapping and inspecting the values to determine their error code. If a Go error has an Errno method, it is called to be converted to an Errno value.
The special value 0 always indicates that there were no errors, similarly to how a Go program would treat a nil error.
type Error ¶
Error is a special optional type which either contains an error or no values. It is useful to represent return values of functions that may error but do not return any other values.
type Float32 ¶
type Float32 float32
func (Float32) FormatObject ¶
func (Float32) FormatValue ¶
func (Float32) ObjectSize ¶
func (Float32) ValueTypes ¶
type Float64 ¶
type Float64 float64
func (Float64) FormatObject ¶
func (Float64) FormatValue ¶
func (Float64) ObjectSize ¶
func (Float64) ValueTypes ¶
type Function ¶
type Function[T any] struct { Name string Params []Value Results []Value Func func(T, context.Context, api.Module, []uint64) }
Function represents a single function exported by a plugin. Programs may configure the fields individually but it is often preferrable to use one of the Func* constructors instead to let the Go compiler ensure type and memory safety when generating the code to bridge between WebAssembly and Go.
func F2 ¶
func F2[ T any, P1 Param[P1], P2 Param[P2], R Result, ](fn func(T, context.Context, P1, P2) R) Function[T]
F2 is the Function constructor for functions accepting two parameters.
func F3 ¶
func F3[ T any, P1 Param[P1], P2 Param[P2], P3 Param[P3], R Result, ](fn func(T, context.Context, P1, P2, P3) R) Function[T]
F3 is the Function constructor for functions accepting three parameters.
func F4 ¶
func F4[ T any, P1 Param[P1], P2 Param[P2], P3 Param[P3], P4 Param[P4], R Result, ](fn func(T, context.Context, P1, P2, P3, P4) R) Function[T]
F4 is the Function constructor for functions accepting four parameters.
func F5 ¶
func F5[ T any, P1 Param[P1], P2 Param[P2], P3 Param[P3], P4 Param[P4], P5 Param[P5], R Result, ](fn func(T, context.Context, P1, P2, P3, P4, P5) R) Function[T]
F5 is the Function constructor for functions accepting five parameters.
func F6 ¶
func F6[ T any, P1 Param[P1], P2 Param[P2], P3 Param[P3], P4 Param[P4], P5 Param[P5], P6 Param[P6], R Result, ](fn func(T, context.Context, P1, P2, P3, P4, P5, P6) R) Function[T]
F6 is the Function constructor for functions accepting six parameters.
type Functions ¶
Functions is a map type representing the collection of functions exported by a plugin. The map keys are the names of that each function gets exported as. The function value is the description of the wazero host function to be added when building a plugin. The type parameter T is used to ensure consistency between the plugin definition and the functions that compose it.
type HostModule ¶ added in v0.2.0
type HostModule[T Module] interface { // Returns the name of the host module (e.g. "wasi_snapshot_preview1"). Name() string // Returns the collection of functions exported by the host module. // The method may return the same value across multiple calls to this // method, the program is expected to treat it as a read-only value. Functions() Functions[T] // Creates a new instance of the host module type, using the list of options // passed as arguments to configure it. This method is intended to be called // automatically when instantiating a module via an instantiation context. Instantiate(...Option[T]) T }
HostModule is an interface representing type-safe wazero host modules. The interface is parametrized on the module type that it instantiates.
HostModule instances are expected to be immutable and therfore safe to use concurrently from multiple goroutines.
type InstantiationContext ¶
type InstantiationContext struct {
// contains filtered or unexported fields
}
InstantiationContext is a type carrying the state of instantiated wazero host modules. This context must be used to create call contexts to invoke exported functions of WebAssembly modules (see NewCallContext).
func NewInstantiationContext ¶
func NewInstantiationContext(ctx context.Context, rt wazero.Runtime) *InstantiationContext
NewInstantiationContext creates a new wazero host module instantiation context.
type Int16 ¶
type Int16 int16
func (Int16) FormatObject ¶
func (Int16) FormatValue ¶
func (Int16) ObjectSize ¶
func (Int16) ValueTypes ¶
type Int32 ¶
type Int32 int32
func (Int32) FormatObject ¶
func (Int32) FormatValue ¶
func (Int32) ObjectSize ¶
func (Int32) ValueTypes ¶
type Int64 ¶
type Int64 int64
func (Int64) FormatObject ¶
func (Int64) FormatValue ¶
func (Int64) ObjectSize ¶
func (Int64) ValueTypes ¶
type Int8 ¶
type Int8 int8
func (Int8) FormatObject ¶
func (Int8) FormatValue ¶
func (Int8) ObjectSize ¶
func (Int8) ValueTypes ¶
type List ¶
type List[T Object[T]] struct { // contains filtered or unexported fields }
List represents a sequence of objects held in module memory.
func (List[T]) FormatValue ¶
func (List[T]) ValueTypes ¶
type Memory ¶
type Memory []byte
Memory is an implementation of the api.Memory interface of wazero backed by a Go byte slice. The memory has a fixed size and cannot grow nor shrink.
This type is mostly useful in tests to construct memory areas where output parameters can be stored.
func NewFixedSizeMemory ¶
NewFixedSizeMemory constructs a Memory instance of size bytes aligned on the WebAssembly page size.
func (Memory) Definition ¶
func (mem Memory) Definition() api.MemoryDefinition
type Module ¶
Module is a type constraint used to validate that all module instances created from wazero host modules abide to the same set of requirements.
type None ¶
type None struct{}
None is a special type of size zero bytes.
func (None) ObjectSize ¶
func (None) ValueTypes ¶
type Object ¶
type Object[T any] interface { // Writes a human-readable representation of the object to w. FormatObject(w io.Writer, memory api.Memory, object []byte) // Loads and returns the object from the given byte slice. If the object // contains pointers it migh read them from the module memory passed as // first argument. LoadObject(memory api.Memory, object []byte) T // Stores the object to the given tye slice. If the object contains pointers // it might write them to the module memory passed as first argument (doing // so without writing to arbitrary location is difficult so this use case is // rather rare). StoreObject(memory api.Memory, object []byte) // Returns the size of the the object in bytes. The byte slices passed to // LoadObject and StoreObjects are guaranteed to be at least of the length // returned by this method. ObjectSize() int }
Object is an interface which represents values that can be loaded or stored in memory.
The interface is mainly used as a constraint for generic type parameters.
type Option ¶
type Option[T any] interface { // Configure is called to apply the configuration option to the value passed // as argument. Configure(T) }
Option is a generic interface used to represent options that apply configuration to a value.
func OptionFunc ¶
OptionFunc is a constructor which creates an option from a function. This function is useful to leverage type inference and not have to repeat the type T in the type parameter.
type Optional ¶
type Optional[T ParamResult[T]] struct { // contains filtered or unexported fields }
Optional represents a function result which may be missing due to the program encountering an error. The type contains either a value of type T or an error.
OK is a special value indicating that a function which returns nothing has not errored either.
func Err ¶
func Err[T ParamResult[T]](err error) Optional[T]
Err constructs an optional from an error. The function panics if the error is nil since a nil error indicates that the optional should contain a value.
func Opt ¶
func Opt[T ParamResult[T]](res T, err error) Optional[T]
Opt constructs an optional from a pair of a result and error.
func (Optional[T]) FormatValue ¶
func (Optional[T]) Result ¶
func (opt Optional[T]) Result() T
Value returns the underlying value of the optional. The method panics if opt contained an error.
func (Optional[T]) StoreValue ¶
func (Optional[T]) ValueTypes ¶
type Param ¶
type Param[T any] interface { Value // Loads and returns the parameter value from the stack and optionally // reading its content from memory. LoadValue(memory api.Memory, stack []uint64) T }
Param is an interface representing parameters of WebAssembly functions which are read form the stack.
The interface is mainly used as a constraint for generic type parameters.
type ParamResult ¶
type Pointer ¶
type Pointer[T Object[T]] struct { // contains filtered or unexported fields }
Pointer is a parameter type used to represent a pointer to an object held in program memory.
func New ¶
New constructs a pointer to an object of type T backed by Go memory.
This function is mostly useful to construct pointers to pass to module methods in tests, its usage in actual production code should be rare.
func Ptr ¶
Ptr constructs a pointer of objects T backed by a memory area at a specified offset.
This function is mostly useful to construct pointers to pass to module methods in tests, its usage in actual production code should be rare.
func (Pointer[T]) FormatValue ¶
func (Pointer[T]) ValueTypes ¶
type Result ¶
type Result interface { Value // Stores the result value onto the stack and optionally writing its // content to memory. StoreValue(memory api.Memory, stack []uint64) }
Result is an interface reprenting results of WebAssembly functions which are written to the stack.
The interface is mainly used as a constraint for generic type parameters.
type SEGFAULT ¶
type SEGFAULT struct{ Offset, Length uint32 }
SEGFAULT is an error type used as value in panics triggered by reading outside of the addressable memory of a program.
type String ¶
type String string
String is similar to Bytes but holds the value as a Go string which is not sharing memory with the WebAssembly program memory anymore.
func (String) FormatValue ¶
func (String) ValueTypes ¶
type Uint16 ¶
type Uint16 uint16
func (Uint16) FormatObject ¶
func (Uint16) FormatValue ¶
func (Uint16) ObjectSize ¶
func (Uint16) ValueTypes ¶
type Uint32 ¶
type Uint32 uint32
func (Uint32) FormatObject ¶
func (Uint32) FormatValue ¶
func (Uint32) ObjectSize ¶
func (Uint32) ValueTypes ¶
type Uint64 ¶
type Uint64 uint64
func (Uint64) FormatObject ¶
func (Uint64) FormatValue ¶
func (Uint64) ObjectSize ¶
func (Uint64) ValueTypes ¶
type Uint8 ¶
type Uint8 uint8
func (Uint8) FormatObject ¶
func (Uint8) FormatValue ¶
func (Uint8) ObjectSize ¶
func (Uint8) ValueTypes ¶
type Value ¶
type Value interface { // Writes a human-readable representation of the field to w, using the // memory and stack of a program to locate the field value. FormatValue(w io.Writer, memory api.Memory, stack []uint64) // Returns the sequence of primitive types that the result value is // composed of. Values of primitive types will have a single type, // but more complex types will have more (e.g. a buffer may hold two // 32 bits integers for the pointer and length). The number of types // indicates the number of words that are consumed from the stack when // loading the parameter. ValueTypes() []api.ValueType }
Value represents a field in a function signature, which may be a parameter or a result.