Hey,
I'm trying to get comfortable with wasm components by writing them by hand in wat, so far I've gotten a few experiments to work, but I struggle with things like getting a function with a record type to work.
For example:
(component
(type $vec2 (record (field "x" f64) (field "y" f64)))
(type $add_t (func (param "a" 0) (param "b" 0) (result "res" 0)))
(core module $module
(func $add (export "add") (param $a (ref $vec2)) (param $b (ref $vec2)) (result (ref $vec2))
(...)
)
(memory (export "mem") 1)
)
(core instance $instance (instantiate 0))
(func $add (type $add_t)
(canon lift
(core func $instance "add")
(memory $instance "mem")
string-encoding=utf8
)
)
)
I can't figure out how to use the types from the component.
Another question I have is that I've noticed that components created in rust and wasm-tools include package names and interfaces. This is something I'd also like to figure out
Jens
Types in the component type index space cannot be used as core module types in the core module type index space. Furthermore core modules don't have the ability to alias types from outside within a component itself, right now the component model is a pure wrapper around teh core wasm spec so there are no modifications to core wasm to enable such aliasing at this time.
What you probably want here is to review the CanonicalABI.md to understand how the component model type $vec2
is lowered into wasm. For example your wasm signature here will be (func (param i32 i32 i32 i32 i32))
and the canonical abi will explain what each of those fields are.
You can also try playing around with wasm-tools component embed --dummy
which will generate a dummy *.wat
file for a particular WIT world
Thanks! wasm-tools component embed --dummy
was very helpful :grinning_face_with_smiling_eyes:
Jens Gåsemyr Magnus has marked this topic as resolved.
Last updated: Dec 23 2024 at 13:07 UTC