Add support for table.copy
This adds support for the `table.copy` instruction from the bulk memory proposal. It also supports multiple tables, which were introduced by the reference types proposal. Part of #928
This commit is contained in:
63
tests/misc_testsuite/table_copy.wast
Normal file
63
tests/misc_testsuite/table_copy.wast
Normal file
@@ -0,0 +1,63 @@
|
||||
(module
|
||||
(func $f (param i32 i32 i32) (result i32) (local.get 0))
|
||||
(func $g (param i32 i32 i32) (result i32) (local.get 1))
|
||||
(func $h (param i32 i32 i32) (result i32) (local.get 2))
|
||||
|
||||
;; Indices: 0 1 2 3 4 5 6 7 8
|
||||
(table funcref (elem $f $g $h $f $g $h $f $g $h))
|
||||
;; After table.copy: $g $h $f
|
||||
|
||||
(func (export "copy") (param i32 i32 i32)
|
||||
local.get 0
|
||||
local.get 1
|
||||
local.get 2
|
||||
table.copy)
|
||||
|
||||
(func (export "call") (param i32 i32 i32 i32) (result i32)
|
||||
local.get 0
|
||||
local.get 1
|
||||
local.get 2
|
||||
local.get 3
|
||||
call_indirect (param i32 i32 i32) (result i32))
|
||||
)
|
||||
|
||||
;; Call $f at 0
|
||||
(assert_return
|
||||
(invoke "call" (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 0))
|
||||
(i32.const 1))
|
||||
|
||||
;; Call $g at 1
|
||||
(assert_return
|
||||
(invoke "call" (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 1))
|
||||
(i32.const 1))
|
||||
|
||||
;; Call $h at 2
|
||||
(assert_return
|
||||
(invoke "call" (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 2))
|
||||
(i32.const 1))
|
||||
|
||||
;; Do a `table.copy` to rearrange the elements. Copy from 4..7 to 0..3.
|
||||
(invoke "copy" (i32.const 0) (i32.const 4) (i32.const 3))
|
||||
|
||||
;; Call $g at 0
|
||||
(assert_return
|
||||
(invoke "call" (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 0))
|
||||
(i32.const 1))
|
||||
|
||||
;; Call $h at 1
|
||||
(assert_return
|
||||
(invoke "call" (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 1))
|
||||
(i32.const 1))
|
||||
|
||||
;; Call $f at 2
|
||||
(assert_return
|
||||
(invoke "call" (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 2))
|
||||
(i32.const 1))
|
||||
|
||||
;; Copying up to the end does not trap.
|
||||
(invoke "copy" (i32.const 7) (i32.const 0) (i32.const 2))
|
||||
|
||||
;; Copying past the end traps.
|
||||
(assert_trap
|
||||
(invoke "copy" (i32.const 7) (i32.const 0) (i32.const 3))
|
||||
"undefined element")
|
||||
165
tests/misc_testsuite/table_copy_on_imported_tables.wast
Normal file
165
tests/misc_testsuite/table_copy_on_imported_tables.wast
Normal file
@@ -0,0 +1,165 @@
|
||||
(module $m
|
||||
(func $f (param i32 i32 i32 i32 i32 i32) (result i32) (local.get 0))
|
||||
(func $g (param i32 i32 i32 i32 i32 i32) (result i32) (local.get 1))
|
||||
(func $h (param i32 i32 i32 i32 i32 i32) (result i32) (local.get 2))
|
||||
|
||||
(table $t (export "t") funcref (elem $f $g $h $f $g $h)))
|
||||
|
||||
(register "m" $m)
|
||||
|
||||
(module $n
|
||||
(table $t (import "m" "t") 6 funcref)
|
||||
|
||||
(func $i (param i32 i32 i32 i32 i32 i32) (result i32) (local.get 3))
|
||||
(func $j (param i32 i32 i32 i32 i32 i32) (result i32) (local.get 4))
|
||||
(func $k (param i32 i32 i32 i32 i32 i32) (result i32) (local.get 5))
|
||||
|
||||
(table $u (export "u") funcref (elem $i $j $k $i $j $k))
|
||||
|
||||
(func (export "copy_into_t_from_u") (param i32 i32 i32)
|
||||
local.get 0
|
||||
local.get 1
|
||||
local.get 2
|
||||
table.copy $t $u)
|
||||
|
||||
(func (export "copy_into_u_from_t") (param i32 i32 i32)
|
||||
local.get 0
|
||||
local.get 1
|
||||
local.get 2
|
||||
table.copy $u $t)
|
||||
|
||||
(func (export "call_t") (param i32 i32 i32 i32 i32 i32 i32) (result i32)
|
||||
local.get 0
|
||||
local.get 1
|
||||
local.get 2
|
||||
local.get 3
|
||||
local.get 4
|
||||
local.get 5
|
||||
local.get 6
|
||||
call_indirect $t (param i32 i32 i32 i32 i32 i32) (result i32))
|
||||
|
||||
(func (export "call_u") (param i32 i32 i32 i32 i32 i32 i32) (result i32)
|
||||
local.get 0
|
||||
local.get 1
|
||||
local.get 2
|
||||
local.get 3
|
||||
local.get 4
|
||||
local.get 5
|
||||
local.get 6
|
||||
call_indirect $u (param i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
|
||||
;; Everything has what we initially expect.
|
||||
(assert_return
|
||||
(invoke "call_t" (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0)
|
||||
(i32.const 0))
|
||||
(i32.const 1))
|
||||
(assert_return
|
||||
(invoke "call_t" (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0)
|
||||
(i32.const 1))
|
||||
(i32.const 1))
|
||||
(assert_return
|
||||
(invoke "call_t" (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 0)
|
||||
(i32.const 2))
|
||||
(i32.const 1))
|
||||
(assert_return
|
||||
(invoke "call_u" (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 0)
|
||||
(i32.const 0))
|
||||
(i32.const 1))
|
||||
(assert_return
|
||||
(invoke "call_u" (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 0)
|
||||
(i32.const 1))
|
||||
(i32.const 1))
|
||||
(assert_return
|
||||
(invoke "call_u" (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 1)
|
||||
(i32.const 2))
|
||||
(i32.const 1))
|
||||
|
||||
;; Now test copying between a local and an imported table.
|
||||
|
||||
;; Copy $i $j $k into $t at 3..6 from $u at 0..3.
|
||||
(invoke "copy_into_t_from_u" (i32.const 3) (i32.const 0) (i32.const 3))
|
||||
|
||||
(assert_return
|
||||
(invoke "call_t" (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 0)
|
||||
(i32.const 3))
|
||||
(i32.const 1))
|
||||
(assert_return
|
||||
(invoke "call_t" (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 0)
|
||||
(i32.const 4))
|
||||
(i32.const 1))
|
||||
(assert_return
|
||||
(invoke "call_t" (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 1)
|
||||
(i32.const 5))
|
||||
(i32.const 1))
|
||||
|
||||
;; Copy $f $g $h into $u at 0..3 from $t at 0..3.
|
||||
(invoke "copy_into_u_from_t" (i32.const 0) (i32.const 0) (i32.const 3))
|
||||
|
||||
(assert_return
|
||||
(invoke "call_u" (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0)
|
||||
(i32.const 0))
|
||||
(i32.const 1))
|
||||
(assert_return
|
||||
(invoke "call_u" (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0)
|
||||
(i32.const 1))
|
||||
(i32.const 1))
|
||||
(assert_return
|
||||
(invoke "call_u" (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 0)
|
||||
(i32.const 2))
|
||||
(i32.const 1))
|
||||
|
||||
(register "n" $n)
|
||||
|
||||
(module $o
|
||||
(table $t (import "m" "t") 6 funcref)
|
||||
(table $u (import "n" "u") 6 funcref)
|
||||
|
||||
(func (export "copy_into_t_from_u_2") (param i32 i32 i32)
|
||||
local.get 0
|
||||
local.get 1
|
||||
local.get 2
|
||||
table.copy $t $u)
|
||||
|
||||
(func (export "copy_into_u_from_t_2") (param i32 i32 i32)
|
||||
local.get 0
|
||||
local.get 1
|
||||
local.get 2
|
||||
table.copy $u $t)
|
||||
|
||||
(func (export "call_t_2") (param i32 i32 i32 i32 i32 i32 i32) (result i32)
|
||||
local.get 0
|
||||
local.get 1
|
||||
local.get 2
|
||||
local.get 3
|
||||
local.get 4
|
||||
local.get 5
|
||||
local.get 6
|
||||
call_indirect $t (param i32 i32 i32 i32 i32 i32) (result i32))
|
||||
|
||||
(func (export "call_u_2") (param i32 i32 i32 i32 i32 i32 i32) (result i32)
|
||||
local.get 0
|
||||
local.get 1
|
||||
local.get 2
|
||||
local.get 3
|
||||
local.get 4
|
||||
local.get 5
|
||||
local.get 6
|
||||
call_indirect $u (param i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
|
||||
;; Now test copying between two imported tables.
|
||||
|
||||
;; Copy $i into $t at 0 from $u at 3.
|
||||
(invoke "copy_into_t_from_u_2" (i32.const 0) (i32.const 3) (i32.const 1))
|
||||
|
||||
(assert_return
|
||||
(invoke "call_t_2" (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 0)
|
||||
(i32.const 0))
|
||||
(i32.const 1))
|
||||
|
||||
;; Copy $g into $u at 4 from $t at 1.
|
||||
(invoke "copy_into_u_from_t_2" (i32.const 4) (i32.const 1) (i32.const 1))
|
||||
|
||||
(assert_return
|
||||
(invoke "call_u_2" (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0)
|
||||
(i32.const 4))
|
||||
(i32.const 1))
|
||||
Reference in New Issue
Block a user