Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit 4c97261

Browse files
authored
[spec] Proper binary format for element segments (#82)
The element segment binary format allows for `ref.null` as well as `ref.func`. TODO: text format
1 parent 864f382 commit 4c97261

File tree

4 files changed

+59
-23
lines changed

4 files changed

+59
-23
lines changed

document/core/binary/modules.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ It decodes into an optional :ref:`start function <syntax-start>` that represents
314314
single: element; segment
315315
.. _binary-elem:
316316
.. _binary-elemsec:
317+
.. _binary-elemexpr:
317318

318319
Element Section
319320
~~~~~~~~~~~~~~~
@@ -327,13 +328,14 @@ It decodes into a vector of :ref:`element segments <syntax-elem>` that represent
327328
\X{seg}^\ast{:}\Bsection_9(\Bvec(\Belem)) &\Rightarrow& \X{seg} \\
328329
\production{element segment} & \Belem &::=&
329330
\hex{00}~~e{:}\Bexpr~~y^\ast{:}\Bvec(\Bfuncidx)
330-
&\Rightarrow& \{ \ETABLE~0, \EOFFSET~e, \EINIT~y^\ast \} \\
331-
\production{element segment} & \Belem &::=&
332-
\hex{01}~~y^\ast{:}\Bvec(\Bfuncidx)
333-
&\Rightarrow& \{ \EINIT~y^\ast \} \\
334-
\production{element segment} & \Belem &::=&
331+
&\Rightarrow& \{ \ETABLE~0, \EOFFSET~e, \EINIT~((\REFFUNC~y)~\END)^\ast \} \\ &&|&
332+
\hex{01}~~e^\ast{:}\Bvec(\Belemexpr)
333+
&\Rightarrow& \{ \EINIT~e^\ast \} \\ &&|&
335334
\hex{02}~~x{:}\Btableidx~~e{:}\Bexpr~~y^\ast{:}\Bvec(\Bfuncidx)
336-
&\Rightarrow& \{ \ETABLE~x, \EOFFSET~e, \EINIT~y^\ast \} \\
335+
&\Rightarrow& \{ \ETABLE~x, \EOFFSET~e, \EINIT~((\REFFUNC~y)~\END)^\ast \} \\
336+
\production{elemexpr} & \Belemexpr &::=&
337+
\hex{D0}~\hex{0B} &\Rightarrow& \REFNULL~\END \\ &&|&
338+
\hex{D2}~x{:}\Bfuncidx~\hex{0B} &\Rightarrow& (\REFFUNC~x)~\END \\
337339
\end{array}
338340
339341
.. note::
@@ -419,11 +421,9 @@ It decodes into a vector of :ref:`data segments <syntax-data>` that represent th
419421
\X{seg}^\ast{:}\Bsection_{11}(\Bvec(\Bdata)) &\Rightarrow& \X{seg} \\
420422
\production{data segment} & \Bdata &::=&
421423
\hex{00}~~e{:}\Bexpr~~b^\ast{:}\Bvec(\Bbyte)
422-
&\Rightarrow& \{ \DMEM~0, \DOFFSET~e, \DINIT~b^\ast \} \\
423-
\production{data segment} & \Bdata &::=&
424+
&\Rightarrow& \{ \DMEM~0, \DOFFSET~e, \DINIT~b^\ast \} \\ &&|&
424425
\hex{01}~~b^\ast{:}\Bvec(\Bbyte)
425-
&\Rightarrow& \{ \DINIT~b^\ast \} \\
426-
\production{data segment} & \Bdata &::=&
426+
&\Rightarrow& \{ \DINIT~b^\ast \} \\ &&|&
427427
\hex{02}~~x{:}\Bmemidx~~e{:}\Bexpr~~b^\ast{:}\Bvec(\Bbyte)
428428
&\Rightarrow& \{ \DMEM~x, \DOFFSET~e, \DINIT~b^\ast \} \\
429429
\end{array}

document/core/syntax/modules.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ starting with the smallest index not referencing a global :ref:`import <syntax-i
247247
single: table; element
248248
single: element; segment
249249
.. _syntax-elem:
250+
.. _syntax-elemexpr:
250251

251252
Element Segments
252253
~~~~~~~~~~~~~~~~
@@ -260,8 +261,11 @@ The |MELEM| component of a module defines a vector of element segments. Each act
260261
.. math::
261262
\begin{array}{llll}
262263
\production{element segment} & \elem &::=&
263-
\{ \ETABLE~\tableidx, \EOFFSET~\expr, \EINIT~\vec(\funcidx) \} \\&&|&
264-
\{ \EINIT~\vec(\funcidx) \} \\
264+
\{ \ETABLE~\tableidx, \EOFFSET~\expr, \EINIT~\vec(\elemexpr) \} \\&&|&
265+
\{ \EINIT~\vec(\elemexpr) \} \\
266+
\production{elemexpr} & \elemexpr &::=&
267+
\REFNULL~\END \\&&|&
268+
(\REFFUNC~\funcidx)~\END \\
265269
\end{array}
266270
267271
The |EOFFSET| is given by a :ref:`constant <valid-constant>` :ref:`expression <syntax-expr>`.

document/core/util/macros.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@
267267
.. |EOFFSET| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{offset}}
268268
.. |EINIT| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{init}}
269269

270+
.. |REFNULL| mathdef:: \xref{syntax/modules}{syntax-elemexpr}{\K{ref.null}}
271+
.. |REFFUNC| mathdef:: \xref{syntax/modules}{syntax-elemexpr}{\K{ref.func}}
272+
270273
.. |DMEM| mathdef:: \xref{syntax/modules}{syntax-data}{\K{data}}
271274
.. |DOFFSET| mathdef:: \xref{syntax/modules}{syntax-data}{\K{offset}}
272275
.. |DINIT| mathdef:: \xref{syntax/modules}{syntax-data}{\K{init}}
@@ -302,6 +305,7 @@
302305
.. |importdesc| mathdef:: \xref{syntax/modules}{syntax-importdesc}{\X{importdesc}}
303306
.. |exportdesc| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\X{exportdesc}}
304307
.. |elem| mathdef:: \xref{syntax/modules}{syntax-elem}{\X{elem}}
308+
.. |elemexpr| mathdef:: \xref{syntax/modules}{syntax-elemexpr}{\X{elemexpr}}
305309
.. |data| mathdef:: \xref{syntax/modules}{syntax-data}{\X{data}}
306310
.. |start| mathdef:: \xref{syntax/modules}{syntax-start}{\X{start}}
307311

@@ -529,6 +533,7 @@
529533
.. |Bimportdesc| mathdef:: \xref{binary/modules}{binary-importdesc}{\B{importdesc}}
530534
.. |Bexportdesc| mathdef:: \xref{binary/modules}{binary-exportdesc}{\B{exportdesc}}
531535
.. |Belem| mathdef:: \xref{binary/modules}{binary-elem}{\B{elem}}
536+
.. |Belemexpr| mathdef:: \xref{binary/modules}{binary-elemexpr}{\B{elemexpr}}
532537
.. |Bcode| mathdef:: \xref{binary/modules}{binary-code}{\B{code}}
533538
.. |Blocal| mathdef:: \xref{binary/modules}{binary-local}{\B{local}}
534539
.. |Blocals| mathdef:: \xref{binary/modules}{binary-local}{\B{locals}}
@@ -773,6 +778,7 @@
773778
.. |vdashmem| mathdef:: \xref{valid/modules}{valid-mem}{\vdash}
774779
.. |vdashglobal| mathdef:: \xref{valid/modules}{valid-global}{\vdash}
775780
.. |vdashelem| mathdef:: \xref{valid/modules}{valid-elem}{\vdash}
781+
.. |vdashelemexpr| mathdef:: \xref{valid/modules}{valid-elemexpr}{\vdash}
776782
.. |vdashdata| mathdef:: \xref{valid/modules}{valid-data}{\vdash}
777783
.. |vdashstart| mathdef:: \xref{valid/modules}{valid-start}{\vdash}
778784
.. |vdashexport| mathdef:: \xref{valid/modules}{valid-export}{\vdash}

document/core/valid/modules.rst

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Element Segments
147147

148148
Element segments :math:`\elem` are classified by :ref:`segment types <syntax-segtype>`.
149149

150-
:math:`\{ \ETABLE~x, \EOFFSET~\expr, \EINIT~y^\ast \}`
150+
:math:`\{ \ETABLE~x, \EOFFSET~\expr, \EINIT~e^\ast \}`
151151
......................................................
152152

153153
* The table :math:`C.\CTABLES[x]` must be defined in the context.
@@ -160,8 +160,9 @@ Element segments :math:`\elem` are classified by :ref:`segment types <syntax-seg
160160

161161
* The expression :math:`\expr` must be :ref:`constant <valid-constant>`.
162162

163-
* For each :math:`y_i` in :math:`y^\ast`,
164-
the function :math:`C.\CFUNCS[y]` must be defined in the context.
163+
* For each :math:`e_i` in :math:`e^\ast`,
164+
165+
* The element expression :math:`e_i` must be :ref:`valid <valid-elemexpr>`.
165166

166167
* Then the element segment is valid with type |SACTIVE|.
167168

@@ -174,26 +175,51 @@ Element segments :math:`\elem` are classified by :ref:`segment types <syntax-seg
174175
\qquad
175176
C \vdashexprconst \expr \const
176177
\qquad
177-
(C.\CFUNCS[y] = \functype)^\ast
178+
(C \vdashelemexpr e \ok)^\ast
178179
}{
179-
C \vdashelem \{ \ETABLE~x, \EOFFSET~\expr, \EINIT~y^\ast \} : \SACTIVE
180+
C \vdashelem \{ \ETABLE~x, \EOFFSET~\expr, \EINIT~e^\ast \} : \SACTIVE
180181
}
181182
182183
183-
:math:`\{ \EINIT~y^\ast \}`
184-
......................................................
184+
:math:`\{ \EINIT~e^\ast \}`
185+
...........................
185186

186-
* For each :math:`y_i` in :math:`y^\ast`,
187-
the function :math:`C.\CFUNCS[y]` must be defined in the context.
187+
* For each :math:`e_i` in :math:`e^\ast`,
188+
189+
* The element expression :math:`e_i` must be :ref:`valid <valid-elemexpr>`.
188190

189191
* Then the element segment is valid with type |SPASSIVE|.
190192

191193

192194
.. math::
193195
\frac{
194-
(C.\CFUNCS[y] = \functype)^\ast
196+
(C \vdashelemexpr e \ok)^\ast
197+
}{
198+
C \vdashelem \{ \EINIT~e^\ast \} : \SPASSIVE
199+
}
200+
201+
202+
.. _valid-elemexpr:
203+
204+
:math:`\elemexpr`
205+
.................
206+
207+
* An element expression must be:
208+
209+
* either of the form :math:`\REFNULL~\END`,
210+
211+
* or of the form :math:`(\REFFUNC~x)~\END`, in which case :math:`C.\CFUNCS[x]` must be defined in the context.
212+
213+
.. math::
214+
\frac{
215+
}{
216+
C \vdashelemexpr \REFNULL~\END \ok
217+
}
218+
\qquad
219+
\frac{
220+
C.\CFUNCS[x] = \functype
195221
}{
196-
C \vdashelem \{ \EINIT~y^\ast \} : \SPASSIVE
222+
C \vdashelemexpr (\REFFUNC~x)~\END \ok
197223
}
198224
199225

0 commit comments

Comments
 (0)