# wasm: Implement structs stored on the stack · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/b2221e564490421265f9e3b2e398a89bbdfb0516)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: b2221e564490421265f9e3b2e398a89bbdfb0516

Requested commit: b2221e564490421265f9e3b2e398a89bbdfb0516

Commit: b2221e564490421265f9e3b2e398a89bbdfb0516

Tree: ddf654e63898ff97c88afa4c3c5201b6b2101f8f

Author: Luuk de Gram

Committer: Luuk de Gram

## Message

```
wasm: Implement structs stored on the stack

By calculating the abi size of the struct, we move the stack
pointer and store each field depending on its size (i.e. a 1-byte field will use i32.store8).
This commit adds all required opcodes to perform those stores and loads.

This also gets rid of `mir_offset` as we now save results of binary operations into
locals and emit its result onto the stack within condbr instead. This makes everything a lot
simpler but also more robust.
In the future, we could look into an algorithm to re-use such locals.

For struct fields we use the new `local_with_offset` tag. This stores the struct's
stack pointer as well as the field's offset from that stack pointer.

`allocLocal` will now always allocate a single local, using a given type.

```

## Parents

- [261f13414b6bafbe075ce5066964b36a3a5b5e16](https://git.cafe/gitcafe/zig/commit/261f13414b6bafbe075ce5066964b36a3a5b5e16?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/b2221e564490421265f9e3b2e398a89bbdfb0516?format=markdown)
