webassemblyjs
webassemblyjs copied to clipboard
The WAST & WASM parsers should normalise function signatures
The current AST is de-normalized, in that the signature information is included in the function and call_indirect nodes.
With WASM the signatures / types are stored in a section and referenced by index. As a result, the wasm-parser currently de-normalises, by copying type information into the function nodes.
In order to ensure a standard and simple AST form (see #241), the WAST parser should normalise, storing the type information separately, and referencing from the func / call_indirect.
As a result, the AST generated from parsing WAST where the signature is inline:
(func (result i32)
(i32.const 5)
)
Would be normalised to a form that is more closely aligned with the following:
(type (func (result i32)))
(func (type 0)
(i32.const 5)
)
Which is itself more closely aligned with the section-based WASM structure
With the changes for #257 function AST nodes can now either include the signature directly, or indirectly as a type references. Currently the interpreter will throw a runtime exception if it encounters a type reference.