Documentation ¶
Index ¶
- Variables
- func Format(w io.Writer, v any)
- func UnsafeLoadObject[T Object[T]](mem []byte) T
- func UnsafeStoreObject[T Object[T]](mem []byte, obj T)
- type Array
- func (arg Array[T]) Format(w io.Writer)
- 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 Bool
- func (arg Bool) Format(w io.Writer)
- func (arg Bool) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Bool) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Bool) LoadObject(memory api.Memory, object []byte) Bool
- func (arg Bool) LoadValue(memory api.Memory, stack []uint64) Bool
- func (arg Bool) ObjectSize() int
- func (arg Bool) StoreObject(memory api.Memory, object []byte)
- func (arg Bool) StoreValue(memory api.Memory, stack []uint64)
- func (arg Bool) 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 Duration
- func (arg Duration) Format(w io.Writer)
- func (arg Duration) FormatObject(w io.Writer, memory api.Memory, object []byte)
- func (arg Duration) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg Duration) LoadObject(memory api.Memory, object []byte) Duration
- func (arg Duration) LoadValue(memory api.Memory, stack []uint64) Duration
- func (arg Duration) ObjectSize() int
- func (arg Duration) StoreObject(memory api.Memory, object []byte)
- func (arg Duration) StoreValue(memory api.Memory, stack []uint64)
- func (arg Duration) ValueTypes() []api.ValueType
- type Errno
- func (err Errno) Errno() int32
- func (err Errno) Error() string
- func (err Errno) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (err Errno) LoadValue(memory api.Memory, stack []uint64) Errno
- func (err Errno) StoreValue(memory api.Memory, stack []uint64)
- func (err Errno) ValueTypes() []api.ValueType
- type Error
- type Float32
- func (arg Float32) Format(w io.Writer)
- 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) Format(w io.Writer)
- 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 Formatter
- type Int16
- func (arg Int16) Format(w io.Writer)
- 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) Format(w io.Writer)
- 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) Format(w io.Writer)
- 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) Format(w io.Writer)
- 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]) Append(buffer []T) []T
- func (arg List[T]) FormatValue(w io.Writer, memory api.Memory, stack []uint64)
- func (arg List[T]) Index(index int) Pointer[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]) Slice() []T
- func (arg List[T]) UnsafeSlice() []T
- func (arg List[T]) ValueTypes() []api.ValueType
- type None
- func (None) Format(w io.Writer)
- 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 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]) Append(buffer []T, count int) []T
- func (arg Pointer[T]) FormatObject(w io.Writer, memory api.Memory, object []byte)
- 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]) LoadObject(memory api.Memory, object []byte) Pointer[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]) ObjectSize() int
- func (arg Pointer[T]) Offset() uint32
- func (arg Pointer[T]) Slice(count int) []T
- func (arg Pointer[T]) Store(value T)
- func (arg Pointer[T]) StoreObject(memory api.Memory, object []byte)
- func (arg Pointer[T]) UnsafeSlice(count int) []T
- func (arg Pointer[T]) ValueTypes() []api.ValueType
- type Result
- type String
- type Uint16
- func (arg Uint16) Format(w io.Writer)
- 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) Format(w io.Writer)
- 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) Format(w io.Writer)
- 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) Format(w io.Writer)
- 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 ¶
This section is empty.
Variables ¶
var ( // ErrorStrings is a global used in the formatting of Errno values. // // The table is empty by default, but the program may assign a table indexed // by error code to customize the error messages. // // There is no synchronization so it is recommended to assign this global // during program initialization (e.g. in an init function). ErrorStrings []string )
Functions ¶
func Format ¶ added in v0.16.0
Format is a helper function which can be used in the implementation of the FormatValue and FormatObject methods of Value and Object[T].
The code below represents a common usage pattern:
func (v T) FormatObject(w io.Writer, memory api.Memory, object []byte) { types.Format(w, v.LoadObject(memory, object)) }
If T is a struct type, the output is wrapped in "{...}" and the struct fields are iterated and printed as comma-separated "name:value" pairs. The name may be customized by defining a "name" struct field tag such as:
type T struct { Field int32 `name:"field"` }
If any of the values impelement the Formatter or fmt.Stringer interfaces, formatting is delegated to those methods.
The implementation of Format has to use reflection, so it may not be best suited to use in contexts where performance is critical, in which cases the program is better off providing a custom implementation of the method.
func UnsafeLoadObject ¶ added in v0.16.0
UnsafeLoadObject is a helper which may be used to implement the LoadObject method for object types which do not contain any inner pointers.
func (v T) LoadObject(_ api.Memory, object []byte) T { return types.UnsafeLoadObject[T](object) }
func UnsafeStoreObject ¶ added in v0.16.0
UnsafeStoreObject is a helper which may be used to implement the StoreObject method for object types which do not contain any inner pointers.
func (v T) StoreObject(_ api.Memory, object []byte) { types.UnsafeStoreObject(object, v) }
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 Bool ¶ added in v0.4.0
type Bool bool
func (Bool) FormatObject ¶ added in v0.4.0
func (Bool) FormatValue ¶ added in v0.4.0
func (Bool) LoadObject ¶ added in v0.4.0
func (Bool) ObjectSize ¶ added in v0.4.0
func (Bool) StoreObject ¶ added in v0.4.0
func (Bool) StoreValue ¶ added in v0.4.0
func (Bool) ValueTypes ¶ added in v0.4.0
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 Duration ¶ added in v0.10.0
func (Duration) FormatObject ¶ added in v0.10.0
func (Duration) FormatValue ¶ added in v0.10.0
func (Duration) LoadObject ¶ added in v0.10.0
func (Duration) ObjectSize ¶ added in v0.10.0
func (Duration) StoreObject ¶ added in v0.10.0
func (Duration) StoreValue ¶ added in v0.10.0
func (Duration) ValueTypes ¶ added in v0.10.0
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.
func (Errno) FormatValue ¶ added in v0.11.0
func (Errno) StoreValue ¶ added in v0.11.0
func (Errno) ValueTypes ¶ added in v0.11.0
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 Formatter ¶ added in v0.16.0
Formatter is an interface used to customize the behavior of Format.
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 MakeList ¶ added in v0.13.0
MakeList constructs a list from a pointer to an object of type T and a length.
func (List[T]) FormatValue ¶
func (List[T]) UnsafeSlice ¶ added in v0.16.0
func (arg List[T]) UnsafeSlice() []T
func (List[T]) ValueTypes ¶
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 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 ¶
ParamResult is an interface implemented by types which can be used as both a parameter and a result.
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]) FormatObject ¶ added in v0.19.1
func (Pointer[T]) FormatValue ¶
func (Pointer[T]) LoadObject ¶ added in v0.19.1
func (Pointer[T]) ObjectSize ¶ added in v0.19.1
func (Pointer[T]) StoreObject ¶ added in v0.19.1
func (Pointer[T]) UnsafeSlice ¶ added in v0.16.0
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 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.