-
Notifications
You must be signed in to change notification settings - Fork 694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How webassembly handle struct? #1099
Comments
#937 would have provided an easy solution for this but is currently closed and I'm not sure if anyone on the WebAssembly team is still thinking about it. For compositions of up to 8 bytes, you can pack them in a 64-bit integer. For larger structures, you'll need to transfer them through linear memory or a set of mutable globals. |
Multiple return values are definitely still on the radar, and I intend to
write up a proposal very soon. That said, they don't give you structs
directly, you'll still have to split them up into individual values for
everything else but function calls.
|
@rossberg-chromium Thank you very much. I think if it doesn't limit the size and order of those returned values then we could workaround with fake struct by the compiled language. That should be enough |
In the meantime, structs could be implemented using pointers, right? |
Just allocate your struct in linear memory and work with pointers. |
@nidin Thank you. Is that the way of C struct compiled to wasm normally did? |
@rossberg any update on structure support? |
@krisnye, there are no plans for "struct" support for wasm programs that use linear memory; the compiler is supposed to lower structs and struct operations to primitive operations. There are some plans for struct types in the context of the GC support proposal, not using linear memory, see eg https://github.com/WebAssembly/gc. There's highly experimental support for at least a subset of that in Firefox Nightly, see https://github.com/lars-t-hansen/moz-gc-experiments. |
I try to read webassembly document and only see it mention type support only i32,i64,f32,f64
But I can't find any place mention a composite type such as struct
It it not possible natively in webassembly? How C compiler workaround for the struct larger than 64 bit? How can I pack 2 floats and 2 ints together in the stack?
The text was updated successfully, but these errors were encountered: