## 4 Tools for WebAssembly Development
### WebAssembly Standardized Features for Existing Web Browsers and Tools
The _resulttype_ is extended from [_valtype?_] to [_valtype*_], allowing for multiple values. Block types in block, loop, and if instructions are generalized from _resultype_ to _functype_. Validation rules are adjusted accordingly, removing _arity_ restrictions and replacing \"?\" with \"*\" in type occurrences. The execution of multiple results involves replacing \"?\" with \"*\" and handling the entry of blocks with operands by popping the values from the stack and pushing them back after the label. The binary format requires an extension to support function types as block types, allowing references to function types. The text format undergoes minimal changes, primarily in the syntax for block types, which is generalized to accommodate multiple values. The scheme addresses the typing of administrative instructions and provides a formulation of formal reduction rules. Possible alternatives and extensions are under discussion, including more flexible block and function types using references to the type section or unifying the encoding of block types with function types. An open question is whether locals are sufficient for destructuring or reshuffling multiple values, or if additional instructions such as pick or let should be introduced to enhance these capabilities. In summary, the Multi-Value Extension expands the capabilities of Wasm by enabling functions, instructions, and blocks to consume and produce multiple operands and results. This extension enhances expressiveness, facilitates efficient compilation, and opens up new possibilities for code patterns and optimizations. * **Mutable Globals*
* Import/Export Mutable Globals aims to address the inconvenience of providing mutable thread-local values in Wasm that can be dynamically linked. The proposal focuses on the ability to import and export mutable globals, specifically using the C++ stack pointer (SP) as a motivating example. While the examples revolve around the SP, the rationale can be extended to other thread-local variables or the TLS pointer itself. The motivation behind this concept stems from the limitation of not being able to import or export mutable globals in the MVP of Wasm. To illustrate the need for mutable globals, consider the scenario of dynamically linking two modules, m1 and m2, both utilizing the C++ stack pointer. In the MVP, this cannot be achieved directly. In a single-agent program, a workaround involves storing the stack pointer in linear memory. However, this solution fails when linear memory is shared, as each agent requires a different memory location for its stack pointer. The scheme presents several solutions to address the challenge of importing and exporting mutable globals. * Solution 1 Use Per-Module Immutable Global: one approach is to utilize a per-module immutable global to store the location of the SP in linear memory. This can be extended to other thread-local variables as well. However, this solution has drawbacks, such as the need to read the global every time the SP is accessed and the SP in linear memory being vulnerable to to interference from other agents. * Solution 2 Use Internal Mutable Global with Shadow in Linear Memory: a mutable global can be employed to optimize SP access. In this approach, the SP is stored in a mutable global, and when crossing module boundaries it is spilled to linear memory in the caller and loaded in the callee. Although this solution could be further optimized, such as spilling SP only when necessary, it incurs additional overhead for every function call and requires spilling and loading of other thread-local values in the same manner. Moreover, the SP remains susceptible to interference from other agents. * Solution 3 Modify Function Signature to Pass SP as Parameter: instead of spilling the SP to linear memory, it can be passed as a parameter in function signatures. However, because it is not known whether an imported function will use the SP, all exported functions must be modified accordingly.