webassemblyjs
webassemblyjs copied to clipboard
Support NaN and Infinity text constants
The text format supports the following literals for floating point numbers
nan: https://github.com/WebAssembly/spec/blob/master/test/core/float_literals.wast#L5-L7nan:0x...: https://github.com/WebAssembly/spec/blob/master/test/core/float_literals.wast#L8-L13inf: https://github.com/WebAssembly/spec/blob/master/test/core/float_literals.wast#L14-L16
Spec is here https://webassembly.github.io/spec/core/text/values.html#text-float
We should also figure out how to represent those?
(you are the float expert here), for example:
(f32.const nan:0x200000)
could be represented as:
FloatLiteral = {
type: 'FloatLiteral',
value: 0x200000, // so 2097152 in js
hasNaN: true, // i'm probably missing different types of NaN
}
Currently it's a NumberLiteral which can be problematic.
Yes, thats what I started doing in the nan-payloads branch. Theyre still number literals and I have a couple of things to fix in JSON (NaN, Infinity and hex literals). I will try to submit the PR today.
https://github.com/xtuc/js-webassembly-interpreter/blob/nan-payloads/test/compiler/parsing/fixtures/watf/nan/payload/expected.json
Also what you propose is enough to hold all NaNs. They have a 23-bit or 52-bit mantissa that defines the payload. We can make this payload positive or negative to store the sign with it as well. Then we have all possible NaN values and can distinguish them and return the correct ones wherever required.