From fb1f010879ea546fa89f25b73662019cfc7f80da Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 9 Aug 2016 12:15:38 -0700 Subject: [PATCH 1/3] Replace branch arities with block and if signatures. Moving arities to blocks has the nice property of giving implementations useful information up front, however some anticipated uses of this information would really want to know the types up front too. This patch proposes replacing block arities with function signature indices, which would provide full type information about a block up front. --- BinaryEncoding.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/BinaryEncoding.md b/BinaryEncoding.md index 4f94aa8a..d2fc11cd 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -56,6 +56,14 @@ A single-byte unsigned integer indicating a [value type](AstSemantics.md#types). * `3` indicating type `f32` * `4` indicating type `f64` +### `inline_signature_type` +A single-byte unsigned integer indicating a signature. These types are encoded as: +* `0` indicating a signature with 0 arguments and 0 results. +* `1` indicating a signature with 0 arguments and 1 result of type `i32`. +* `2` indicating a signature with 0 arguments and 1 result of type `i64`. +* `3` indicating a signature with 0 arguments and 1 result of type `f32`. +* `4` indicating a signature with 0 arguments and 1 result of type `f64`. + ### `external_kind` A single-byte unsigned integer indicating the kind of definition being imported or defined: * `0` indicating a `Function` [import](Modules.md#imports) or [definition](Modules.md#function-and-code-sections) @@ -436,20 +444,21 @@ It is legal to have several entries with the same type. | Name | Opcode | Immediates | Description | | ---- | ---- | ---- | ---- | | `unreachable` | `0x00` | | trap immediately | -| `block` | `0x01` | | begin a sequence of expressions, the last of which yields a value | -| `loop` | `0x02` | | begin a block which can also form control flow loops | -| `if` | `0x03` | | begin if expression | +| `block` | `0x01` | sig : `inline_signature_type` | begin a sequence of expressions, yielding 0 or 1 values | +| `loop` | `0x02` | sig : `inline_signature_type` | begin a block which can also form control flow loops | +| `if` | `0x03` | sig : `inline_signature_type` | begin if expression | | `else` | `0x04` | | begin else expression of if | | `select` | `0x05` | | select one of two values based on condition | -| `br` | `0x06` | arity : `varuint1`, relative_depth : `varuint32` | break that targets an outer nested block | -| `br_if` | `0x07` | arity : `varuint1`, relative_depth : `varuint32` | conditional break that targets an outer nested block | +| `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_table` | `0x08` | see below | branch table control flow construct | | `return` | `0x09` | return zero or one value from this function | | `drop` | `0x0b` | | ignore value | | `nop` | `0x0a` | | no operation | | `end` | `0x0f` | | end a block, loop, or if | -The counts following the break operators specify how many operands are taken as transfer arguments; in the MVP, all these values must be either 0 or 1. +The _sig_ fields of `block` and `if` operators specify function signatures +which describe their use of the operand stack. The `br_table` operator has an immediate operand which is encoded as follows: From dcd2a3aa7b99daa2f9b442a173c405ec20541deb Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 9 Sep 2016 08:55:42 -0700 Subject: [PATCH 2/3] Remove the arity operand from br_table too. --- BinaryEncoding.md | 1 - 1 file changed, 1 deletion(-) diff --git a/BinaryEncoding.md b/BinaryEncoding.md index d2fc11cd..56c03fa9 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -464,7 +464,6 @@ 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 entries in the target_table | | target_table | `varuint32*` | target entries that indicate an outer block or loop to which to break | | default_target | `varuint32` | an outer block or loop to which to break in the default case | From 2bee76faf2c51fc64c32782c3a84e1a6b781ec64 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 12 Sep 2016 08:25:15 -0700 Subject: [PATCH 3/3] Remove mentions of "arguments". --- BinaryEncoding.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BinaryEncoding.md b/BinaryEncoding.md index 56c03fa9..737c374c 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -58,11 +58,11 @@ A single-byte unsigned integer indicating a [value type](AstSemantics.md#types). ### `inline_signature_type` A single-byte unsigned integer indicating a signature. These types are encoded as: -* `0` indicating a signature with 0 arguments and 0 results. -* `1` indicating a signature with 0 arguments and 1 result of type `i32`. -* `2` indicating a signature with 0 arguments and 1 result of type `i64`. -* `3` indicating a signature with 0 arguments and 1 result of type `f32`. -* `4` indicating a signature with 0 arguments and 1 result of type `f64`. +* `0` indicating a signature with 0 results. +* `1` indicating a signature with 1 result of type `i32`. +* `2` indicating a signature with 1 result of type `i64`. +* `3` indicating a signature with 1 result of type `f32`. +* `4` indicating a signature with 1 result of type `f64`. ### `external_kind` A single-byte unsigned integer indicating the kind of definition being imported or defined: