You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Witx, each type corresponds to a lower-level type. For example, the `size` type resolves to a `u32`, the `errno` type resolves to an `Enum(u16)`, and more. Detailed below is each type, and what they resolve to in memory.
3
2
4
-
# u8/u16/u32/u64/s64
5
-
These are C-style `uint8_t`s, `uint16_t`s, `uint32_t`s, `uint64_t`s, and `int64_t`s. In the .NET world, they may be more recognizable as an `byte` (in C# this is an unsigned `byte` if you're coming from Java), `ushort`, `uint`, `ulong`, and `long`. These are typically little-endian, although it may not be necessary to know that.
3
+
In Witx, each type corresponds to a lower-level type. For example, the `size`
4
+
type resolves to a `u32`, the `errno` type resolves to an `Enum(u16)`, and
5
+
more. Detailed below is each type, and what they correspond to in the
6
+
WebAssembly type system.
7
+
8
+
## u8/u16/u32/u64/s64
9
+
10
+
These are C-style `uint8_t`s, `uint16_t`s, `uint32_t`s, `uint64_t`s, and
11
+
`int64_t`s. More information about the signedness-aware integer types [can be
12
+
found here](https://github.com/WebAssembly/interface-types/blob/master/proposals/interface-types/Explainer.md#integers).
13
+
14
+
The endian-ness of these types are **little endian**, as _all_ types in the WebAssembly
15
+
type system are little endian. [See here for more information](https://github.com/WebAssembly/design/issues/786#issuecomment-244548105).
6
16
7
17
# Enum(T)
8
-
An `Enum(T)` is, unlike a Rust Enum(T), simply is a `T`. However, the value of T can only be one of the specific variants of the enum. This type lends itself to describing when something can only be one of the enumerations in the group (for example, in a group of Dogs and Cats, you may have an enum representing either a Dog or a Cat).
18
+
19
+
An `Enum(T)` is simply is a `T`. However, the value of T can only be one of the
20
+
specific variants of the enum. This type lends itself to describing when
21
+
something can only be one of the enumerations in the group (for example, in a
22
+
group of Dogs and Cats, you may have an enum representing either a Dog or a
(`clockid` despite only representing 4 values is an `Enum(u32)`. This is for ABI compatibility.)
33
+
(`clockid` despite only representing 4 values is an `Enum(u32)`. This is
34
+
primarily for ABI compatibility, and future-proofing.)
19
35
20
36
# Flags(T)
21
-
A `Flags(T)` datatype takes up exactly a `T` in memory, similar to `Enum(T)`. However, each variant of a `Flags(T)` will take up exactly one bit in the data. This allows the usage of bitwise AND, bitwise OR, and bitwise NOT operators to combine, check, or exclude specific values in the flag very easily. This type lends itself to describing capabilities.
37
+
38
+
A `Flags(T)` datatype takes up exactly a `T` in memory, similar to `Enum(T)`.
39
+
However, each variant of a `Flags(T)` will take up exactly one bit in the data.
40
+
This allows the usage of bitwise AND, bitwise OR, and bitwise NOT operators to
41
+
combine, check, or exclude specific values in the flag very easily. This type
42
+
lends itself to describing capabilities.
22
43
23
44
```
24
45
oflags: Flags(u16)
@@ -34,53 +55,67 @@ oflags: Flags(u16)
34
55
```
35
56
36
57
# Struct
37
-
A `Struct` is a type that takes up some contiguous amount of blocks in memory, with each field taking up a specific amount of reserved bytes. Interpreting the bytes as one of the types in Witx will yield a usable value.
58
+
59
+
A `Struct` is a type that takes up some contiguous amount of memory, with each
60
+
field taking up a specific amount of reserved bytes. Interpreting the bytes as
61
+
one of the types in Witx will yield a usable value.
The `Size` of a `Struct` refers to how many contiguous bytes it takes up in memory.
75
+
The `Size` of a `Struct` refers to how many contiguous bytes it takes up in
76
+
memory.
52
77
53
78
The `Alignment` of a `Struct` refers to <X>.
54
79
55
80
# Union
56
-
A `Union` is a type which uses `tag_size` bytes to determine which variant of the union the data will be. The data is simply inserted as is with whatever type it may be.
81
+
82
+
A `Union` is a type which uses `tag_size` bytes to determine which variant of
83
+
the union the data will be. The data is simply inserted as is with whatever
A `Pointer<T>` and `Array<T>` are both just `Pointer<T>`s. A `Pointer<T>`'s size is guaranteed to be 8 bytes, but if on a 32 bit architecture it will only be 4 bytes. The data stored in one of these types is exactly enough to point to some data in RAM. When the pointer is dereferenced, the data stored at that location will be a contiguous amount of `T`s. // how to get length? is there one for ArrayT?
105
+
106
+
A `Pointer<T>` and `Array<T>` are both just `Pointer<T>`s. A `Pointer<T>`'s
107
+
size is guaranteed to be 8 bytes, but if on a 32 bit architecture it will only
108
+
use 4 of the 8 bytes. The pointers themselves are 32 bit, as wasm32 is the only
109
+
ABI currently implemented. In the future when the specification for wasm64 is
110
+
done, that will change. The data stored in one of these types is exactly enough
111
+
to point to some data in RAM. When the pointer is dereferenced, the data stored
112
+
at that location will be an unknown contiguous amount of `T`s.
0 commit comments