Static Arrays (data sections), Memory resizing
This release adds new syntax sugar for data sections, memory size/resize operations and bug fixes to the CLI tool.
New - Static Arrays/Data sections
WebAssembly Spec allows for the declaration of static regions of memory which can be pre-defined in the wasm source.
https://github.com/WebAssembly/spec/blob/master/test/core/data.wast
(module
(memory $m 1)
(data (i32.const 0))
(data (i32.const 1) "a" "" "bcd")
(data (offset (i32.const 0)))
(data (offset (i32.const 0)) "" "a" "bc" "")
(data 0 (i32.const 0))
(data 0x0 (i32.const 1) "a" "" "bcd")
(data 0x000 (offset (i32.const 0)))
(data 0 (offset (i32.const 0)) "" "a" "bc" "")
(data $m (i32.const 0))
(data $m (i32.const 1) "a" "" "bcd")
(data $m (offset (i32.const 0)))
(data $m (offset (i32.const 0)) "" "a" "bc" "")
)
This exact pattern was impossible to implement in Walt previous. Now the developer may define these sections with an array literal syntax at global scope inside a walt module.
const array: i32[] = ['<', 'a', 'b', 1, 2, 3];
Any combination of Walt Primitives is allowed in the array literal as long as they map to the type of the array, however expressions and function calls are not.
New - Memory instructions
WebAssembly spec supports memory resizing from within the binary with a set of memory resizing instructions. This is now supported by Walt syntax by the following methods on an Object of type Memory
:
memory.size()
- maps tocurrent_memory
opcodememory.grow()
- maps togrow_memory
opcode, requires a parametermemory.dataSize()
- syntax sugar for getting size of the combined data section regions. Reads zeroth word of memory.
Bug fixes
walt-cli
has a number of bug fixes to make it operate as designedwalt-compiler
fixed a bug with escape sequences not working as expected inside character literals