Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
[overview] Fill in binary format (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg authored Mar 27, 2020
1 parent 4753632 commit 60ff11c
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions proposals/function-references/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Note: In a Wasm engine, function references (whether first-class or as table ent

* Add a new form of *typed reference type* `ref $t` and a nullable variant `ref (null $t)`, where `$t` is a type index; can be used as both a value type or an element type for tables

* Add an instruction `ref.as_non_null` that converts an nullable reference to a non-nullable one or traps if null
* Add an instruction `ref.as_non_null` that converts a nullable reference to a non-nullable one or traps if null

* Add an instruction `br_on_null` that converts an nullable reference to a non-nullable one or branches if null
* Add an instruction `br_on_null` that converts a nullable reference to a non-nullable one or branches if null

* Add an instruction `call_ref` for calling a function through a `ref $t`

Expand Down Expand Up @@ -220,7 +220,7 @@ The following rules, now defined in terms of constructed types, replace and exte

#### Optional References

* `ref.as_non_null` converts an nullable reference to a non-null one
* `ref.as_non_null` converts a nullable reference to a non-null one
- `ref.as_non_null : [(ref null $t)] -> [(ref $t)]`
- iff `$t` is defined
- traps on `null`
Expand Down Expand Up @@ -261,12 +261,34 @@ TODO: This assumes that let-bound locals are mutable. Should they be?
- `(table <tabletype>)` is shorthand for `(table <tabletype> (ref.null))`


### Tables
## Binary Format

### Types

TODO: how to initialise tables of non-null element type (init value? init segment?).
#### Reference Types

The opcode for reference types is generalised to an `s33`.

## Binary Format
| Opcode | Type | Parameters |
| ------ | --------------- | ---------- |
| i >= 0 | `(ref i)` | |
| -0x10 | `funcref` | |
| -0x11 | `anyref` | |
| -0x12 | `nullref` | |
| -0x14 | `(ref null $t)` | `$t : u32` |

### Instructions

| Opcode | Instruction | Immediates |
| ------ | ------------------------ | ---------- |
| 0x14 | `call_ref` | |
| 0x15 | `return_call_ref` | |
| 0x16 | `func.bind (type $t)` | `$t : u32` |
| 0x17 | `let <bt> <locals>` | `bt : blocktype, locals : (as in functions)` |
| 0xd3 | `ref.as_non_null` | |
| 0xd4 | `br_on_null $l` | `$l : u32` |

### Tables

TODO.

Expand Down

0 comments on commit 60ff11c

Please sign in to comment.