Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit 1901e56

Browse files
authored
Update Overview.md for element segments
Passive element segments now include an element type, and have a sequence of expressions instead of function indices.
1 parent 61018e8 commit 1901e56

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

proposals/bulk-memory-operations/Overview.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,42 @@ An active segment is equivalent to a passive segment, but with an implicit
192192

193193
The new encoding of a data segment is now:
194194

195-
| Field | Type | Description |
196-
|------|-------|-------------|
197-
| flags | `varuint32` | Flags for passive and presence of fields below, only values of 0, 1, and 2 are valid |
198-
| index | `varuint32`? | Memory index this segment is for, only present if `flags` is 2, otherwise the index is implicitly 0 |
199-
| offset | `init_expr`? | an `i32` initializer expression for offset, not present if `flags & 0x1` is set |
200-
| size | `varuint32` | size of `data` (in bytes) |
201-
| data | `bytes` | sequence of `size` bytes |
202-
203-
An element segment (for tables) is encoded similarly by repurposing its table
204-
index (which is required to be zero) as a flags field.
195+
| Field | Type | Present? | Description |
196+
| - | - | - | - |
197+
| flags | `varuint32` | always | Flags for passive and presence of fields below, only values of 0, 1, and 2 are valid |
198+
| index | `varuint32`? | flags = 2 | Memory index; 0 if the field is not present |
199+
| offset | `init_expr`? | flags != 1 | an `i32` initializer expression for offset |
200+
| size | `varuint32` | always | size of `data` (in bytes) |
201+
| data | `bytes` | always | sequence of `size` bytes |
202+
203+
Another way of looking at it:
204+
205+
| Flags | Index Field | Offset |
206+
207+
### Element segments
208+
209+
The new binary format for element segments is similar to the new format for data segments, but
210+
also includes an element type when the segment is passive. A passive segment also has a sequence
211+
of `expr`s instead of function indices.
212+
213+
| Field | Type | Present? | Description |
214+
| - | - | - | - |
215+
| flags | `varuint32` | always | Flags for passive and presence of fields below, only values of 0, 1, and 2 are valid |
216+
| index | `varuint32`? | flags = 2 | Table index; 0 if the field is not present |
217+
| element_type | `elem_type`? | flags = 1 | element type of this segment; `anyfunc` if not present |
218+
| offset | `init_expr`? | flags != 1 | an `i32` initializer expression for offset |
219+
| count | `varuint32` | always | number of elements |
220+
| elems | `varuint32*` | flags != 1 | sequence of function indices |
221+
| elems | `elem_expr*` | flags = 1 | sequence of element expressions |
222+
223+
An `elem_expr` is like an `init_expr`, but can only contain expressions of the following sequences:
224+
225+
| Binary | Text | Description |
226+
| - | - | - |
227+
| `0xd0 0x0b` | `ref.null end` | Returns a null reference |
228+
| `0xd2 varuint32 0x0b` | `ref.func $funcidx end` | Returns a reference to function `$funcidx` |
229+
230+
TODO: coordinate with other proposals to determine the binary encoding for `ref.null` and `ref.func`.
205231

206232
### `memory.init` instruction
207233

0 commit comments

Comments
 (0)