Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 64f9837

Browse files
authored
[spec/interpreter/test] Declarative element segments (#73)
1 parent 3e32403 commit 64f9837

25 files changed

+194
-45
lines changed

document/core/binary/modules.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,20 +333,24 @@ It decodes into a vector of :ref:`element segments <syntax-elem>` that represent
333333
&\Rightarrow& \{ \ETYPE~\X{et}, \EINIT~((\REFFUNC~y)~\END)^\ast, \EMODE~\EPASSIVE \} \\ &&|&
334334
\hex{02}~~x{:}\Btableidx~~e{:}\Bexpr~~\X{et}:\Belemkind~~y^\ast{:}\Bvec(\Bfuncidx)
335335
&\Rightarrow& \{ \ETYPE~\X{et}, \EINIT~((\REFFUNC~y)~\END)^\ast, \EMODE~\EACTIVE~\{ \ETABLE~x, \EOFFSET~e \} \} \\ &&|&
336+
\hex{03}~~\X{et}:\Belemkind~~y^\ast{:}\Bvec(\Bfuncidx)
337+
&\Rightarrow& \{ \ETYPE~\X{et}, \EINIT~((\REFFUNC~y)~\END)^\ast, \EMODE~\EDECLARATIVE \} \\ &&|&
336338
\hex{04}~~e{:}\Bexpr~~\X{el}^\ast{:}\Bvec(\Bexpr)
337339
&\Rightarrow& \{ \ETYPE~\FUNCREF, \EINIT~\X{el}^\ast, \EMODE~\EACTIVE~\{ \ETABLE~0, \EOFFSET~e \} \} \\ &&|&
338340
\hex{05}~~\X{et}:\Breftype~~\X{el}^\ast{:}\Bvec(\Bexpr)
339341
&\Rightarrow& \{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EPASSIVE \} \\ &&|&
340342
\hex{06}~~x{:}\Btableidx~~e{:}\Bexpr~~\X{et}:\Breftype~~\X{el}^\ast{:}\Bvec(\Bexpr)
341-
&\Rightarrow& \{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EACTIVE~\{ \ETABLE~x, \EOFFSET~e \} \} \\
343+
&\Rightarrow& \{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EACTIVE~\{ \ETABLE~x, \EOFFSET~e \} \} \\ &&|&
344+
\hex{07}~~\X{et}:\Breftype~~\X{el}^\ast{:}\Bvec(\Bexpr)
345+
&\Rightarrow& \{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EDECLARATIVE \} \\
342346
\production{element kind} & \Belemkind &::=&
343347
\hex{00} &\Rightarrow& \FUNCREF \\
344348
\end{array}
345349
346350
.. note::
347351
The initial byte can be interpreted as a bitfield.
348-
Bit 0 indicates a passive segment,
349-
bit 1 indicates the presence of an explicit table index for an active segment,
352+
Bit 0 indicates a passive or declarative segment,
353+
bit 1 indicates the presence of an explicit table index for an active segment and otherwise distinguishes passive from declarative segments,
350354
bit 2 indicates the use of element type and element :ref:`expressions <binary-expr>` instead of element kind and element indices.
351355

352356
Additional element kinds may be added in future versions of WebAssembly.

document/core/exec/modules.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,9 @@ where:
729729
\begin{array}{@{}l}
730730
\F{runelem}_i(\{\ETYPE~\X{et}, \EINIT~\reff^n, \EMODE~\EPASSIVE\}) \quad=\quad \epsilon \\
731731
\F{runelem}_i(\{\ETYPE~\X{et}, \EINIT~\reff^n, \EMODE~\EACTIVE \{\ETABLE~0, \EOFFSET~\instr^\ast~\END\}\}) \quad=\\ \qquad
732-
\instr^\ast~(\I32.\CONST~0)~(\I32.\CONST~n)~(\TABLEINIT~i)~(\ELEMDROP~i) \\[1ex]
732+
\instr^\ast~(\I32.\CONST~0)~(\I32.\CONST~n)~(\TABLEINIT~i)~(\ELEMDROP~i) \\
733+
\F{runelem}_i(\{\ETYPE~\X{et}, \EINIT~\reff^n, \EMODE~\EDECLARATIVE\}) \quad=\\ \qquad
734+
(\ELEMDROP~i) \\[1ex]
733735
\F{rundata}_i(\{\DINIT~b^n, DMODE~\DPASSIVE\}) \quad=\quad \epsilon \\
734736
\F{rundata}_i(\{\DINIT~b^n, DMODE~\DACTIVE \{\DMEM~0, \DOFFSET~\instr^\ast~\END\}\}) \quad=\\ \qquad
735737
\instr^\ast~(\I32.\CONST~0)~(\I32.\CONST~n)~(\MEMORYINIT~i)~(\DATADROP~i) \\

document/core/syntax/modules.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ Conventions
106106

107107
* The meta variables :math:`x, y` range over indices in any of the other index spaces.
108108

109-
* The notation :math:`\F{idx}(A)` denotes the set of indices from index space :math:`\X{idx}` occurring free in :math:`A`.
109+
* The notation :math:`\F{idx}(A)` denotes the set of indices from index space :math:`\X{idx}` occurring free in :math:`A`. We sometimes reinterpret this set as the :ref:`vector <syntax-vec>` of its elements.
110110

111111
.. note::
112-
For example, if :math:`\instr^\ast` is :math:`(\DATADROP~x) (\MEMORYINIT~y)`, then :math:`\freedataidx(\instr^\ast) = \{x, y\}`.
112+
For example, if :math:`\instr^\ast` is :math:`(\DATADROP~x) (\MEMORYINIT~y)`, then :math:`\freedataidx(\instr^\ast) = \{x, y\}`, or equivalently, the vector :math:`x~y`.
113113

114114

115115
.. index:: ! type definition, type index, function type
@@ -242,10 +242,12 @@ Globals are referenced through :ref:`global indices <syntax-globalidx>`,
242242
starting with the smallest index not referencing a global :ref:`import <syntax-import>`.
243243

244244

245-
.. index:: ! element, active, passive, element index, table, table index, expression, constant, function index, vector
245+
.. index:: ! element, ! element mode, ! active, ! passive, ! declarative, element index, table, table index, expression, constant, function index, vector
246246
pair: abstract syntax; element
247+
pair: abstract syntax; element mode
247248
single: table; element
248249
single: element; segment
250+
single: element; mode
249251
.. _syntax-elem:
250252
.. _syntax-elemmode:
251253

@@ -257,17 +259,19 @@ The initial contents of a table is uninitialized. *Element segments* can be used
257259
The |MELEMS| component of a module defines a vector of element segments.
258260
Each element segment defines an :ref:`reference type <syntax-reftype>` and a corresponding list of :ref:`constant <valid-constant>` element :ref:`expressions <syntax-expr>`.
259261

260-
Element segments have a mode that identifies them as either *passive* or *active*.
262+
Element segments have a mode that identifies them as either *passive*, *active*, or *declarative*.
261263
A passive element segment's elements can be copied to a table using the |TABLEINIT| instruction.
262264
An active element segment copies its elements into a table during :ref:`instantiation <exec-instantiation>`, as specified by a :ref:`table index <syntax-tableidx>` and a :ref:`constant <valid-constant>` :ref:`expression <syntax-expr>` defining an offset into that table.
265+
A declarative element segment is not available at runtime but merely serves to forward-declare references that are formed in code with instructions like :math:`REFFUNC`.
263266

264267
.. math::
265268
\begin{array}{llll}
266269
\production{element segment} & \elem &::=&
267270
\{ \ETYPE~\reftype, \EINIT~\vec(\expr), \EMODE~\elemmode \} \\
268271
\production{element segment mode} & \elemmode &::=&
269272
\EPASSIVE \\&&|&
270-
\EACTIVE~\{ \ETABLE~\tableidx, \EOFFSET~\expr \} \\
273+
\EACTIVE~\{ \ETABLE~\tableidx, \EOFFSET~\expr \} \\&&|&
274+
\EDECLARATIVE \\
271275
\end{array}
272276
273277
The |EOFFSET| is given by a :ref:`constant <valid-constant>` :ref:`expression <syntax-expr>`.

document/core/text/modules.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,9 @@ Element segments allow for an optional :ref:`table index <text-tableidx>` to ide
501501
\text{(}~\text{elem}~~\Tid^?~~(et, y^\ast){:}\Telemlist~\text{)} \\ &&& \qquad
502502
\Rightarrow\quad \{ \ETYPE~et, \EINIT~y^\ast, \EMODE~\EPASSIVE \} \\ &&|&
503503
\text{(}~\text{elem}~~\Tid^?~~x{:}\Ttableuse_I~~\text{(}~\text{offset}~~e{:}\Texpr_I~\text{)}~~(et, y^\ast){:}\Telemlist~\text{)} \\ &&& \qquad
504-
\Rightarrow\quad \{ \ETYPE~et, \EINIT~y^\ast, \EMODE~\EACTIVE~\{ \ETABLE~x, \EOFFSET~e \} \} \\
504+
\Rightarrow\quad \{ \ETYPE~et, \EINIT~y^\ast, \EMODE~\EACTIVE~\{ \ETABLE~x, \EOFFSET~e \} \} \\ &&&
505+
\text{(}~\text{elem}~~\Tid^?~~\text{declare}~~(et, y^\ast){:}\Telemlist~\text{)} \\ &&& \qquad
506+
\Rightarrow\quad \{ \ETYPE~et, \EINIT~y^\ast, \EMODE~\EDECLARATIVE \} \\
505507
\production{element list} & \Telemlist &::=&
506508
t{:}\Treftype~~y^\ast{:}\Tvec(\Telemexpr_I) \qquad\Rightarrow\quad ( \ETYPE~t, \EINIT~y^\ast ) \\
507509
\production{element expression} & \Telemexpr &::=&

document/core/util/macros.def

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
.. External Standards
44
.. ------------------
55

6-
.. |WasmDraft| replace:: http://webassembly.github.io/spec/core/
7-
.. _WasmDraft: http://webassembly.github.io/spec/core/
6+
.. |WasmDraft| replace:: https://webassembly.github.io/reference-types/core/
7+
.. _WasmDraft: https://webassembly.github.io/reference-types/core/
88

9-
.. |WasmIssues| replace:: http://github.com/webassembly/spec/issues/
10-
.. _WasmIssues: http://github.com/webassembly/spec/issues/
9+
.. |WasmIssues| replace:: https://github.com/webassembly/reference-types/issues/
10+
.. _WasmIssues: https://github.com/webassembly/reference-types/issues/
1111

1212
.. |IEEE754| replace:: IEEE 754-2019
1313
.. _IEEE754: https://ieeexplore.ieee.org/document/8766229
1414

1515
.. |Unicode| replace:: Unicode
16-
.. _Unicode: http://www.unicode.org/versions/latest/
16+
.. _Unicode: https://www.unicode.org/versions/latest/
1717

1818
.. |ASCII| replace:: ASCII
19-
.. _ASCII: http://webstore.ansi.org/RecordDetail.aspx?sku=INCITS+4-1986%5bR2012%5d
19+
.. _ASCII: https://webstore.ansi.org/RecordDetail.aspx?sku=INCITS+4-1986%5bR2012%5d
2020

2121

2222
.. External Definitions
@@ -273,8 +273,9 @@
273273
.. |ETYPE| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{type}}
274274
.. |EINIT| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{init}}
275275
.. |EMODE| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{mode}}
276-
.. |EPASSIVE| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{passive}}
277-
.. |EACTIVE| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{active}}
276+
.. |EPASSIVE| mathdef:: \xref{syntax/modules}{syntax-elemmode}{\K{passive}}
277+
.. |EACTIVE| mathdef:: \xref{syntax/modules}{syntax-elemmode}{\K{active}}
278+
.. |EDECLARATIVE| mathdef:: \xref{syntax/modules}{syntax-elemmode}{\K{declarative}}
278279
.. |ETABLE| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{table}}
279280
.. |EOFFSET| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{offset}}
280281

