Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions BinaryEncoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be simpler to explain in terms of a single result time, since the signatures won't be relevant until some future post-MVP version.

* `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:
* `0` indicating a `Function` [import](Modules.md#imports) or [definition](Modules.md#function-and-code-sections)
Expand Down Expand Up @@ -436,26 +444,26 @@ 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 |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There does not appear to be any compelling reason to restrict blocks to returning only '0 or 1 values` in the MVP. It is probably a small matter for the runtimes to be able to return multiple values here? But don't let that hold this up, can always revisit how it is going.

Also no mention if a function signature with arguments is usable in the MVP? Also seems a small matter, just not sure if it is really necessary yet.

| `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:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The br_table immediate needs the arity removed, too.

| 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 |
Expand Down