Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional i31ref spec tests #534

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Changes from 1 commit
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
215 changes: 215 additions & 0 deletions test/core/gc/i31.wast
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@

(global $i (ref i31) (ref.i31 (i32.const 2)))
(global $m (mut (ref i31)) (ref.i31 (i32.const 3)))

(func (export "get_globals") (result i32 i32)
(i31.get_u (global.get $i))
(i31.get_u (global.get $m))
)

(func (export "set_global") (param i32)
local.get 0
ref.i31
global.set $m
)
)

(assert_return (invoke "new" (i32.const 1)) (ref.i31))
Expand All @@ -49,3 +56,211 @@
(assert_trap (invoke "get_s-null") "null i31 reference")

(assert_return (invoke "get_globals") (i32.const 2) (i32.const 3))

(invoke "set_global" (i32.const 1234))
(assert_return (invoke "get_globals") (i32.const 2) (i32.const 1234))

(module $tables_of_i31ref
(table $table 3 10 i31ref)
(elem (table $table) (i32.const 0) i31ref (item (ref.i31 (i32.const 999)))
(item (ref.i31 (i32.const 888)))
(item (ref.i31 (i32.const 777))))

(func (export "size") (result i32)
table.size $table
)

(func (export "get") (param i32) (result i32)
local.get 0
table.get $table
i31.get_u
)

(func (export "grow") (param i32 i32) (result i32)
(ref.i31 (local.get 1))
local.get 0
table.grow $table
)

(func (export "fill") (param i32 i32 i32)
local.get 0
(ref.i31 (local.get 1))
local.get 2
table.fill $table
)

(func (export "copy") (param i32 i32 i32)
local.get 0
local.get 1
local.get 2
table.copy $table $table
)

(elem $elem i31ref (item (ref.i31 (i32.const 123)))
(item (ref.i31 (i32.const 456)))
(item (ref.i31 (i32.const 789))))
(func (export "init") (param i32 i32 i32)
local.get 0
local.get 1
local.get 2
table.init $table $elem
)
)

;; Initial state.
(assert_return (invoke "size") (i32.const 3))
(assert_return (invoke "get" (i32.const 0)) (i32.const 999))
(assert_return (invoke "get" (i32.const 1)) (i32.const 888))
(assert_return (invoke "get" (i32.const 2)) (i32.const 777))

;; Grow from size 3 to size 5.
(assert_return (invoke "grow" (i32.const 2) (i32.const 333)) (i32.const 3))
(assert_return (invoke "size") (i32.const 5))
(assert_return (invoke "get" (i32.const 3)) (i32.const 333))
(assert_return (invoke "get" (i32.const 4)) (i32.const 333))

;; Fill table[2..4] = 111.
(invoke "fill" (i32.const 2) (i32.const 111) (i32.const 2))
(assert_return (invoke "get" (i32.const 2)) (i32.const 111))
(assert_return (invoke "get" (i32.const 3)) (i32.const 111))

;; Copy from table[0..2] to table[3..5].
(invoke "copy" (i32.const 3) (i32.const 0) (i32.const 2))
(assert_return (invoke "get" (i32.const 3)) (i32.const 999))
(assert_return (invoke "get" (i32.const 4)) (i32.const 888))

;; Initialize the passive element at table[1..4].
(invoke "init" (i32.const 1) (i32.const 0) (i32.const 3))
(assert_return (invoke "get" (i32.const 1)) (i32.const 123))
(assert_return (invoke "get" (i32.const 2)) (i32.const 456))
(assert_return (invoke "get" (i32.const 3)) (i32.const 789))

(module $env
(global (export "g") i32 (i32.const 42))
)
(register "env")

(module $i31ref_of_global_table_initializer
(global $g (import "env" "g") i32)
(table $t 3 3 (ref i31) (ref.i31 (global.get $g)))
(func (export "get") (param i32) (result i32)
local.get 0
table.get $t
i31.get_u
)
)