@@ -782,6 +783,7 @@
782783
.. |CLOCALS| mathdef:: \xref{valid/conventions}{context}{\K{locals}}
783784
.. |CLABELS| mathdef:: \xref{valid/conventions}{context}{\K{labels}}
784785
.. |CRETURN| mathdef:: \xref{valid/conventions}{context}{\K{return}}
786+
.. |CREFS| mathdef:: \xref{valid/conventions}{context}{\K{refs}}
785787

786788

787789
.. Judgments

document/core/valid/conventions.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ which collects relevant information about the surrounding :ref:`module <syntax-m
4343
* *Locals*: the list of locals declared in the current function (including parameters), represented by their value type.
4444
* *Labels*: the stack of labels accessible from the current position, represented by their result type.
4545
* *Return*: the return type of the current function, represented as an optional result type that is absent when no return is allowed, as in free-standing expressions.
46+
* *References*: the list of :ref:`function indices <syntax-funcidx>` that occur in element segments and can hence be used to form references elsewhere.
4647

4748
In other words, a context contains a sequence of suitable :ref:`types <syntax-type>` for each :ref:`index space <syntax-index>`,
4849
describing each defined entry in that space.
@@ -64,7 +65,8 @@ More concretely, contexts are defined as :ref:`records <notation-record>` :math:
6465
& \CDATAS & {\ok}^\ast, \\
6566
& \CLOCALS & \valtype^\ast, \\
6667
& \CLABELS & \resulttype^\ast, \\
67-
& \CRETURN & \resulttype^? ~\} \\
68+
& \CRETURN & \resulttype^?, \\
69+
& \CREFS & \funcidx^\ast ~\} \\
6870
\end{array}
6971
\end{array}
7072

document/core/valid/instructions.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,15 @@ Reference Instructions
198198

199199
* The function :math:`C.\CFUNCS[x]` must be defined in the context.
200200

201+
* The :ref:`function index <syntax-funcidx>` :math:`x` must be contained in :math:`C.\CREFS`.
202+
201203
* The instruction is valid with type :math:`[] \to [\FUNCREF]`.
202204

203205
.. math::
204206
\frac{
205207
C.\CFUNCS[x] = \functype
208+
\qquad
209+
x \in C.\CREFS
206210
}{
207211
C \vdashinstr \REFFUNC~x : [] \to [\FUNCREF]
208212
}

document/core/valid/modules.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ Element segments :math:`\elem` are not classified by any type but merely checked
217217
C; \X{et} \vdashelemmode \EACTIVE~\{ \ETABLE~x, \EOFFSET~\expr \} \ok
218218
}
219219
220+
:math:`\EDECLARATIVE`
221+
.....................
222+
223+
* The element mode is valid for any :ref:`reference type <syntax-reftype>` :math:`\X{et}`.
224+
225+
.. math::
226+
\frac{
227+
}{
228+
C; \X{et} \vdashelemmode \EDECLARATIVE \ok
229+
}
230+
231+
220232
221233
.. index:: data, memory, memory index, expression, byte
222234
pair: validation; data
@@ -278,7 +290,7 @@ Data segments :math:`\data` are not classified by any type but merely checked fo
278290
\qquad
279291
C \vdashexprconst \expr \const
280292
}{
281-
C \vdashelemmode \EACTIVE~\{ \DMEM~x, \DOFFSET~\expr \} \ok
293+
C \vdashelemmode \DACTIVE~\{ \DMEM~x, \DOFFSET~\expr \} \ok
282294
}
283295
284296
@@ -529,6 +541,8 @@ Instead, the context :math:`C` for validation of the module's content is constru
529541

530542
* :math:`C.\CRETURN` is empty.
531543

544+
* :math:`C.\CREFS` is the set :math:`\freefuncidx(\module.\MELEMS)`, i.e., the set of :ref:`function indices <syntax-funcidx>` occurring in any of the module's :ref:`element segments <syntax-elem>`.
545+
532546
* Let :math:`C'` be the :ref:`context <context>` where :math:`C'.\CGLOBALS` is the sequence :math:`\etglobals(\X{it}^\ast)` and all other fields are empty.
533547

534548
* Under the context :math:`C`:
@@ -614,7 +628,7 @@ Instead, the context :math:`C` for validation of the module's content is constru
614628
\qquad
615629
\X{igt}^\ast = \etglobals(\X{it}^\ast)
616630
\\
617-
C = \{ \CTYPES~\functype^\ast, \CFUNCS~\X{ift}^\ast~\X{ft}^\ast, \CTABLES~\X{itt}^\ast~\X{tt}^\ast, \CMEMS~\X{imt}^\ast~\X{mt}^\ast, \CGLOBALS~\X{igt}^\ast~\X{gt}^\ast, \CELEMS~{\ok}^{N_e}, \CDATAS~{\ok}^{N_d} \}
631+
C = \{ \CTYPES~\functype^\ast, \CFUNCS~\X{ift}^\ast~\X{ft}^\ast, \CTABLES~\X{itt}^\ast~\X{tt}^\ast, \CMEMS~\X{imt}^\ast~\X{mt}^\ast, \CGLOBALS~\X{igt}^\ast~\X{gt}^\ast, \CELEMS~{\ok}^{N_e}, \CDATAS~{\ok}^{N_d}, \CREFS~\freefuncidx(\elem^{N_e}) \}
618632
\\
619633
C' = \{ \CGLOBALS~\X{igt}^\ast \}
620634
\qquad
@@ -630,8 +644,8 @@ Instead, the context :math:`C` for validation of the module's content is constru
630644
\MTABLES~\table^\ast,
631645
\MMEMS~\mem^\ast,
632646
\MGLOBALS~\global^\ast, \\
633-
\MELEMS~\elem^\ast,
634-
\MDATAS~\data^\ast,
647+
\MELEMS~\elem^{N_e},
648+
\MDATAS~\data^{N_d},
635649
\MSTART~\start^?,
636650
\MIMPORTS~\import^\ast,
637651
\MEXPORTS~\export^\ast \} : \X{it}^\ast \to \X{et}^\ast \\

interpreter/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,15 @@ global: ( global <name>? <global_type> <instr>* )
262262
( global <name>? ( import <string> <string> ) <global_type> ) ;; = (import <name>? <string> <string> (global <global_type>))
263263
table: ( table <name>? <table_type> )
264264
( table <name>? ( export <string> ) <...> ) ;; = (export <string> (table <N>)) (table <name>? <...>)
265-
( table <name>? ( import <string> <string> ) <table_type> ) ;; = (import <name>? <string> <string> (table <table_type>))
265+
( table <name>? ( import <string> <string> ) <table_type> ) ;; = (import <string> <string> (table <name>? <table_type>))
266266
( table <name>? ( export <string> )* <ref_type> ( elem <var>* ) ) ;; = (table <name>? ( export <string> )* <size> <size> <ref_type>) (elem (i32.const 0) <var>*)
267+
elem: ( elem <var>? (offset <instr>* ) <var>* )
268+
( elem <var>? <expr> <var>* ) ;; = (elem <var>? (offset <expr>) <var>*)
269+
( elem <var>? declare <ref_type> <var>* )
267270
elem: ( elem <name>? ( table <var> )? <offset> <ref_type> <item>* )
268271
( elem <name>? ( table <var> )? <offset> func <var>* ) ;; = (elem <name>? ( table <var> )? <offset> funcref (ref.func <var>)*)
272+
( elem <var>? declare? <ref_type> <var>* )
273+
( elem <name>? declare? func <var>* ) ;; = (elem <name>? declare? funcref (ref.func <var>)*)
269274
offset: ( offset <instr>* )
270275
<expr> ;; = ( offset <expr> )
271276
item: ( item <instr>* )

interpreter/binary/decode.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,9 @@ let active_zero s =
651651
let offset = const s in
652652
Active {index; offset}
653653

654+
let declarative s =
655+
Declarative
656+
654657
let elem_index s =
655658
let x = at var s in
656659
[Source.(ref_func x @@ x.at)]
@@ -676,6 +679,11 @@ let elem s =
676679
let etype = elem_kind s in
677680
let einit = vec (at elem_index) s in
678681
{etype; einit; emode}
682+
| 0x03l ->
683+
let emode = at declarative s in
684+
let etype = elem_kind s in
685+
let einit = vec (at elem_index) s in
686+
{etype; einit; emode}
679687
| 0x04l ->
680688
let emode = at active_zero s in
681689
let einit = vec const s in
@@ -690,6 +698,11 @@ let elem s =
690698
let etype = ref_type s in
691699
let einit = vec const s in
692700
{etype; einit; emode}
701+
| 0x07l ->
702+
let emode = at declarative s in
703+
let etype = ref_type s in
704+
let einit = vec const s in
705+
{etype; einit; emode}
693706
| _ -> error s (pos s - 1) "invalid elements segment kind"
694707

695708
let elem_section s =

interpreter/binary/encode.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ let encode m =
524524
| Active {index; offset} ->
525525
vu32 0x02l;
526526
var index; const offset; elem_kind etype; vec elem_index einit
527+
| Declarative ->
528+
vu32 0x03l; elem_kind etype; vec elem_index einit
527529
else
528530
match emode.it with
529531
| Passive ->
@@ -532,6 +534,8 @@ let encode m =
532534
vu32 0x04l; const offset; vec const einit
533535
| Active {index; offset} ->
534536
vu32 0x06l; var index; const offset; ref_type etype; vec const einit
537+
| Declarative ->
538+
vu32 0x07l; ref_type etype; vec const einit
535539

536540
let elem_section elems =
537541
section 9 (vec elem) elems (elems <> [])
@@ -546,6 +550,8 @@ let encode m =
546550
vu32 0x00l; const offset; string dinit
547551
| Active {index; offset} ->
548552
vu32 0x02l; var index; const offset; string dinit
553+
| Declarative ->
554+
assert false
549555

550556
let data_section datas =
551557
section 11 (vec data) datas (datas <> [])

interpreter/exec/eval.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ let create_export (inst : module_inst) (ex : export) : export_inst =
573573
| TableExport x -> ExternTable (table inst x)
574574
| MemoryExport x -> ExternMemory (memory inst x)
575575
| GlobalExport x -> ExternGlobal (global inst x)
576-
in name, ext
576+
in (name, ext)
577577

578578
let create_elem (inst : module_inst) (seg : elem_segment) : elem_inst =
579579
let {etype; einit; _} = seg.it in
@@ -600,31 +600,34 @@ let init_func (inst : module_inst) (func : func_inst) =
600600
| _ -> assert false
601601

602602
let run_elem i elem =
603+
let at = elem.it.emode.at in
604+
let x = i @@ at in
603605
match elem.it.emode.it with
604606
| Passive -> []
605607
| Active {index; offset} ->
606-
let at = elem.it.emode.at in
607-
let x = i @@ at in
608608
offset.it @ [
609609
Const (I32 0l @@ at) @@ at;
610610
Const (I32 (Lib.List32.length elem.it.einit) @@ at) @@ at;
611611
TableInit (index, x) @@ at;
612612
ElemDrop x @@ at
613613
]
614+
| Declarative ->
615+
[ElemDrop x @@ at]
614616

615617
let run_data i data =
618+
let at = data.it.dmode.at in
619+
let x = i @@ at in
616620
match data.it.dmode.it with
617621
| Passive -> []
618622
| Active {index; offset} ->
619623
assert (index.it = 0l);
620-
let at = data.it.dmode.at in
621-
let x = i @@ at in
622624
offset.it @ [
623625
Const (I32 0l @@ at) @@ at;
624626
Const (I32 (Int32.of_int (String.length data.it.dinit)) @@ at) @@ at;
625627
MemoryInit x @@ at;
626628
DataDrop x @@ at
627629
]
630+
| Declarative -> assert false
628631

629632
let run_start start =
630633
[Call start @@ start.at]

interpreter/syntax/ast.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ type segment_mode = segment_mode' Source.phrase
151151
and segment_mode' =
152152
| Passive
153153
| Active of {index : var; offset : const}
154+
| Declarative
154155

155156
type elem_segment = elem_segment' Source.phrase
156157
and elem_segment' =

0 commit comments

Comments
 (0)