Introduction to WebAssembly Text
Introduction to WebAssembly Text
Previous | Next | |
---|---|---|
Using a Language Runtime as a WebAssembly Host Environment | Up | Local Variables |
4: WAT Datatypes
At the moment, there are only four WebAssembly numeric datatypes:
32-bit | 64-bit | |
---|---|---|
Integer | i32 |
i64 |
Floating point | f32 |
f64 |
That’s it — just numbers…
No string datatype; no character datatype.
In fact, there isn’t even a Boolean type! 1
Other data types exist such as the Vector type v128
, reference types and function types, but these are beyond the scope of this introduction and will not be discussed here.
Interpreting Integers
One very important point here concerns how you interpret integers.
A floating point number always carries a sign value, but when examining an integer, you are free to choose whether the value is interpreted as an unsigned sequence of bits, or as a two’s complement integer.
This means that when applied to integers, certain comparison instructions such as gt
or lt
must additionally state whether or not the most significant bit should be treated as the sign bit.
-
Don’t be concerned at the lack of a specific Boolean datatype because this is, in fact, just syntactic sugar.
In WAT, the outcome of a condition is stored simply as ani32
where zero meansfalse
, and any non-zero value meanstrue
. It’s that simple… ↩