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
Copy file name to clipboardExpand all lines: design/witx-type-representation.md
+24-54Lines changed: 24 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,49 +14,9 @@ found here](https://github.com/WebAssembly/interface-types/blob/master/proposals
14
14
The endian-ness of these types are **little endian**, as _all_ types in the WebAssembly
15
15
type system are little endian. [See here for more information](https://github.com/WebAssembly/design/issues/786#issuecomment-244548105).
16
16
17
-
# Enum(T)
17
+
# Record
18
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
23
-
Cat).
24
-
25
-
```
26
-
errno: Enum(u32)
27
-
+------+------+------+------+
28
-
| 0x00 | 0x00 | 0x00 | 0x15 |
29
-
+------+------+------+------+
30
-
^ fault
31
-
```
32
-
33
-
(`clockid` despite only representing 4 values is an `Enum(u32)`. This is
34
-
primarily for ABI compatibility, and future-proofing.)
35
-
36
-
# Flags(T)
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.
43
-
44
-
```
45
-
oflags: Flags(u16)
46
-
47
-
+-----------------+-----------------+
48
-
| 0 1 1 0 0 0 0 0 | 0 0 0 0 0 0 0 0 |
49
-
+-----------------+-----------------+
50
-
^ ^ ^ ^
51
-
| | | trunc
52
-
| | excl
53
-
| directory
54
-
creat
55
-
```
56
-
57
-
# Struct
58
-
59
-
A `Struct` is a type that takes up some contiguous amount of memory, with each
19
+
A `Record` is a type that takes up some contiguous amount of memory, with each
60
20
field taking up a specific amount of reserved bytes. Interpreting the bytes as
61
21
one of the types in Witx will yield a usable value.
62
22
@@ -72,26 +32,36 @@ buf_len: size @ offset 4
72
32
^buf ^buf_len
73
33
```
74
34
75
-
The `Size` of a `Struct` refers to how many contiguous bytes it takes up in
35
+
The `Size` of a `Record` refers to how many contiguous bytes it takes up in
76
36
memory.
77
37
78
-
The `Alignment` of a `Struct` refers to <X>.
38
+
The `Alignment` of a `Record` refers to the byte boundary that the record must
39
+
be on in memory. For example, the above `iovec` could only ever get allocated
40
+
to a memory address that is divisible by 4, because the alignment is 4.
79
41
80
-
# Union
42
+
# Variant
81
43
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
44
+
A `Variant` is a type which uses some bits to determine which variant of
45
+
the variant the data will be. The data is simply inserted as is with whatever
0 commit comments