diff --git a/BinaryEncoding.md b/BinaryEncoding.md index 2b41bdc1..f3436a2f 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -321,7 +321,7 @@ It is legal to have several entries with the same type. ## Control flow operators ([described here](AstSemantics.md#control-flow-structures)) -| Name | Opcode | Immediate | Description | +| Name | Opcode | Immediates | Description | | ---- | ---- | ---- | ---- | | `nop` | `0x00` | | no operation | | `block` | `0x01` | | begin a sequence of expressions, the last of which yields a value | @@ -329,19 +329,22 @@ It is legal to have several entries with the same type. | `if` | `0x03` | | begin if expression | | `else` | `0x04` | | begin else expression of if | | `select` | `0x05` | | select one of two values based on condition | -| `br` | `0x06` | relative_depth = `varuint32` | break that targets an outer nested block | -| `br_if` | `0x07` | relative_depth = `varuint32` | conditional break that targets an outer nested block | +| `br` | `0x06` | argument_count : `varuint1`, relative_depth : `varuint32` | break that targets an outer nested block | +| `br_if` | `0x07` | argument_count : `varuint1`, relative_depth : `varuint32` | conditional break that targets an outer nested block | | `br_table` | `0x08` | see below | branch table control flow construct | -| `return` | `0x09` | | return zero or one value from this function | +| `return` | `0x09` | argument_count : `varuint1` | return zero or one value from this function | | `unreachable` | `0x0a` | | trap immediately | | `end` | `0x0f` | | end a block, loop, or if | Note that there is no explicit `if_else` opcode, as the else clause is encoded with the `else` bytecode. +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. + The `br_table` operator has an immediate operand which is encoded as follows: | Field | Type | Description | | ---- | ---- | ---- | +| arity | `varuint1` | number of arguments | | target_count | `varuint32` | number of targets in the target_table | | target_table | `uint32*` | target entries that indicate an outer block or loop to which to break | | 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 out of range, `br_table` branches to the default target. ## Basic operators ([described here](AstSemantics.md#constants)) -| Name | Opcode | Immediate | Description | + +| Name | Opcode | Immediates | Description | | ---- | ---- | ---- | ---- | -| `i32.const` | `0x10` | value = `varint32` | a constant value interpreted as `i32` | -| `i64.const` | `0x11` | value = `varint64` | a constant value interpreted as `i64` | -| `f64.const` | `0x12` | value = `uint64` | a constant value interpreted as `f64` | -| `f32.const` | `0x13` | value = `uint32` | a constant value interpreted as `f32` | -| `get_local` | `0x14` | local_index = `varuint32` | read a local variable or parameter | -| `set_local` | `0x15` | local_index = `varuint32` | write a local variable or parameter | -| `call` | `0x16` | function_index = `varuint32` | call a function by its index | -| `call_indirect` | `0x17` | signature_index = `varuint32` | call a function indirect with an expected signature | -| `call_import` | `0x18` | import_index = `varuint32` | call an imported function by its index | +| `i32.const` | `0x10` | value : `varint32` | a constant value interpreted as `i32` | +| `i64.const` | `0x11` | value : `varint64` | a constant value interpreted as `i64` | +| `f64.const` | `0x12` | value : `uint64` | a constant value interpreted as `f64` | +| `f32.const` | `0x13` | value : `uint32` | a constant value interpreted as `f32` | +| `get_local` | `0x14` | local_index : `varuint32` | read a local variable or parameter | +| `set_local` | `0x15` | local_index : `varuint32` | write a local variable or parameter | +| `call` | `0x16` | argument_count : `varuint1`, function_index : `varuint32` | call a function by its index | +| `call_indirect` | `0x17` | argument_count : `varuint1`, type_index : `varuint32` | call a function indirect with an expected signature | +| `call_import` | `0x18` | argument_count : `varuint1`, import_index : `varuint32` | call an imported function by its index | + +The counts following the different call opcodes specify the number of preceding operands taken as arguments. ## Memory-related operators ([described here](AstSemantics.md#linear-memory-accesses))