# wasm: Implement \`@errorName\` · gitcafe/zig

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

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

Visibility: public

Requested revision: 49051c065120781b6ff78172c447b6307bd01e39

Requested commit: 49051c065120781b6ff78172c447b6307bd01e39

Commit: 49051c065120781b6ff78172c447b6307bd01e39

Tree: 37efe02f2da2419f37fec7ce152313229cab6950

Author: Luuk de Gram

Committer: Luuk de Gram

## Message

```
wasm: Implement `@errorName`

This implements the `error_name` instruction, which is emit for runtime `@errorName` callsites.

The implementation works by creating 2 symbols and corresponding atoms.
The initial symbol contains a table which each element consisting of a slice where the ptr field
points towards the error name, and the len field contains the error name length without the sentinel.

The secondary symbol contains a list of all error names from the global error set.

During the error_name instruction, we first get a pointer to the first symbol.
Then based on the operand we perform pointer arithmetic, to get the correct index into this table.
e.g. error index 2 = ptr + (2 * ptr size). The result of this will be stored in a local
and then returned as instruction result.

During `flush()` we populate the error names table by looping over the global error set
and creating a relocation for each error name. This relocation is appended to the table symbol.
Then finally, this name is written to the names list itself.

Finally, both symbols' atom are allocated within the rest of the binary.
When no error name is referenced, the `error_name_symbol` is never set, and therefore
no error name table will be emit into the final binary.

```

## Parents

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

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