Skip to content

Commit 273c2ac

Browse files
committed
Merge branch 'funcref'
2 parents cd543fa + fa6ff17 commit 273c2ac

File tree

4 files changed

+350
-4
lines changed

4 files changed

+350
-4
lines changed

document/core/binary/modules.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ It decodes into a vector of :ref:`element segments <syntax-elem>` that represent
364364
&\Rightarrow& \\&&&\quad
365365
\{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EDECLARATIVE \} \\
366366
\production{element kind} & \Belemkind &::=&
367-
\hex{00} &\Rightarrow& \FUNCREF \\
367+
\hex{00} &\Rightarrow& (\REF~\FUNC) \\
368368
\end{array}
369369
370370
.. note::

interpreter/binary/decode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ let elem s =
11581158
| 0x04l ->
11591159
let emode = at active_zero s in
11601160
let einit = vec const s in
1161-
{etype = (NoNull, FuncHT); einit; emode}
1161+
{etype = (Null, FuncHT); einit; emode}
11621162
| 0x05l ->
11631163
let emode = at passive s in
11641164
let etype = ref_type s in

interpreter/binary/encode.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ struct
992992
match emode.it with
993993
| Passive ->
994994
u32 0x01l; elem_kind etype; vec elem_index einit
995-
| Active {index; offset} when index.it = 0l && is_elem_kind etype ->
995+
| Active {index; offset} when index.it = 0l ->
996996
u32 0x00l; const offset; vec elem_index einit
997997
| Active {index; offset} ->
998998
u32 0x02l;
@@ -1003,7 +1003,7 @@ struct
10031003
match emode.it with
10041004
| Passive ->
10051005
u32 0x05l; ref_type etype; vec const einit
1006-
| Active {index; offset} when index.it = 0l && is_elem_kind etype ->
1006+
| Active {index; offset} when index.it = 0l && etype = (Null, FuncHT) ->
10071007
u32 0x04l; const offset; vec const einit
10081008
| Active {index; offset} ->
10091009
u32 0x06l; var index; const offset; ref_type etype; vec const einit

test/core/elem.wast

Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,352 @@
242242
)
243243

244244

