Skip to content

Static Arrays (data sections), Memory resizing

Compare
Choose a tag to compare
@ballercat ballercat released this 06 Oct 17:01
· 45 commits to master since this release

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 to current_memory opcode
  • memory.grow() - maps to grow_memory opcode, requires a parameter
  • memory.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 designed
  • walt-compiler fixed a bug with escape sequences not working as expected inside character literals