Skip to content
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

Closed
Thaina opened this issue Jun 26, 2017 · 8 comments
Closed

How webassembly handle struct? #1099

Thaina opened this issue Jun 26, 2017 · 8 comments

Comments

@Thaina
Copy link

Thaina commented Jun 26, 2017

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?

@RyanLamansky
Copy link

#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.

@rossberg
Copy link
Member

rossberg commented Jun 26, 2017 via email

@Thaina
Copy link
Author

Thaina commented Jun 26, 2017

@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

@Thaina Thaina closed this as completed Jun 26, 2017
@kevinbarabash
Copy link

In the meantime, structs could be implemented using pointers, right?

@nidin
Copy link
Contributor

nidin commented Jun 26, 2017

Just allocate your struct in linear memory and work with pointers.

@Thaina
Copy link
Author

Thaina commented Jun 27, 2017

@nidin Thank you. Is that the way of C struct compiled to wasm normally did?

@krisnye
Copy link

krisnye commented Mar 4, 2019

@rossberg any update on structure support?

@lars-t-hansen
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants