Skip to content

Commit

Permalink
Merge pull request WebAssembly#104 from WebAssembly/update-encodings
Browse files Browse the repository at this point in the history
Update binary encodings
  • Loading branch information
rossberg committed Sep 6, 2023
2 parents b062307 + 89d13db commit eab6b36
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions document/core/appendix/index-instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ def Instruction(name, opcode, type=None, validation=None, execution=None, operat
Instruction(r'\REFNULL~\X{ht}', r'\hex{D0}', r'[] \to [(\REF~\NULL~\X{ht})]', r'valid-ref.null', r'exec-ref.null'),
Instruction(r'\REFISNULL', r'\hex{D1}', r'[(\REF~\NULL~\X{ht})] \to [\I32]', r'valid-ref.is_null', r'exec-ref.is_null'),
Instruction(r'\REFFUNC~x', r'\hex{D2}', r'[] \to [\FUNCREF]', r'valid-ref.func', r'exec-ref.func'),
Instruction(r'\REFASNONNULL', r'\hex{D3}', r'[(\REF~\NULL~\X{ht})] \to [(\REF~\X{ht})]', r'valid-ref.as_non_null', r'exec-ref.as_non_null'),
Instruction(r'\BRONNULL~l', r'\hex{D4}', r'[t^\ast~(\REF~\NULL~\X{ht})] \to [t^\ast~(\REF~\X{ht})]', r'valid-br_on_null', r'exec-br_on_null'),
Instruction(None, r'\hex{D5}'),
Instruction(None, r'\hex{D3}'),
Instruction(r'\REFASNONNULL', r'\hex{D4}', r'[(\REF~\NULL~\X{ht})] \to [(\REF~\X{ht})]', r'valid-ref.as_non_null', r'exec-ref.as_non_null'),
Instruction(r'\BRONNULL~l', r'\hex{D5}', r'[t^\ast~(\REF~\NULL~\X{ht})] \to [t^\ast~(\REF~\X{ht})]', r'valid-br_on_null', r'exec-br_on_null'),
Instruction(r'\BRONNONNULL~l', r'\hex{D6}', r'[t^\ast~(\REF~\NULL~\X{ht})] \to [t^\ast]', r'valid-br_on_non_null', r'exec-br_on_non_null'),
Instruction(None, r'\hex{D7}'),
Instruction(None, r'\hex{D8}'),
Expand Down
8 changes: 4 additions & 4 deletions document/core/appendix/index-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Category Constructor
(reserved) :math:`\hex{7A}` .. :math:`\hex{71}`
:ref:`Heap type <syntax-heaptype>` |FUNC| :math:`\hex{70}` (-16 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |EXTERN| :math:`\hex{6F}` (-17 as |Bs7|)
(reserved) :math:`\hex{6E}` .. :math:`\hex{6D}`
:ref:`Reference type <syntax-reftype>` |REF| |NULL| :math:`\hex{6C}` (-20 as |Bs7|)
:ref:`Reference type <syntax-reftype>` |REF| :math:`\hex{6B}` (-21 as |Bs7|)
(reserved) :math:`\hex{6A}` .. :math:`\hex{61}`
(reserved) :math:`\hex{6E}` .. :math:`\hex{65}`
:ref:`Reference type <syntax-reftype>` |REF| :math:`\hex{64}` (-28 as |Bs7|)
:ref:`Reference type <syntax-reftype>` |REF| |NULL| :math:`\hex{63}` (-29 as |Bs7|)
(reserved) :math:`\hex{62}` .. :math:`\hex{61}`
:ref:`Function type <syntax-functype>` :math:`[\valtype^\ast] \toF[\valtype^\ast]` :math:`\hex{60}` (-32 as |Bs7|)
(reserved) :math:`\hex{5F}` .. :math:`\hex{41}`
:ref:`Result type <syntax-resulttype>` :math:`[\epsilon]` :math:`\hex{40}` (-64 as |Bs7|)
Expand Down
4 changes: 2 additions & 2 deletions document/core/binary/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Control Instructions
\hex{13}~~y{:}\Btypeidx~~x{:}\Btableidx &\Rightarrow& \RETURNCALLINDIRECT~x~y \\ &&|&
\hex{14}~~x{:}\Btypeidx &\Rightarrow& \CALLREF~x \\ &&|&
\hex{15}~~x{:}\Btypeidx &\Rightarrow& \RETURNCALLREF~x \\ &&|&
\hex{D4}~~l{:}\Blabelidx &\Rightarrow& \BRONNULL~l \\ &&|&
\hex{D5}~~l{:}\Blabelidx &\Rightarrow& \BRONNULL~l \\ &&|&
\hex{D6}~~l{:}\Blabelidx &\Rightarrow& \BRONNONNULL~l \\
\end{array}
Expand Down Expand Up @@ -103,7 +103,7 @@ Reference Instructions
\hex{D0}~~t{:}\Bheaptype &\Rightarrow& \REFNULL~t \\ &&|&
\hex{D1} &\Rightarrow& \REFISNULL \\ &&|&
\hex{D2}~~x{:}\Bfuncidx &\Rightarrow& \REFFUNC~x \\ &&|&
\hex{D3} &\Rightarrow& \REFASNONNULL \\
\hex{D4} &\Rightarrow& \REFASNONNULL \\
\end{array}
Expand Down
4 changes: 2 additions & 2 deletions document/core/binary/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Reference Types
.. math::
\begin{array}{llclll@{\qquad\qquad}l}
\production{reference type} & \Breftype &::=&
\hex{6B}~~\X{ht}{:}\Bheaptype &\Rightarrow& \REF~\X{ht} \\ &&|&
\hex{6C}~~\X{ht}{:}\Bheaptype &\Rightarrow& \REF~\NULL~\X{ht} \\ &&|&
\hex{63}~~\X{ht}{:}\Bheaptype &\Rightarrow& \REF~\NULL~\X{ht} \\ &&|&
\hex{64}~~\X{ht}{:}\Bheaptype &\Rightarrow& \REF~\X{ht} \\ &&|&
\hex{6F} &\Rightarrow& \EXTERNREF \\ &&|&
\hex{70} &\Rightarrow& \FUNCREF \\
\end{array}
Expand Down
10 changes: 5 additions & 5 deletions interpreter/binary/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ let ref_type s =
match s7 s with
| -0x10 -> (Null, FuncHT)
| -0x11 -> (Null, ExternHT)
| -0x14 -> (Null, heap_type s)
| -0x15 -> (NoNull, heap_type s)
| -0x1c -> (NoNull, heap_type s)
| -0x1d -> (Null, heap_type s)
| _ -> error s pos "malformed reference type"

let val_type s =
Expand Down Expand Up @@ -522,9 +522,9 @@ let rec instr s =
| 0xd0 -> ref_null (heap_type s)
| 0xd1 -> ref_is_null
| 0xd2 -> ref_func (at var s)
| 0xd3 -> ref_as_non_null
| 0xd4 -> br_on_null (at var s)
| 0xd5 as b -> illegal s pos b
| 0xd3 as b -> illegal s pos b
| 0xd4 -> ref_as_non_null
| 0xd5 -> br_on_null (at var s)
| 0xd6 -> br_on_non_null (at var s)

| 0xfc as b ->
Expand Down
8 changes: 4 additions & 4 deletions interpreter/binary/encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ struct
let ref_type = function
| (Null, FuncHT) -> s7 (-0x10)
| (Null, ExternHT) -> s7 (-0x11)
| (Null, t) -> s7 (-0x14); heap_type t
| (NoNull, t) -> s7 (-0x15); heap_type t
| (NoNull, t) -> s7 (-0x1c); heap_type t
| (Null, t) -> s7 (-0x1d); heap_type t

let val_type = function
| NumT t -> num_type t
Expand Down Expand Up @@ -193,7 +193,7 @@ struct
| Br x -> op 0x0c; var x
| BrIf x -> op 0x0d; var x
| BrTable (xs, x) -> op 0x0e; vec var xs; var x
| BrOnNull x -> op 0xd4; var x
| BrOnNull x -> op 0xd5; var x
| BrOnNonNull x -> op 0xd6; var x
| Return -> op 0x0f
| Call x -> op 0x10; var x
Expand Down Expand Up @@ -318,7 +318,7 @@ struct
| RefNull t -> op 0xd0; heap_type t
| RefFunc x -> op 0xd2; var x
| RefIsNull -> op 0xd1
| RefAsNonNull -> op 0xd3
| RefAsNonNull -> op 0xd4

| Const {it = I32 c; _} -> op 0x41; s32 c
| Const {it = I64 c; _} -> op 0x42; s64 c
Expand Down
10 changes: 5 additions & 5 deletions proposals/function-references/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Typing of instruction sequences is updated to account for initialization of loca
- `epsilon : [] -> [] epsilon`

Note: These typing rules do not try to eliminate duplicate indices, but an implementation could.

A subsumption rule allows to go to a supertype for any instruction:

* `instr`
Expand Down Expand Up @@ -302,8 +302,8 @@ Table definitions have an initialiser value:
| ------ | --------------- | ---------- |
| -0x10 | `funcref` | |
| -0x11 | `externref` | |
| -0x14 | `(ref null ht)` | `$t : heaptype` |
| -0x15 | `(ref ht)` | `$t : heaptype` |
| -0x1c | `(ref ht)` | `$t : heaptype` |
| -0x1d | `(ref null ht)` | `$t : heaptype` |

#### Heap Types

Expand All @@ -321,8 +321,8 @@ The opcode for heap types is encoded as an `s33`.
| ------ | ------------------------ | ---------- |
| 0x14 | `call_ref $t` | `$t : u32` |
| 0x15 | `return_call_ref $t` | `$t : u32` |
| 0xd3 | `ref.as_non_null` | |
| 0xd4 | `br_on_null $l` | `$l : u32` |
| 0xd4 | `ref.as_non_null` | |
| 0xd5 | `br_on_null $l` | `$l : u32` |
| 0xd6 | `br_on_non_null $l` | `$l : u32` |

### Tables
Expand Down

0 comments on commit eab6b36

Please sign in to comment.