.. index:: ! value pair: abstract syntax; value
WebAssembly programs operate on primitive numeric values. Moreover, in the definition of programs, immutable sequences of values occur to represent more complex data, such as text strings or other vectors.
.. index:: ! byte pair: abstract syntax; byte
The simplest form of value are raw uninterpreted bytes. In the abstract syntax they are represented as hexadecimal literals.
\begin{array}{llll}
\production{byte} & \byte &::=&
\hex{00} ~|~ \dots ~|~ \hex{FF} \\
\end{array}
- The meta variable b ranges over bytes.
- Bytes are sometimes interpreted as natural numbers n < 256.
.. index:: ! integer, ! unsigned integer, ! signed integer, ! uninterpreted integer, bit width, two's complement pair: abstract syntax; integer pair: abstract syntax; unsigned integer pair: abstract syntax; signed integer pair: abstract syntax; uninterpreted integer single: integer; unsigned single: integer; signed single: integer; uninterpreted
Different classes of integers with different value ranges are distinguished by their bit width N and by whether they are unsigned or signed.
\begin{array}{llll}
\production{unsigned integer} & \uN &::=&
0 ~|~ 1 ~|~ \dots ~|~ 2^N{-}1 \\
\production{signed integer} & \sN &::=&
-2^{N-1} ~|~ \dots ~|~ {-}1 ~|~ 0 ~|~ 1 ~|~ \dots ~|~ 2^{N-1}{-}1 \\
\production{uninterpreted integer} & \iN &::=&
\uN \\
\end{array}
The latter class defines uninterpreted integers, whose signedness interpretation can vary depending on context. In the abstract syntax, they are represented as unsigned values. However, some operations :ref:`convert <aux-signed>` them to signed based on a two's complement interpretation.
Note
The main integer types occurring in this specification are |u32|, |u64|, |s32|, |s64|, |i8|, |i16|, |i32|, |i64|. However, other sizes occur as auxiliary constructions, e.g., in the definition of :ref:`floating-point <syntax-float>` numbers.
- The meta variables m, n, i range over integers.
- Numbers may be denoted by simple arithmetics, as in the grammar above. In order to distinguish arithmetics like 2^N from sequences like (1)^N, the latter is distinguished with parentheses.
.. index:: ! floating-point, ! NaN, payload, significand, exponent, magnitude, canonical NaN, arithmetic NaN, bit width, IEEE 754 pair: abstract syntax; floating-point number single: NaN; payload single: NaN; canonical single: NaN; arithmetic
Floating-point data represents 32 or 64 bit values that correspond to the respective binary formats of the |IEEE754|_ standard (Section 3.3).
Every value has a sign and a magnitude. Magnitudes can either be expressed as normal numbers of the form m_0.m_1m_2\dots m_M \cdot2^e, where e is the exponent and m is the significand whose most significant bit m_0 is 1, or as a subnormal number where the exponent is fixed to the smallest possible value and m_0 is 0; among the subnormals are positive and negative zero values. Since the significands are binary values, normals are represented in the form (1 + m\cdot 2^{-M}) \cdot 2^e, where M is the bit width of m; similarly for subnormals.
Possible magnitudes also include the special values \infty (infinity) and |NAN| (NaN, not a number). NaN values have a payload that describes the mantissa bits in the underlying :ref:`binary representation <aux-fbits>`. No distinction is made between signalling and quiet NaNs.
\begin{array}{llcll}
\production{floating-point value} & \fN &::=&
{+} \fNmag ~|~ {-} \fNmag \\
\production{floating-point magnitude} & \fNmag &::=&
(1 + \uM\cdot 2^{-M}) \cdot 2^e & (\iff -2^{E-1}+2 \leq e \leq 2^{E-1}-1) \\ &&|&
(0 + \uM\cdot 2^{-M}) \cdot 2^e & (\iff e = -2^{E-1}+2) \\ &&|&
\infty \\ &&|&
\NAN(n) & (\iff 1 \leq n < 2^M) \\
\end{array}
where M = \significand(N) and E = \exponent(N) with
\begin{array}{lclllllcl}
\significand(32) &=& 23 &&&&
\exponent(32) &=& 8 \\
\significand(64) &=& 52 &&&&
\exponent(64) &=& 11 \\
\end{array}
A canonical NaN is a floating-point value \pm\NAN(\canon_N) where \canon_N is a payload whose most significant bit is 1 while all others are 0:
\canon_N = 2^{\significand(N)-1}
An arithmetic NaN is a floating-point value \pm\NAN(n) with n \geq \canon_N, such that the most significant bit is 1 while all others are arbitrary.
Note
In the abstract syntax, subnormals are distinguished by the leading 0 of the significand. The exponent of subnormals has the same value as the smallest possible exponent of a normal number. Only in the :ref:`binary representation <binary-float>` the exponent of a subnormal is encoded differently than the exponent of any normal number.
- The meta variable z ranges over floating-point values where clear from context.
.. index:: ! numeric vectors, integer, floating-point, lane, SIMD pair: abstract syntax; vector
Numeric vectors are 128-bit values that are processed by vector instructions (also known as SIMD instructions, single instruction multiple data). They are represented in the abstract syntax using |i128|. The interpretation of lane types (:ref:`integer <syntax-int>` or :ref:`floating-point <syntax-float>` numbers) and lane sizes are determined by the specific instruction operating on them.
.. index:: ! name, byte, Unicode, UTF-8, character, binary format pair: abstract syntax; name
Names are sequences of characters, which are scalar values as defined by |Unicode|_ (Section 2.4).
\begin{array}{llclll}
\production{name} & \name &::=&
\char^\ast \qquad\qquad (\iff |\utf8(\char^\ast)| < 2^{32}) \\
\production{character} & \char &::=&
\unicode{00} ~|~ \dots ~|~ \unicode{D7FF} ~|~
\unicode{E000} ~|~ \dots ~|~ \unicode{10FFFF} \\
\end{array}
Due to the limitations of the :ref:`binary format <binary-name>`, the length of a name is bounded by the length of its :ref:`UTF-8 <binary-utf8>` encoding.
- Characters (Unicode scalar values) are sometimes used interchangeably with natural numbers n < 1114112.