(assert_return (invoke "get" (i32.const 0)) (i32.const 42))
(assert_return (invoke "get" (i32.const 0)) (i32.const 42))
(assert_return (invoke "get" (i32.const 0)) (i32.const 42))

(module $i31ref_of_global_global_initializer
(global $g0 (import "env" "g") i32)
(global $g1 i31ref (ref.i31 (global.get $g0)))
(func (export "get") (result i32)
global.get $g1
i31.get_u
)
)

(assert_return (invoke "get") (i32.const 42))

(module $anyref_global_of_i31ref
(global $c anyref (ref.i31 (i32.const 1234)))
(global $m (mut anyref) (ref.i31 (i32.const 5678)))

(func (export "get_globals") (result i32 i32)
global.get $c
ref.cast i31ref
i31.get_u
global.get $m
ref.cast i31ref
i31.get_u
)

(func (export "set_global") (param i32)
local.get 0
ref.i31
global.set $m
)
)

(assert_return (invoke "get_globals") (i32.const 1234) (i32.const 5678))
(invoke "set_global" (i32.const 0))
(assert_return (invoke "get_globals") (i32.const 1234) (i32.const 0))

(module $anyref_table_of_i31ref
(table $table 3 10 anyref)
(elem (table $table) (i32.const 0) i31ref (item (ref.i31 (i32.const 999)))
(item (ref.i31 (i32.const 888)))
(item (ref.i31 (i32.const 777))))

(func (export "size") (result i32)
table.size $table
)

(func (export "get") (param i32) (result i32)
local.get 0
table.get $table
ref.cast i31ref
i31.get_u
)

(func (export "grow") (param i32 i32) (result i32)
(ref.i31 (local.get 1))
local.get 0
table.grow $table
)

(func (export "fill") (param i32 i32 i32)
local.get 0
(ref.i31 (local.get 1))
local.get 2
table.fill $table
)

(func (export "copy") (param i32 i32 i32)
local.get 0
local.get 1
local.get 2
table.copy $table $table
)

(elem $elem i31ref (item (ref.i31 (i32.const 123)))
(item (ref.i31 (i32.const 456)))
(item (ref.i31 (i32.const 789))))
(func (export "init") (param i32 i32 i32)
local.get 0
local.get 1
local.get 2
table.init $table $elem
)
)

;; Initial state.
(assert_return (invoke "size") (i32.const 3))
(assert_return (invoke "get" (i32.const 0)) (i32.const 999))
(assert_return (invoke "get" (i32.const 1)) (i32.const 888))
(assert_return (invoke "get" (i32.const 2)) (i32.const 777))

;; Grow from size 3 to size 5.
(assert_return (invoke "grow" (i32.const 2) (i32.const 333)) (i32.const 3))
(assert_return (invoke "size") (i32.const 5))
(assert_return (invoke "get" (i32.const 3)) (i32.const 333))
(assert_return (invoke "get" (i32.const 4)) (i32.const 333))

;; Fill table[2..4] = 111.
(invoke "fill" (i32.const 2) (i32.const 111) (i32.const 2))
(assert_return (invoke "get" (i32.const 2)) (i32.const 111))
(assert_return (invoke "get" (i32.const 3)) (i32.const 111))

;; Copy from table[0..2] to table[3..5].
(invoke "copy" (i32.const 3) (i32.const 0) (i32.const 2))
(assert_return (invoke "get" (i32.const 3)) (i32.const 999))
(assert_return (invoke "get" (i32.const 4)) (i32.const 888))

;; Initialize the passive element at table[1..4].
(invoke "init" (i32.const 1) (i32.const 0) (i32.const 3))
(assert_return (invoke "get" (i32.const 1)) (i32.const 123))
(assert_return (invoke "get" (i32.const 2)) (i32.const 456))
(assert_return (invoke "get" (i32.const 3)) (i32.const 789))
Loading