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 ParseFiles(deps []*Interface, srcs ...string) (map[string]*Interface, error)
- func ReturnsStream(f *Func) bool
- 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 CoreImport
- 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).
const ( StreamRead = iota StreamReadAsync StreamCancelRead StreamCancelReadAsync StreamDropReadable )
Stream built-in kinds, in StreamBuiltins order.
const ( WaitableSetNew = iota WaitableSetDrop WaitableJoin WaitableSetPoll WaitableSetWait )
Waitable-set built-in kinds, in WaitableBuiltins order.
const ( EventNone = 0 // waitable-set.poll: nothing ready EventStreamRead = 2 // a stream read finished CopyCompleted = 0 // payload low 4 bits CopyDropped = 1 // the writer is gone CopyCancelled = 2 // the read was cancelled Blocked = 0xffff_ffff // an async read did not finish yet )
Canonical ABI values of those built-ins.
const RootModule = "$root"
RootModule is the module of the waitable-set built-ins.
Variables ¶
var ErrTrap = errors.New("canonical ABI trap")
ErrTrap wraps every error that the Canonical ABI defines as a trap.
var WaitableBuiltins = []CoreImport{ WaitableSetNew: {"[waitable-set-new]", "", "i"}, WaitableSetDrop: {"[waitable-set-drop]", "i", ""}, WaitableJoin: {"[waitable-join]", "ii", ""}, WaitableSetPoll: {"[waitable-set-poll]", "ii", "i"}, WaitableSetWait: {"[waitable-set-wait]", "ii", "i"}, }
WaitableBuiltins are the $root module's waitable-set built-ins.
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).
func ParseFiles ¶ added in v0.5.0
ParseFiles reads the files of one package (a file without a package line belongs to the package of the others), resolving uses of its own interfaces and of deps (interfaces of other packages, by short name or by ImportModule). The result is keyed by short interface name.
func ReturnsStream ¶ added in v0.6.0
ReturnsStream reports whether f's result is a stream (whose built-ins StreamBuiltins names).
Types ¶
type AllocReq ¶
type AllocReq struct{ Align, Size uint32 }
AllocReq is one allocation a lowering needs.
type CoreImport ¶ added in v0.6.0
type CoreImport struct{ Name, Params, Result string }
CoreImport is a core import's name and core signature (I32 etc.).
func StreamBuiltins ¶ added in v0.6.0
func StreamBuiltins(fn string) []CoreImport
StreamBuiltins are the built-ins for the stream that function fn (its core import name) returns, imported from fn's module; the index 0 is that stream's position among the function's streams (its only one).
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 PlanElems ¶ added in v0.6.0
PlanElems prepares storing vs, each a t, one after another from p (a stream read's buffer: stream.read lowers its elements there).
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
Owner string // Own/Borrow: the resource's interface (ImportModule)
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).