Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions document/core/binary/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,23 @@ Composite Types
$${grammar: Bmut Bcomptype Bfieldtype Bstoragetype Bpacktype}


.. index:: recursive type, sub type, composite type
.. index:: recursive type, sub type, desctype, composite type
pair: binary format; recursive type
pair: binary format; sub type
pair: binary format; desctype
.. _binary-rectype:
.. _binary-subtype:
.. _binary-desctype:
.. _binary-describestype:
.. _binary-descriptortype:

Recursive Types
~~~~~~~~~~~~~~~

:ref:`Recursive types <syntax-rectype>` are encoded by the byte ${:0x4E} followed by a :ref:`list <binary-list>` of :ref:`sub types <syntax-subtype>`.
Additional shorthands are recognized for unary recursions and sub types without super types.

$${grammar: Brectype Bsubtype}
$${grammar: Brectype Bsubtype Bdesctype Bdescribestype Bdescriptortype}


.. index:: limits
Expand Down
3 changes: 3 additions & 0 deletions document/core/util/macros.def
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@
.. |Bstoragetype| mathdef:: \xref{binary/types}{binary-storagetype}{\B{storagetype}}
.. |Bpacktype| mathdef:: \xref{binary/types}{binary-packtype}{\B{packtype}}
.. |Bcomptype| mathdef:: \xref{binary/types}{binary-comptype}{\B{comptype}}
.. |Bdescribestype| mathdef:: \xref{binary/types}{binary-describestype}{\B{describestype}}
.. |Bdescriptortype| mathdef:: \xref{binary/types}{binary-descriptortype}{\B{descriptortype}}
.. |Bdesctype| mathdef:: \xref{binary/types}{binary-desctype}{\B{desctype}}
.. |Bsubtype| mathdef:: \xref{binary/types}{binary-subtype}{\B{subtype}}
.. |Brectype| mathdef:: \xref{binary/types}{binary-rectype}{\B{rectype}}
.. |Bglobaltype| mathdef:: \xref{binary/types}{binary-globaltype}{\B{globaltype}}
Expand Down
19 changes: 16 additions & 3 deletions specification/wasm-latest/5.2-binary.types.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ grammar Babsheaptype : heaptype =

grammar Bheaptype : heaptype =
| ht:Babsheaptype => ht
| 0x62 x:Btypeidx => _HT EXACT (_IDX x)
| x33:Bs33 => _HT (_IDX $s33_to_u32(x33)) -- if x33 >= 0

grammar Breftype : reftype =
Expand Down Expand Up @@ -68,10 +69,22 @@ grammar Bcomptype : comptype =
| 0x5F ft*:Blist(Bfieldtype) => STRUCT ft*
| 0x60 t_1*:Bresulttype t_2*:Bresulttype => FUNC t_1* -> t_2*

grammar Bdescribestype : describestype =
| 0x4C x:Btypeidx => DESCRIBES (_IDX x)

grammar Bdescriptortype : descriptortype =
| 0x4D x:Btypeidx => DESCRIPTOR (_IDX x)

grammar Bdesctype : desctype =
| describestype:Bdescribestype descriptortype:Bdescriptortype ct:Bcomptype => describestype descriptortype ct

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We probably want some other variable names here. I can use dt1 and dt2, but not dt_1 and dt_2 because dt is already taken by deftype. Any suggestions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about just d_1, d_2? I think d isn't taken globally.

Btw, how about dropping the type suffix on describes/descriptortype? These names are a mouthful, and they aren't really types in their own right anyway, more like modifiers.

| describestype:Bdescribestype ct:Bcomptype => describestype ct
| descriptortype:Bdescriptortype ct:Bcomptype => descriptortype ct
| ct:Bcomptype => ct

grammar Bsubtype : subtype =
| 0x4F x*:Blist(Btypeidx) ct:Bcomptype => SUB FINAL (_IDX x)* ct
| 0x50 x*:Blist(Btypeidx) ct:Bcomptype => SUB (_IDX x)* ct
| ct:Bcomptype => SUB FINAL eps ct
| 0x4F x*:Blist(Btypeidx) desctype:Bdesctype => SUB FINAL (_IDX x)* desctype
| 0x50 x*:Blist(Btypeidx) desctype:Bdesctype => SUB (_IDX x)* desctype
| desctype:Bdesctype => SUB FINAL eps desctype

grammar Brectype : rectype =
| 0x4E st*:Blist(Bsubtype) => REC st*
Expand Down
9 changes: 9 additions & 0 deletions specification/wasm-latest/5.3-binary.instructions.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ grammar Binstr/control : instr = ...
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST l (REF null_1? ht_1) (REF null_2? ht_2)
| 0xFB 25:Bu32 (null_1?, null_2?):Bcastop
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST_FAIL l (REF null_1? ht_1) (REF null_2? ht_2)
| 0xFB 37:Bu32 (null_1?, null_2?):Bcastop
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST_DESC_EQ l (REF null_1? ht_1) (REF null_2? ht_2)
| 0xFB 38:Bu32 (null_1?, null_2?):Bcastop
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST_DESC_EQ_FAIL l (REF null_1? ht_1) (REF null_2? ht_2)
| ...

grammar Bcatch : catch =
Expand Down Expand Up @@ -146,6 +150,9 @@ grammar Binstr/ref : instr = ...
| 0xFB 21:Bu32 ht:Bheaptype => REF.TEST (REF NULL ht)
| 0xFB 22:Bu32 ht:Bheaptype => REF.CAST (REF ht)
| 0xFB 23:Bu32 ht:Bheaptype => REF.CAST (REF NULL ht)
| 0xFB 34:Bu32 x:Btypeidx => REF.GET_DESC x
| 0xFB 35:Bu32 ht:Bheaptype => REF.CAST_DESC_EQ (REF ht)
| 0xFB 36:Bu32 ht:Bheaptype => REF.CAST_DESC_EQ (REF NULL ht)
| ...

grammar Binstr/struct : instr = ...
Expand All @@ -155,6 +162,8 @@ grammar Binstr/struct : instr = ...
| 0xFB 3:Bu32 x:Btypeidx i:Bu32 => STRUCT.GET S x i
| 0xFB 4:Bu32 x:Btypeidx i:Bu32 => STRUCT.GET U x i
| 0xFB 5:Bu32 x:Btypeidx i:Bu32 => STRUCT.SET x i
| 0xFB 32:Bu32 x:Btypeidx => STRUCT.NEW_DESC x
| 0xFB 33:Bu32 x:Btypeidx => STRUCT.NEW_DEFAULT_DESC x
| ...

grammar Binstr/array : instr = ...
Expand Down
Loading