Documentation
¶
Overview ¶
Package wit reads WIT (the WebAssembly Interface Types language, component-model design/mvp/WIT.md) for the subset the wasi-gfx packages use, and implements the Canonical ABI (design/mvp/CanonicalABI.md) over a core module's linear memory: alignment, sizes, flattening, loads, stores, flat lifting and lowering. A core-module host serves WIT-described imports with it, without a component-model runtime.
Index ¶
- Constants
- Variables
- func Align(t *Type) uint32
- func Flatten(t *Type) []byte
- func LiftFlat(t *Type, vals []uint64, m Memory) (any, error)
- func LiftParams(f *Func, args []uint64, m Memory) ([]any, error)
- func Load(m Memory, p uint32, t *Type) (any, error)
- func LowerFlat(m Memory, a Allocator, t *Type, v any) ([]uint64, error)
- func Parse(src string) (map[string]*Interface, error)
- func Size(t *Type) uint32
- func Store(m Memory, a Allocator, p uint32, t *Type, v any) error
- type AllocReq
- type Allocator
- type Case
- type CoreSig
- type Field
- type Func
- type FuncKind
- type Interface
- type Kind
- type Lowering
- type Memory
- type Param
- type Resource
- type ResultValue
- type Some
- type Type
- type VariantValue
Constants ¶
const ( I32 = 'i' I64 = 'I' F32c = 'f' F64c = 'F' )
Core value types, as the engine's host modules spell them.
const ( MaxFlatParams = 16 MaxFlatResults = 1 // MaxListBytes bounds one list or string a guest passes or receives. MaxListBytes = 1 << 28 )
Limits of the ABI (MAX_FLAT_PARAMS, MAX_FLAT_RESULTS).
Variables ¶
var ErrTrap = errors.New("canonical ABI trap")
ErrTrap wraps every error that the Canonical ABI defines as a trap.
Functions ¶
func LiftFlat ¶
LiftFlat lifts one value of type t from its core values (a function's flat result, on the caller's side).
func LiftParams ¶
LiftParams lifts f's parameters from its core arguments (loading the parameter tuple from memory when they did not fit flat).
Types ¶
type AllocReq ¶
type AllocReq struct{ Align, Size uint32 }
AllocReq is one allocation a lowering needs.
type CoreSig ¶
CoreSig is a function's core signature when lowered synchronously (flatten_functype, 'lower'): params beyond MaxFlatParams go through one pointer; results beyond MaxFlatResults through a return-area pointer appended to the params.
type Func ¶
type Func struct {
Name string // as in WIT: "create-buffer", or "" for a constructor
Kind FuncKind
Async bool
Params []Param
Result *Type // nil: no result
}
Func is a WIT function; for a method, Params[0] is "self".
func (*Func) ImportName ¶
ImportName is a function's core import name.
type Interface ¶
type Interface struct {
Package string // "wasi:webgpu@0.3.0-rc.2"
Name string
Types map[string]*Type
Resources map[string]*Resource
Funcs []*Func
// contains filtered or unexported fields
}
Interface is a WIT interface: its named types, resources and functions.
func (*Interface) ImportModule ¶
ImportModule is the core import module name, "ns:pkg/iface@ver".
func (*Interface) ResourceNames ¶
ResourceNames lists the resources in declaration order.
type Lowering ¶
type Lowering struct {
Reqs []AllocReq
// contains filtered or unexported fields
}
Lowering is a result being lowered: its allocations, then Apply.
func PlanResult ¶
PlanResult prepares lowering f's result v. args are the call's core arguments (the last is the return area when Sig(f).RetPtr).
type ResultValue ¶
ResultValue is a result: Value is the ok or the error payload.
type Type ¶
type Type struct {
Kind Kind
Name string // type name for named types, resource name for Own/Borrow
Elem *Type // List, Option, Future, Stream; Result's ok
Err *Type // Result's error
Fields []Field // Record, Tuple (labels "0", "1", ...)
Cases []Case // Variant
Labels []string
}
Type is a WIT value type.
func ParamTuple ¶
ParamTuple is the tuple of f's parameter types (what goes to memory when the parameters do not fit flat).
type VariantValue ¶
VariantValue is a variant case and its payload (nil without one).