Files
wasmtime/tests/structs.witx
Jakub Konka c8ea27553d Allow returning structs if copy (#19)
* Allow returning structs if copy

This commit does three things:
1. enables marshalling of structs as return args from interface funcs
   but so far *only* for the case when the struct itself is copy
2. puts bits that use `std::convert::TryInto` in a local scope to avoid
   multiple reimports
3. for added clarity, we now print for which `tref` type the marshalling
   of results is unimplemented

The first case (1.) is required to make `fd_fdstat_get` WASI interface
func work which returns `Fdstat` struct (which is copy). The second
case (2.) caused me some grief somewhere along the lines when I was
playing with snapshot1. Putting the code that requires it inside a local
scope fixed all the issues

* Add proptests for returing struct if copyable

* Use write_ptr_to_guest to marshal value to guest

* Successfully return non-copy struct
2020-02-26 18:32:03 +01:00

41 lines
1.1 KiB
Plaintext

(use "errno.witx")
(typename $pair_ints
(struct
(field $first s32)
(field $second s32)))
(typename $pair_int_ptrs
(struct
(field $first (@witx const_pointer s32))
(field $second (@witx const_pointer s32))))
(typename $pair_int_and_ptr
(struct
(field $first (@witx const_pointer s32))
(field $second s32)))
(module $structs
(@interface func (export "sum_of_pair")
(param $an_pair $pair_ints)
(result $error $errno)
(result $doubled s64))
(@interface func (export "sum_of_pair_of_ptrs")
(param $an_pair $pair_int_ptrs)
(result $error $errno)
(result $doubled s64))
(@interface func (export "sum_of_int_and_ptr")
(param $an_pair $pair_int_and_ptr)
(result $error $errno)
(result $double s64))
(@interface func (export "return_pair_ints")
(result $error $errno)
(result $an_pair $pair_ints))
(@interface func (export "return_pair_of_ptrs")
(param $first (@witx const_pointer s32))
(param $second (@witx const_pointer s32))
(result $error $errno)
(result $an_pair $pair_int_ptrs))
)