245+
;; Binary format variations
246+
247+
(module
248+
(func)
249+
(table 1 funcref)
250+
(elem (i32.const 0) func 0)
251+
)
252+
(module binary
253+
"\00asm" "\01\00\00\00" ;; Magic
254+
"\01\04\01\60\00\00" ;; Type section: 1 type
255+
"\03\02\01\00" ;; Function section: 1 function
256+
"\04\04\01" ;; Table section: 1 table
257+
"\70\00\01" ;; Table 0: [1..] funcref
258+
"\09\07\01" ;; Elem section: 1 element segment
259+
"\00\41\00\0b\01\00" ;; Segment 0: (i32.const 0) func 0
260+
"\0a\04\01" ;; Code section: 1 function
261+
"\02\00\0b" ;; Function 0: empty
262+
)
263+
264+
(module
265+
(func)
266+
(table 1 funcref)
267+
(elem func 0)
268+
)
269+
(module binary
270+
"\00asm" "\01\00\00\00" ;; Magic
271+
"\01\04\01\60\00\00" ;; Type section: 1 type
272+
"\03\02\01\00" ;; Function section: 1 function
273+
"\04\04\01" ;; Table section: 1 table
274+
"\70\00\01" ;; Table 0: [1..] funcref
275+
"\09\05\01" ;; Elem section: 1 element segment
276+
"\01\00\01\00" ;; Segment 0: func 0
277+
"\0a\04\01" ;; Code section: 1 function
278+
"\02\00\0b" ;; Function 0: empty
279+
)
280+
281+
(module
282+
(func)
283+
(table 1 funcref)
284+
(elem (table 0) (i32.const 0) func 0)
285+
)
286+
(module binary
287+
"\00asm" "\01\00\00\00" ;; Magic
288+
"\01\04\01\60\00\00" ;; Type section: 1 type
289+
"\03\02\01\00" ;; Function section: 1 function
290+
"\04\04\01" ;; Table section: 1 table
291+
"\70\00\01" ;; Table 0: [1..] funcref
292+
"\09\09\01" ;; Elem section: 1 element segment
293+
"\02\00\41\00\0b\00\01\00" ;; Segment 0: (table 0) (i32.const 0) func 0
294+
"\0a\04\01" ;; Code section: 1 function
295+
"\02\00\0b" ;; Function 0: empty
296+
)
297+
298+
(module
299+
(func)
300+
(table 1 funcref)
301+
(elem declare func 0)
302+
)
303+
(module binary
304+
"\00asm" "\01\00\00\00" ;; Magic
305+
"\01\04\01\60\00\00" ;; Type section: 1 type
306+
"\03\02\01\00" ;; Function section: 1 function
307+
"\04\04\01" ;; Table section: 1 table
308+
"\70\00\01" ;; Table 0: [1..] funcref
309+
"\09\05\01" ;; Elem section: 1 element segment
310+
"\03\00\01\00" ;; Segment 0: declare func 0
311+
"\0a\04\01" ;; Code section: 1 function
312+
"\02\00\0b" ;; Function 0: empty
313+
)
314+
315+
(module
316+
(func)
317+
(table 1 funcref)
318+
(elem (i32.const 0) (;;)(ref func) (ref.func 0))
319+
)
320+
(module binary
321+
"\00asm" "\01\00\00\00" ;; Magic
322+
"\01\04\01\60\00\00" ;; Type section: 1 type
323+
"\03\02\01\00" ;; Function section: 1 function
324+
"\04\04\01" ;; Table section: 1 table
325+
"\70\00\01" ;; Table 0: [1..] funcref
326+
"\09\09\01" ;; Elem section: 1 element segment
327+
"\04\41\00\0b\01\d2\00\0b" ;; Segment 0: (i32.const 0) (ref.func 0)
328+
"\0a\04\01" ;; Code section: 1 function
329+
"\02\00\0b" ;; Function 0: empty
330+
)
331+
(module
332+
(func)
333+
(table 1 funcref)
334+
(elem (i32.const 0) funcref (ref.null func))
335+
)
336+
(module binary
337+
"\00asm" "\01\00\00\00" ;; Magic
338+
"\01\04\01\60\00\00" ;; Type section: 1 type
339+
"\03\02\01\00" ;; Function section: 1 function
340+
"\04\04\01" ;; Table section: 1 table
341+
"\70\00\01" ;; Table 0: [1..] funcref
342+
"\09\09\01" ;; Elem section: 1 element segment
343+
"\04\41\00\0b\01\d0\70\0b" ;; Segment 0: (i32.const 0) (ref.null func)
344+
"\0a\04\01" ;; Code section: 1 function
345+
"\02\00\0b" ;; Function 0: empty
346+
)
347+
348+
(module
349+
(func)
350+
(table 1 funcref)
351+
(elem (i32.const 0) funcref (ref.func 0))
352+
)
353+
(module binary
354+
"\00asm" "\01\00\00\00" ;; Magic
355+
"\01\04\01\60\00\00" ;; Type section: 1 type
356+
"\03\02\01\00" ;; Function section: 1 function
357+
"\04\04\01" ;; Table section: 1 table
358+
"\70\00\01" ;; Table 0: [1..] funcref
359+
"\09\07\01" ;; Elem section: 1 element segment
360+
"\05\70\01\d2\00\0b" ;; Segment 0: funcref (ref.func 0)
361+
"\0a\04\01" ;; Code section: 1 function
362+
"\02\00\0b" ;; Function 0: empty
363+
)
364+
(module
365+
(func)
366+
(table 1 funcref)
367+
(elem (i32.const 0) funcref (ref.null func))
368+
)
369+
(module binary
370+
"\00asm" "\01\00\00\00" ;; Magic
371+
"\01\04\01\60\00\00" ;; Type section: 1 type
372+
"\03\02\01\00" ;; Function section: 1 function
373+
"\04\04\01" ;; Table section: 1 table
374+
"\70\00\01" ;; Table 0: [1..] funcref
375+
"\09\07\01" ;; Elem section: 1 element segment
376+
"\05\70\01\d0\70\0b" ;; Segment 0: funcref (ref.null func)
377+
"\0a\04\01" ;; Code section: 1 function
378+
"\02\00\0b" ;; Function 0: empty
379+
)
380+
381+
(module
382+
(func)
383+
(table 1 funcref)
384+
(elem (table 0) (i32.const 0) funcref (ref.func 0))
385+
)
386+
(module binary
387+
"\00asm" "\01\00\00\00" ;; Magic
388+
"\01\04\01\60\00\00" ;; Type section: 1 type
389+
"\03\02\01\00" ;; Function section: 1 function
390+
"\04\04\01" ;; Table section: 1 table
391+
"\70\00\01" ;; Table 0: [1..] funcref
392+
"\09\0b\01" ;; Elem section: 1 element segment
393+
"\06\00\41\00\0b\70\01\d2\00\0b" ;; Segment 0: (table 0) (i32.const 0) funcref (ref.func 0)
394+
"\0a\04\01" ;; Code section: 1 function
395+
"\02\00\0b" ;; Function 0: empty
396+
)
397+
(module
398+
(func)
399+
(table 1 funcref)
400+
(elem (table 0) (i32.const 0) funcref (ref.null func))
401+
)
402+
(module binary
403+
"\00asm" "\01\00\00\00" ;; Magic
404+
"\01\04\01\60\00\00" ;; Type section: 1 type
405+
"\03\02\01\00" ;; Function section: 1 function
406+
"\04\04\01" ;; Table section: 1 table
407+
"\70\00\01" ;; Table 0: [1..] funcref
408+
"\09\0b\01" ;; Elem section: 1 element segment
409+
"\06\00\41\00\0b\70\01\d0\70\0b" ;; Segment 0: (table 0) (i32.const 0) funcref (ref.null func)
410+
"\0a\04\01" ;; Code section: 1 function
411+
"\02\00\0b" ;; Function 0: empty
412+
)
413+
414+
(module
415+
(func)
416+
(table 1 funcref)
417+
(elem declare funcref (ref.func 0))
418+
)
419+
(module binary
420+
"\00asm" "\01\00\00\00" ;; Magic
421+
"\01\04\01\60\00\00" ;; Type section: 1 type
422+
"\03\02\01\00" ;; Function section: 1 function
423+
"\04\04\01" ;; Table section: 1 table
424+
"\70\00\01" ;; Table 0: [1..] funcref
425+
"\09\07\01" ;; Elem section: 1 element segment
426+
"\07\70\01\d2\00\0b" ;; Segment 0: declare funcref (ref.func 0)
427+
"\0a\04\01" ;; Code section: 1 function
428+
"\02\00\0b" ;; Function 0: empty
429+
)
430+
(module
431+
(func)
432+
(table 1 funcref)
433+
(elem declare funcref (ref.null func))
434+
)
435+
(module binary
436+
"\00asm" "\01\00\00\00" ;; Magic
437+
"\01\04\01\60\00\00" ;; Type section: 1 type
438+
"\03\02\01\00" ;; Function section: 1 function
439+
"\04\04\01" ;; Table section: 1 table
440+
"\70\00\01" ;; Table 0: [1..] funcref
441+
"\09\07\01" ;; Elem section: 1 element segment
442+
"\07\70\01\d0\70\0b" ;; Segment 0: declare funcref (ref.null func)
443+
"\0a\04\01" ;; Code section: 1 function
444+
"\02\00\0b" ;; Function 0: empty
445+
)
446+
447+
448+
(module
449+
(func)
450+
(table 1 (ref func) (ref.func 0))
451+
(elem (i32.const 0) func 0)
452+
)
453+
(module binary
454+
"\00asm" "\01\00\00\00" ;; Magic
455+
"\01\04\01\60\00\00" ;; Type section: 1 type
456+
"\03\02\01\00" ;; Function section: 1 function
457+
"\04\0a\01" ;; Table section: 1 table
458+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
459+
"\09\07\01" ;; Elem section: 1 element segment
460+
"\00\41\00\0b\01\00" ;; Segment 0: (i32.const 0) func 0
461+
"\0a\04\01" ;; Code section: 1 function
462+
"\02\00\0b" ;; Function 0: empty
463+
)
464+
465+
(module
466+
(func)
467+
(table 1 (ref func) (ref.func 0))
468+
(elem func 0)
469+
)
470+
(module binary
471+
"\00asm" "\01\00\00\00" ;; Magic
472+
"\01\04\01\60\00\00" ;; Type section: 1 type
473+
"\03\02\01\00" ;; Function section: 1 function
474+
"\04\0a\01" ;; Table section: 1 table
475+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
476+
"\09\05\01" ;; Elem section: 1 element segment
477+
"\01\00\01\00" ;; Segment 0: func 0
478+
"\0a\04\01" ;; Code section: 1 function
479+
"\02\00\0b" ;; Function 0: empty
480+
)
481+
482+
(module
483+
(func)
484+
(table 1 (ref func) (ref.func 0))
485+
(elem (table 0) (i32.const 0) func 0)
486+
)
487+
(module binary
488+
"\00asm" "\01\00\00\00" ;; Magic
489+
"\01\04\01\60\00\00" ;; Type section: 1 type
490+
"\03\02\01\00" ;; Function section: 1 function
491+
"\04\0a\01" ;; Table section: 1 table
492+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
493+
"\09\09\01" ;; Elem section: 1 element segment
494+
"\02\00\41\00\0b\00\01\00" ;; Segment 0: (table 0) (i32.const 0) func 0
495+
"\0a\04\01" ;; Code section: 1 function
496+
"\02\00\0b" ;; Function 0: empty
497+
)
498+
499+
(module
500+
(func)
501+
(table 1 (ref func) (ref.func 0))
502+
(elem declare func 0)
503+
)
504+
(module binary
505+
"\00asm" "\01\00\00\00" ;; Magic
506+
"\01\04\01\60\00\00" ;; Type section: 1 type
507+
"\03\02\01\00" ;; Function section: 1 function
508+
"\04\0a\01" ;; Table section: 1 table
509+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
510+
"\09\05\01" ;; Elem section: 1 element segment
511+
"\03\00\01\00" ;; Segment 0: declare func 0
512+
"\0a\04\01" ;; Code section: 1 function
513+
"\02\00\0b" ;; Function 0: empty
514+
)
515+
516+
(assert_invalid
517+
(module
518+
(func)
519+
(table 1 (ref func) (ref.func 0))
520+
(elem (i32.const 0) funcref (ref.func 0))
521+
)
522+
"type mismatch"
523+
)
524+
(assert_invalid
525+
(module binary
526+
"\00asm" "\01\00\00\00" ;; Magic
527+
"\01\04\01\60\00\00" ;; Type section: 1 type
528+
"\03\02\01\00" ;; Function section: 1 function
529+
"\04\0a\01" ;; Table section: 1 table
530+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
531+
"\09\09\01" ;; Elem section: 1 element segment
532+
"\04\41\00\0b\01\d2\00\0b" ;; Segment 0: (i32.const 0) (ref.func 0)
533+
"\0a\04\01" ;; Code section: 1 function
534+
"\02\00\0b" ;; Function 0: empty
535+
)
536+
"type mismatch"
537+
)
538+
539+
(module
540+
(func)
541+
(table 1 (ref func) (ref.func 0))
542+
(elem (ref func) (ref.func 0))
543+
)
544+
(module binary
545+
"\00asm" "\01\00\00\00" ;; Magic
546+
"\01\04\01\60\00\00" ;; Type section: 1 type
547+
"\03\02\01\00" ;; Function section: 1 function
548+
"\04\0a\01" ;; Table section: 1 table
549+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
550+
"\09\08\01" ;; Elem section: 1 element segment
551+
"\05\64\70\01\d2\00\0b" ;; Segment 0: (ref func) (ref.func 0)
552+
"\0a\04\01" ;; Code section: 1 function
553+
"\02\00\0b" ;; Function 0: empty
554+
)
555+
556+
(module
557+
(func)
558+
(table 1 (ref func) (ref.func 0))
559+
(elem (table 0) (i32.const 0) (ref func) (ref.func 0))
560+
)
561+
(module binary
562+
"\00asm" "\01\00\00\00" ;; Magic
563+
"\01\04\01\60\00\00" ;; Type section: 1 type
564+
"\03\02\01\00" ;; Function section: 1 function
565+
"\04\0a\01" ;; Table section: 1 table
566+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
567+
"\09\0c\01" ;; Elem section: 1 element segment
568+
"\06\00\41\00\0b\64\70\01\d2\00\0b" ;; Segment 0: (table 0) (i32.const 0) (ref func) (ref.func 0)
569+
"\0a\04\01" ;; Code section: 1 function
570+
"\02\00\0b" ;; Function 0: empty
571+
)
572+
573+
(module
574+
(func)
575+
(table 1 (ref func) (ref.func 0))
576+
(elem declare (ref func) (ref.func 0))
577+
)
578+
(module binary
579+
"\00asm" "\01\00\00\00" ;; Magic
580+
"\01\04\01\60\00\00" ;; Type section: 1 type
581+
"\03\02\01\00" ;; Function section: 1 function
582+
"\04\0a\01" ;; Table section: 1 table
583+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
584+
"\09\08\01" ;; Elem section: 1 element segment
585+
"\07\64\70\01\d2\00\0b" ;; Segment 0: declare (ref func) (ref.func 0)
586+
"\0a\04\01" ;; Code section: 1 function
587+
"\02\00\0b" ;; Function 0: empty
588+
)
589+
590+
245591
;; Invalid bounds for elements
246592

247593
(assert_trap

0 commit comments

Comments
 (0)