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

Commit 1276e58

Browse files
authored
Update Overview.md for element segments (#41)
* 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 1276e58

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

proposals/bulk-memory-operations/Overview.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,54 @@ 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 | Active? | index | offset |
206+
| - | - | - | - |
207+
| 0 | Active | Always 0 | Present |
208+
| 1 | Passive | - | - |
209+
| 2 | Active | Present | Present |
210+
211+
### Element segments
212+
213+
The new binary format for element segments is similar to the new format for data segments, but
214+
also includes an element type when the segment is passive. A passive segment also has a sequence
215+
of `expr`s instead of function indices.
216+
217+
| Field | Type | Present? | Description |
218+
| - | - | - | - |
219+
| flags | `varuint32` | always | Flags for passive and presence of fields below, only values of 0, 1, and 2 are valid |
220+
| index | `varuint32`? | flags = 2 | Table index; 0 if the field is not present |
221+
| element_type | `elem_type`? | flags = 1 | element type of this segment; `anyfunc` if not present |
222+
| offset | `init_expr`? | flags != 1 | an `i32` initializer expression for offset |
223+
| count | `varuint32` | always | number of elements |
224+
| elems | `varuint32*` | flags != 1 | sequence of function indices |
225+
| elems | `elem_expr*` | flags = 1 | sequence of element expressions |
226+
227+
Another way of looking at it:
228+
229+
| Flags | Active? | index | element_type | offset |
230+
| - | - | - | - | - |
231+
| 0 | Active | Always 0 | Always `anyfunc` | Present |
232+
| 1 | Passive | - | Present | - |
233+
| 2 | Active | Present | Always `anyfunc` | Present |
234+
235+
An `elem_expr` is like an `init_expr`, but can only contain expressions of the following sequences:
236+
237+
| Binary | Text | Description |
238+
| - | - | - |
239+
| `0xd0 0x0b` | `ref.null end` | Returns a null reference |
240+
| `0xd2 varuint32 0x0b` | `ref.func $funcidx end` | Returns a reference to function `$funcidx` |
241+
242+
TODO: coordinate with other proposals to determine the binary encoding for `ref.null` and `ref.func`.
205243

206244
### `memory.init` instruction
207245

0 commit comments

Comments
 (0)