Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeExternref(input uint64) uintptr
- func DecodeF32(input uint64) float32
- func DecodeF64(input uint64) float64
- func EncodeExternref(input uintptr) uint64
- func EncodeF32(input float32) uint64
- func EncodeF64(input float64) uint64
- func EncodeI32(input int32) uint64
- func EncodeI64(input int64) uint64
- func ExternTypeName(et ExternType) string
- func ValueTypeName(t ValueType) string
- type Backend
- type Config
- type Context
- type ExternType
- type Factory
- type Function
- type FunctionDefinition
- type FunctionInstance
- type Global
- type HostFunctionProvider
- type HostModule
- type Instance
- type Loader
- type Logger
- type Memory
- type MemorySizer
- type Module
- type ModuleInstance
- type OutputType
- type Plugin
- type PluginInstance
- type Resolver
- type Runtime
- type Service
- type Source
- type SourceModule
- type ValueType
Constants ¶
const ( // See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#memory-instances%E2%91%A0 MemoryPageSize = uint32(65536) // See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#grow-mem MemoryLimitPages = uint32(65536) )
const ( // ExternTypeFuncName is the name of the WebAssembly 1.0 (20191205) Text Format field for ExternTypeFunc. ExternTypeFuncName = "func" // ExternTypeTableName is the name of the WebAssembly 1.0 (20191205) Text Format field for ExternTypeTable. ExternTypeTableName = "table" // ExternTypeMemoryName is the name of the WebAssembly 1.0 (20191205) Text Format field for ExternTypeMemory. ExternTypeMemoryName = "memory" // ExternTypeGlobalName is the name of the WebAssembly 1.0 (20191205) Text Format field for ExternTypeGlobal. ExternTypeGlobalName = "global" )
The below are exported to consolidate parsing behavior for external types.
Variables ¶
var ( GetTimeout = 60 * time.Second //TODO: Lookup should handle timeout (tns fetch may need to take context) LookupTimeout = 10 * time.Second )
ContextType lets the satellite plugin server detect a leading context.Context parameter when reflecting over a plugin's exported functions.
Functions ¶
func DecodeExternref ¶
DecodeExternref decodes the input as a ValueTypeExternref.
func EncodeExternref ¶
EncodeExternref encodes the input as a ValueTypeExternref.
func ExternTypeName ¶
func ExternTypeName(et ExternType) string
ExternTypeName returns the name of the WebAssembly 1.0 (20191205) Text Format field of the given type.
func ValueTypeName ¶
ValueTypeName returns the type name of the given ValueType as a string. These type names match the names used in the WebAssembly text format.
Types ¶
type Config ¶
type Config struct {
MemoryLimitPages uint32 // should default to MemoryLimitPages
Output OutputType
}
Config sets configuration of the VM service
type Context ¶
type Context interface {
// Context returns the go context of the function instance
Context() context.Context
// Project returns the Taubyte project id
Project() string
// Application returns the application, if none returns an empty string
Application() string
// Resource returns the id of the resource being used.
Resource() string
// Branches returns the branch name used by this resource execution pipeline.
Branches() []string
// Commit returns the commit id used by this resource execution pipeline.
Commit() string
// Clone clones the VM.Context with a new go context
Clone(context.Context) Context
}
type ExternType ¶
type ExternType = byte
ExternType classifies imports and exports with their respective types.
See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#external-types%E2%91%A0
const ( ExternTypeFunc ExternType = 0x00 ExternTypeTable ExternType = 0x01 ExternTypeMemory ExternType = 0x02 ExternTypeGlobal ExternType = 0x03 )
type FunctionDefinition ¶
type FunctionDefinition interface {
// Name is the module-defined name of the function, which is not necessarily
// the same as its export name.
Name() string
// ParamTypes are the possibly empty sequence of value types accepted by a
// function with this signature.
ParamTypes() []ValueType
// ResultTypes are the results of the function.
ResultTypes() []ValueType
}
FunctionDefinition is a WebAssembly function exported in a module.
type FunctionInstance ¶
FunctionInstance is a callable wasm export. It stays a tau interface (rather than aliasing api.Function) so it can be mocked in substrate tests without a real engine. Params/results are raw wasm uint64 slots — the caller marshals.
type HostFunctionProvider ¶ added in v1.2.0
type HostFunctionProvider interface {
RegisterHostFunctions(wazy.HostModuleBuilder)
}
HostFunctionProvider is implemented by factories that register their host functions onto a wazy host-module builder (typed, via wazy.HostFuncN / HostProcN). The plugin loader calls this for each factory.
type HostModule ¶
type HostModule interface {
// Builder returns the underlying wazy host-module builder.
Builder() wazy.HostModuleBuilder
// Compile instantiates the registered functions and returns the module.
Compile() (ModuleInstance, error)
}
HostModule is a wazy host module under construction. Register host functions on its Builder (with wazy.HostFuncN / HostProcN, or WithGoModuleFunction for raw signatures), then Compile.
type Instance ¶
type Instance interface {
// Context returns the context of the function Instance
Context() Context
// Close will close the Instance
Close() error
// Runtime returns a new Function Instance Runtime. Optional register
// callbacks add extra host functions to the built-in `env` module (used by
// tests to expose fixtures' host imports).
Runtime(register ...func(wazy.HostModuleBuilder)) (Runtime, error)
// Filesystem returns the filesystem used by the given Instance.
Filesystem() afero.Fs
// Stdout returns the Reader interface of stdout
Stdout() io.Reader
// Stderr returns the Reader interface of stderr
Stderr() io.Reader
}
type Loader ¶
type Loader interface {
// Load resolves the module, then loads the module using a Backend
Load(ctx Context, module string) (io.ReadCloser, error)
}
type Logger ¶ added in v1.1.9
type Logger interface {
// New creates a new call logger instance using the provided vm.Context
// Writes to memory buffer, commits to file on close
New(ctx Context) (io.WriteCloser, error)
// Open returns a ReadCloser for reading logs at specific timestamp, fails if file doesn't exist
Open(ctx Context, timestamp time.Time) (io.ReadCloser, error)
// List returns all timestamps for a specific context within the specified range
// If start is zero, uses first timestamp. If end is zero, uses last timestamp.
List(ctx Context, start, end time.Time) ([]time.Time, error)
// First returns the first (earliest) timestamp for a specific context
First(ctx Context) (time.Time, error)
// Last returns the last (most recent) timestamp for a specific context
Last(ctx Context) (time.Time, error)
// Close closes the logger and all open files
Close() error
}
Logger provides logging capabilities for VM function calls and executions
type MemorySizer ¶
MemorySizer applies during compilation after a module has been decoded from wasm, but before it is instantiated.
type Module ¶
Module is a wazy-instantiated module, exposed directly. wazy is the only engine, so there is no abstraction to wrap it (the old callBridge is gone).
type ModuleInstance ¶
type ModuleInstance interface {
// Function returns a FunctionInstance of given name from the ModuleInstance
Function(name string) (FunctionInstance, error)
Memory() Memory
}
type Plugin ¶
type Plugin interface {
// New creates a new PluginInstance
New(Instance) (PluginInstance, error)
// Name returns the name of the Plugin
Name() string
Close() error
}
TODO: New takes options for factories
type PluginInstance ¶
type PluginInstance interface {
// Load will load all Factories to the HostModule, and return the ModuleInstance
Load(HostModule) (ModuleInstance, error)
// Close will close the PluginInstance
Close() error
}
type Runtime ¶
type Runtime interface {
Modules() []string
Module(name string) (ModuleInstance, error)
Expose(name string) (HostModule, error)
Attach(plugin Plugin) (PluginInstance, ModuleInstance, error)
Stdout() io.Reader
Stderr() io.Reader
// TODO: Add Runtime Stat
Close() error
}
type Source ¶
type Source interface {
// Module Loads the given module name, and returns the SourceModule
Module(ctx Context, name string) (SourceModule, error)
}
type SourceModule ¶
type SourceModule []byte
type ValueType ¶
type ValueType = byte
ValueType describes a numeric type used in Web Assembly 1.0 (20191205).
const ( // ValueTypeI32 is a 32-bit integer. ValueTypeI32 ValueType = 0x7f // ValueTypeI64 is a 64-bit integer. ValueTypeI64 ValueType = 0x7e // ValueTypeF32 is a 32-bit floating point number. ValueTypeF32 ValueType = 0x7d // ValueTypeF64 is a 64-bit floating point number. ValueTypeF64 ValueType = 0x7c // ValueTypeExternref is a externref type. ValueTypeExternref ValueType = 0x6f )