Skip to content

Commit aa114ef

Browse files
committed
Add explicit argument counts (#672)
* Add explicit arities * Rename
1 parent f28dd7e commit aa114ef

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

BinaryEncoding.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -321,27 +321,30 @@ It is legal to have several entries with the same type.
321321

322322
## Control flow operators ([described here](AstSemantics.md#control-flow-structures))
323323

324-
| Name | Opcode | Immediate | Description |
324+
| Name | Opcode | Immediates | Description |
325325
| ---- | ---- | ---- | ---- |
326326
| `nop` | `0x00` | | no operation |
327327
| `block` | `0x01` | | begin a sequence of expressions, the last of which yields a value |
328328
| `loop` | `0x02` | | begin a block which can also form control flow loops |
329329
| `if` | `0x03` | | begin if expression |
330330
| `else` | `0x04` | | begin else expression of if |
331331
| `select` | `0x05` | | select one of two values based on condition |
332-
| `br` | `0x06` | relative_depth = `varuint32` | break that targets an outer nested block |
333-
| `br_if` | `0x07` | relative_depth = `varuint32` | conditional break that targets an outer nested block |
332+
| `br` | `0x06` | argument_count : `varuint1`, relative_depth : `varuint32` | break that targets an outer nested block |
333+
| `br_if` | `0x07` | argument_count : `varuint1`, relative_depth : `varuint32` | conditional break that targets an outer nested block |
334334
| `br_table` | `0x08` | see below | branch table control flow construct |
335-
| `return` | `0x09` | | return zero or one value from this function |
335+
| `return` | `0x09` | argument_count : `varuint1` | return zero or one value from this function |
336336
| `unreachable` | `0x0a` | | trap immediately |
337337
| `end` | `0x0f` | | end a block, loop, or if |
338338

339339
Note that there is no explicit `if_else` opcode, as the else clause is encoded with the `else` bytecode.
340340

341+
The counts following the break and return operators specify how many preceding operands are taken as transfer arguments; in the MVP, all these values must be either 0 or 1.
342+
341343
The `br_table` operator has an immediate operand which is encoded as follows:
342344

343345
| Field | Type | Description |
344346
| ---- | ---- | ---- |
347+
| arity | `varuint1` | number of arguments |
345348
| target_count | `varuint32` | number of targets in the target_table |
346349
| target_table | `uint32*` | target entries that indicate an outer block or loop to which to break |
347350
| default_target | `uint32` | an outer block or loop to which to break in the default case |
@@ -352,17 +355,20 @@ branches to the block or loop at the given offset within the `target_table`. If
352355
out of range, `br_table` branches to the default target.
353356

354357
## Basic operators ([described here](AstSemantics.md#constants))
355-
| Name | Opcode | Immediate | Description |
358+
359+
| Name | Opcode | Immediates | Description |
356360
| ---- | ---- | ---- | ---- |
357-
| `i32.const` | `0x10` | value = `varint32` | a constant value interpreted as `i32` |
358-
| `i64.const` | `0x11` | value = `varint64` | a constant value interpreted as `i64` |
359-
| `f64.const` | `0x12` | value = `uint64` | a constant value interpreted as `f64` |
360-
| `f32.const` | `0x13` | value = `uint32` | a constant value interpreted as `f32` |
361-
| `get_local` | `0x14` | local_index = `varuint32` | read a local variable or parameter |
362-
| `set_local` | `0x15` | local_index = `varuint32` | write a local variable or parameter |
363-
| `call` | `0x16` | function_index = `varuint32` | call a function by its index |
364-
| `call_indirect` | `0x17` | signature_index = `varuint32` | call a function indirect with an expected signature |
365-
| `call_import` | `0x18` | import_index = `varuint32` | call an imported function by its index |
361+
| `i32.const` | `0x10` | value : `varint32` | a constant value interpreted as `i32` |
362+
| `i64.const` | `0x11` | value : `varint64` | a constant value interpreted as `i64` |
363+
| `f64.const` | `0x12` | value : `uint64` | a constant value interpreted as `f64` |
364+
| `f32.const` | `0x13` | value : `uint32` | a constant value interpreted as `f32` |
365+
| `get_local` | `0x14` | local_index : `varuint32` | read a local variable or parameter |
366+
| `set_local` | `0x15` | local_index : `varuint32` | write a local variable or parameter |
367+
| `call` | `0x16` | argument_count : `varuint1`, function_index : `varuint32` | call a function by its index |
368+
| `call_indirect` | `0x17` | argument_count : `varuint1`, type_index : `varuint32` | call a function indirect with an expected signature |
369+
| `call_import` | `0x18` | argument_count : `varuint1`, import_index : `varuint32` | call an imported function by its index |
370+
371+
The counts following the different call opcodes specify the number of preceding operands taken as arguments.
366372

367373
## Memory-related operators ([described here](AstSemantics.md#linear-memory-accesses))
368374

0 commit comments

Comments
 (0)