Documentation
¶
Index ¶
- Variables
- func EvalConstantExpression(imports []*Global, expr []byte) (interface{}, error)
- func Fmax(z1, z2 float64) float64
- func Fmin(z1, z2 float64) float64
- func I32DivS(i1, i2 int32) int32
- func I32TruncS(z float64) int32
- func I32TruncSatS(z float64) int32
- func I32TruncSatU(z float64) uint32
- func I32TruncU(z float64) uint32
- func I64DivS(i1, i2 int64) int64
- func I64TruncS(z float64) int64
- func I64TruncSatS(z float64) int64
- func I64TruncSatU(z float64) uint64
- func I64TruncU(z float64) uint64
- func NewKindMismatchError(exportingModuleName, exportName string, importKind, exportKind wasm.External) error
- func TranslateRecover(x interface{})
- type AllocatedModule
- type ExportNotFoundError
- type Frame
- type Function
- type Global
- func (g *Global) Get() uint64
- func (g *Global) GetF32() float32
- func (g *Global) GetF64() float64
- func (g *Global) GetI32() int32
- func (g *Global) GetI64() int64
- func (g *Global) GetValue() interface{}
- func (g *Global) Set(v uint64)
- func (g *Global) SetF32(v float32)
- func (g *Global) SetF64(v float64)
- func (g *Global) SetI32(v int32)
- func (g *Global) SetI64(v int64)
- func (g *Global) SetValue(v interface{})
- func (g *Global) Type() wasm.GlobalVar
- type HostFunction
- type ImportResolver
- type InvalidGlobalIndexError
- type InvalidImportError
- type InvalidTableIndexError
- type InvalidValueTypeInitExprError
- type KindMismatchError
- type MapResolver
- type Memory
- func (m *Memory) Byte(base, offset uint32) byte
- func (m *Memory) ByteAt(offset uint32) byte
- func (m *Memory) Bytes() []byte
- func (m *Memory) Float32(base, offset uint32) float32
- func (m *Memory) Float32At(offset uint32) float32
- func (m *Memory) Float64(base, offset uint32) float64
- func (m *Memory) Float64At(offset uint32) float64
- func (m *Memory) Grow(pages uint32) (uint32, error)
- func (m *Memory) Limits() (min, max uint32)
- func (m *Memory) PutByte(v byte, base, offset uint32)
- func (m *Memory) PutByteAt(v byte, offset uint32)
- func (m *Memory) PutFloat32(v float32, base, offset uint32)
- func (m *Memory) PutFloat32At(v float32, offset uint32)
- func (m *Memory) PutFloat64(v float64, base, offset uint32)
- func (m *Memory) PutFloat64At(v float64, offset uint32)
- func (m *Memory) PutUint16(v uint16, base, offset uint32)
- func (m *Memory) PutUint16At(v uint16, offset uint32)
- func (m *Memory) PutUint32(v uint32, base, offset uint32)
- func (m *Memory) PutUint32At(v uint32, offset uint32)
- func (m *Memory) PutUint64(v uint64, base, offset uint32)
- func (m *Memory) PutUint64At(v uint64, offset uint32)
- func (m *Memory) PutUint8(v byte, base, offset uint32)
- func (m *Memory) PutUint8At(v byte, offset uint32)
- func (m *Memory) Size() uint32
- func (m *Memory) Start() uintptr
- func (m *Memory) Uint16(base, offset uint32) uint16
- func (m *Memory) Uint16At(offset uint32) uint16
- func (m *Memory) Uint32(base, offset uint32) uint32
- func (m *Memory) Uint32At(offset uint32) uint32
- func (m *Memory) Uint64(base, offset uint32) uint64
- func (m *Memory) Uint64At(offset uint32) uint64
- func (m *Memory) Uint8(base, offset uint32) byte
- func (m *Memory) Uint8At(offset uint32) byte
- type Module
- type ModuleDefinition
- type ModuleEventHandler
- type ModuleResolver
- type Store
- type Table
- type Thread
- type Trap
Constants ¶
This section is empty.
Variables ¶
var ErrDataSegmentDoesNotFit = errors.New("data segment does not fit")
ErrDataSegmentDoesNotFit should be returned by Instantiate if a data segment attempts to write outside of its target memory's bounds.
var ErrElementSegmentDoesNotFit = errors.New("element segment does not fit")
ErrElementSegmentDoesNotFit should be returned by Instantiate if a element segment attempts to write outside of its target table's bounds.
var ErrGlobalType = errors.New("global type mismatch")
var ErrInvalidTypeIndex = fmt.Errorf("invalid type index")
ErrInvalidTypeIndex is returned by InstantiateModule if the module's imports contain an invalid type index.
var ErrLimitExceeded = fmt.Errorf("memory limit exceeded")
var ErrMemoryType = errors.New("memory type mismatch")
var ErrModuleNotFound = fmt.Errorf("module not found")
var ErrTableType = errors.New("table type mismatch")
var TrapCallStackExhausted = Trap("call stack exhausted")
TrapCallStackExhausted indicates call stack exhaustion.
var TrapGeneric = Trap("")
TrapGeneric is produced for failures with no associated information.
var TrapIndirectCallTypeMismatch = Trap("indirect call type mismatch")
TrapIndirectCallTypeMismatch indicates a mismatch between the exepected and actual signature of a function.
var TrapIntegerDivideByZero = Trap("integer divide by zero")
TrapIntegerDivideByZero indicates an attempt to divide by zero.
var TrapIntegerOverflow = Trap("integer overflow")
TrapIntegerOverflow indicates an integer overflow.
var TrapInvalidConversionToInteger = Trap("invalid conversion to integer")
TrapInvalidConversionToInteger indicates an invalid converstion from a floating-point value to an integer.
var TrapOutOfBoundsMemoryAccess = Trap("out of bounds memory access")
TrapOutOfBoundsMemoryAccess indicates an out-of-bounds memory access.
var TrapUndefinedElement = Trap("undefined element")
TrapInvalidUndefinedElement indicates an attempt to access a table with an index that is out of bounds.
var TrapUninitializedElement = Trap("uninitialized element")
TrapUninitializedElement indicates an attempt to use an uninitialized table element.
var TrapUnreachable = Trap("unreachable")
TrapUnreachable indicates execution of unreachable code.
Functions ¶
func EvalConstantExpression ¶
EvalConstantExpression executes the given (encoded) constant expression in the context of the given imports.
func I32TruncSatS ¶
func I32TruncSatU ¶
func I64TruncSatS ¶
func I64TruncSatU ¶
func NewKindMismatchError ¶
func NewKindMismatchError(exportingModuleName, exportName string, importKind, exportKind wasm.External) error
NewKindMismatchError creates a new error that reports a mismatch between an import and export kind. This function should be used to create the errors returned by Module.Get{Function,Table,Memory,Global} if the requested name refers to an export of a different kind.
func TranslateRecover ¶
func TranslateRecover(x interface{})
TranslateRecover is a utility function that translates the result of a call to recover() into nothing, a trap, or a panic. This function should be called like so:
defer func() { exec.TranslateRecover(recover()) }()
Types ¶
type AllocatedModule ¶
type AllocatedModule interface { Module // Instantiate initializes the allocated module with imports supplied by the given resolver. Instantiate(imports ImportResolver) (Module, error) }
An AllocatedModule is an allocated but uninitialized WASM module.
type ExportNotFoundError ¶
An ExportNotFoundError is returned by InstantiateModule if an export could not be found.
func (*ExportNotFoundError) Error ¶
func (e *ExportNotFoundError) Error() string
type Frame ¶
type Frame struct { Caller *Frame ModuleName string FunctionIndex uint32 FunctionSignature wasm.FunctionSig Locals []uint64 }
A Frame records a single WASM activation record.
type Function ¶
type Function interface { // GetSignature returns this function's signature. GetSignature() wasm.FunctionSig // Call calls the function with the given arguments. If the number and type of the arguments do not match the // number and type of the parameters in this function's signature, this method may panic. Call(thread *Thread, args ...interface{}) []interface{} // UncheckedCall calls the function with the given arguments. This method's behavior is undefined If the number of // arguments/returns does not match the number of parameters/results in this function's signature. UncheckedCall(thread *Thread, args, returns []uint64) }
Function represents a function exported by a WASM module.
var UninitializedFunction Function = uninitializedFunction(0)
UninitializedFunction represents an uninitialized table entry. Calling this function will trap.
type Global ¶
type Global struct {
// contains filtered or unexported fields
}
func NewGlobalF32 ¶
func NewGlobalF64 ¶
func NewGlobalI32 ¶
func NewGlobalI64 ¶
type HostFunction ¶
type HostFunction struct {
// contains filtered or unexported fields
}
func NewHostFunction ¶
func NewHostFunction(module Module, index uint32, method reflect.Value) *HostFunction
func (*HostFunction) Call ¶
func (f *HostFunction) Call(thread *Thread, args ...interface{}) []interface{}
func (*HostFunction) Func ¶
func (f *HostFunction) Func() interface{}
func (*HostFunction) GetSignature ¶
func (f *HostFunction) GetSignature() wasm.FunctionSig
func (*HostFunction) UncheckedCall ¶
func (f *HostFunction) UncheckedCall(thread *Thread, args, returns []uint64)
type ImportResolver ¶
type ImportResolver interface { ResolveFunction(moduleName, functionName string, type_ wasm.FunctionSig) (Function, error) ResolveMemory(moduleName, memoryName string, type_ wasm.Memory) (*Memory, error) ResolveTable(moduleName, tableName string, type_ wasm.Table) (*Table, error) ResolveGlobal(moduleName, globalName string, type_ wasm.GlobalVar) (*Global, error) }
An ImportResolver resolves import entries to function, memory, table, and global instances.
type InvalidGlobalIndexError ¶
type InvalidGlobalIndexError uint32
func (InvalidGlobalIndexError) Error ¶
func (e InvalidGlobalIndexError) Error() string
type InvalidImportError ¶
InvalidImportError is returned when the export of a resolved module doesn't match the signature of its import declaration.
func (*InvalidImportError) Error ¶
func (e *InvalidImportError) Error() string
type InvalidTableIndexError ¶
type InvalidTableIndexError uint32
func (InvalidTableIndexError) Error ¶
func (e InvalidTableIndexError) Error() string
type InvalidValueTypeInitExprError ¶
func (InvalidValueTypeInitExprError) Error ¶
func (e InvalidValueTypeInitExprError) Error() string
type KindMismatchError ¶
type KindMismatchError struct { ModuleName string FieldName string Import wasm.External Export wasm.External }
func (*KindMismatchError) Error ¶
func (e *KindMismatchError) Error() string
type MapResolver ¶
type MapResolver map[string]ModuleDefinition
A MapResolver is a ModuleResolver that maps module names to definitions using the contents of a map.
func (MapResolver) ResolveModule ¶
func (r MapResolver) ResolveModule(name string) (ModuleDefinition, error)
ResolveModule resolves the given module name to a module definition.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is a WASM linear memory.
func (*Memory) Grow ¶
Grow grows the memory by the given number of pages. It returns the old size of the memory in pages and an error if growing the memory by the requested amount would exceed the memory's maximum size.
func (*Memory) PutFloat32 ¶
PutFloat32 writes the given float32 to the given effective address.
func (*Memory) PutFloat32At ¶
PutFloat32At writes the given float32 to the given offset.
func (*Memory) PutFloat64 ¶
PutFloat64 writes the given float64 to the given effective address.
func (*Memory) PutFloat64At ¶
PutFloat64At writes the given float64 to the given offset.
func (*Memory) PutUint16At ¶
PutUint16At writes the given uint16 to the given offset.
func (*Memory) PutUint32At ¶
PutUint32At writes the given uint32 to the given offset.
func (*Memory) PutUint64At ¶
PutUint64 writes the given uint64 to the given offset.
func (*Memory) PutUint8At ¶
PutUint8At writes the given byte to the given offset.
type Module ¶
type Module interface { // Name returns the name of this module. Name() string // GetFunction returns the exported function with the given name. If the function does not exist or the name // refers to an export of a different kind, this function returns an error. GetFunction(name string) (Function, error) // GetTable returns the exported table with the given name. If the table does not exist or the name // refers to an export of a different kind, this function returns an error. GetTable(name string) (*Table, error) // GetMemory returns the exported memory with the given name. If the memory does not exist or the name // refers to an export of a different kind, this function returns an error. GetMemory(name string) (*Memory, error) // GetGlobal returns the exported global with the given name. If the global does not exist or the name // refers to an export of a different kind, this function returns an error. GetGlobal(name string) (*Global, error) }
A Module is an instantiated WASM module.
func NewHostModule ¶
type ModuleDefinition ¶
type ModuleDefinition interface { // Allocate creates an allocated, uninitialized module with the given name from this module definition. Allocate(name string) (AllocatedModule, error) }
ModuleDefinition represents a WASM module definition.
func NewHostModuleDefinition ¶
func NewHostModuleDefinition(instantiate interface{}) ModuleDefinition
instantiate must be a func() T. instantiate will be called to instantiate a host module.
type ModuleEventHandler ¶
type ModuleEventHandler interface { ModuleAllocated(m AllocatedModule) error ModuleInstantiated(m Module) error }
A ModuleEventHandler responds to module allocations and instantiations.
type ModuleResolver ¶
type ModuleResolver interface { // ResolveModule resolves the given module name to a module definition. ResolveModule(name string) (ModuleDefinition, error) }
A ModuleResolver resolves module names to module definitions.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
A Store is responsible for instantiating modules.
func NewStore ¶
func NewStore(resolver ModuleResolver, handlers ...ModuleEventHandler) *Store
NewStore creates a new store that will use the given resolver to resolve modules.
func (*Store) InstantiateModule ¶
InstantiateModule instantiates the given module. The name is resolved to a module definition using the store's ModuleResolver.
func (*Store) InstantiateModuleDefinition ¶
func (s *Store) InstantiateModuleDefinition(name string, def ModuleDefinition) (Module, error)
InstantiateModuleDefinition instantiates the given module definition.
func (*Store) RegisterModule ¶
RegisterModule registers an instantiated module with the store, replacing any existing module with the same name.
type Thread ¶
type Thread struct {
// contains filtered or unexported fields
}
A Thread carries information about a single WASM thread.
func NewDebugThread ¶
NewDebugThread creates a new, debuggable thread with the given tracer and max depth, if any.
func (*Thread) Enter ¶
func (t *Thread) Enter()
Enter pushes a new frame onto the thread's stack. Each call to Enter must be balanced with a call to Leave.
func (*Thread) EnterFrame ¶
EnterFrame pushes a new frame onto the thread's stack. Each call to EnterFrame must be balanced with a call to LeaveFrame.
func (*Thread) LeaveFrame ¶
func (t *Thread) LeaveFrame()
LeaveFrame pops the top of the thread's stack.