|
| 1 | +;;;; Expression-style element segments. |
| 2 | + |
| 3 | +(module |
| 4 | + (type $arr (array i31ref)) |
| 5 | + |
| 6 | + (elem $e i31ref |
| 7 | + (ref.i31 (i32.const 0xaa)) |
| 8 | + (ref.i31 (i32.const 0xbb)) |
| 9 | + (ref.i31 (i32.const 0xcc)) |
| 10 | + (ref.i31 (i32.const 0xdd))) |
| 11 | + |
| 12 | + (func (export "array-new-elem") (param i32 i32) (result (ref $arr)) |
| 13 | + (array.new_elem $arr $e (local.get 0) (local.get 1)) |
| 14 | + ) |
| 15 | +) |
| 16 | + |
| 17 | +;; In-bounds element segment accesses. |
| 18 | +(assert_return (invoke "array-new-elem" (i32.const 0) (i32.const 0)) (ref.array)) |
| 19 | +(assert_return (invoke "array-new-elem" (i32.const 0) (i32.const 4)) (ref.array)) |
| 20 | +(assert_return (invoke "array-new-elem" (i32.const 1) (i32.const 2)) (ref.array)) |
| 21 | +(assert_return (invoke "array-new-elem" (i32.const 4) (i32.const 0)) (ref.array)) |
| 22 | + |
| 23 | +;; Out-of-bounds element segment accesses. |
| 24 | +(assert_trap (invoke "array-new-elem" (i32.const 0) (i32.const 5)) "out of bounds table access") |
| 25 | +(assert_trap (invoke "array-new-elem" (i32.const 5) (i32.const 0)) "out of bounds table access") |
| 26 | +(assert_trap (invoke "array-new-elem" (i32.const 1) (i32.const 4)) "out of bounds table access") |
| 27 | +(assert_trap (invoke "array-new-elem" (i32.const 4) (i32.const 1)) "out of bounds table access") |
| 28 | + |
| 29 | +(module |
| 30 | + (type $arr (array i31ref)) |
| 31 | + |
| 32 | + (elem $e i31ref |
| 33 | + (ref.i31 (i32.const 0xaa)) |
| 34 | + (ref.i31 (i32.const 0xbb)) |
| 35 | + (ref.i31 (i32.const 0xcc)) |
| 36 | + (ref.i31 (i32.const 0xdd))) |
| 37 | + |
| 38 | + (func (export "array-new-elem-contents") (result i32 i32) |
| 39 | + (local (ref $arr)) |
| 40 | + (local.set 0 (array.new_elem $arr $e (i32.const 1) (i32.const 2))) |
| 41 | + (i31.get_u (array.get $arr (local.get 0) (i32.const 0))) |
| 42 | + (i31.get_u (array.get $arr (local.get 0) (i32.const 1))) |
| 43 | + ) |
| 44 | +) |
| 45 | + |
| 46 | +;; Array is initialized with the correct contents. |
| 47 | +(assert_return (invoke "array-new-elem-contents") (i32.const 0xbb) (i32.const 0xcc)) |
| 48 | + |
| 49 | +;;;; MVP-style function-index segments. |
| 50 | + |
| 51 | +(module |
| 52 | + (type $arr (array funcref)) |
| 53 | + |
| 54 | + (elem $e func $aa $bb $cc $dd) |
| 55 | + (func $aa (result i32) (i32.const 0xaa)) |
| 56 | + (func $bb (result i32) (i32.const 0xbb)) |
| 57 | + (func $cc (result i32) (i32.const 0xcc)) |
| 58 | + (func $dd (result i32) (i32.const 0xdd)) |
| 59 | + |
| 60 | + (func (export "array-new-elem") (param i32 i32) (result (ref $arr)) |
| 61 | + (array.new_elem $arr $e (local.get 0) (local.get 1)) |
| 62 | + ) |
| 63 | +) |
| 64 | + |
| 65 | +;; In-bounds element segment accesses. |
| 66 | +(assert_return (invoke "array-new-elem" (i32.const 0) (i32.const 0)) (ref.array)) |
| 67 | +(assert_return (invoke "array-new-elem" (i32.const 0) (i32.const 4)) (ref.array)) |
| 68 | +(assert_return (invoke "array-new-elem" (i32.const 1) (i32.const 2)) (ref.array)) |
| 69 | +(assert_return (invoke "array-new-elem" (i32.const 4) (i32.const 0)) (ref.array)) |
| 70 | + |
| 71 | +;; Out-of-bounds element segment accesses. |
| 72 | +(assert_trap (invoke "array-new-elem" (i32.const 0) (i32.const 5)) "out of bounds table access") |
| 73 | +(assert_trap (invoke "array-new-elem" (i32.const 5) (i32.const 0)) "out of bounds table access") |
| 74 | +(assert_trap (invoke "array-new-elem" (i32.const 1) (i32.const 4)) "out of bounds table access") |
| 75 | +(assert_trap (invoke "array-new-elem" (i32.const 4) (i32.const 1)) "out of bounds table access") |
| 76 | + |
| 77 | +(module |
| 78 | + (type $f (func (result i32))) |
| 79 | + (type $arr (array funcref)) |
| 80 | + |
| 81 | + (elem $e func $aa $bb $cc $dd) |
| 82 | + (func $aa (result i32) (i32.const 0xaa)) |
| 83 | + (func $bb (result i32) (i32.const 0xbb)) |
| 84 | + (func $cc (result i32) (i32.const 0xcc)) |
| 85 | + (func $dd (result i32) (i32.const 0xdd)) |
| 86 | + |
| 87 | + (table $t 2 2 funcref) |
| 88 | + |
| 89 | + (func (export "array-new-elem-contents") (result i32 i32) |
| 90 | + (local (ref $arr)) |
| 91 | + (local.set 0 (array.new_elem $arr $e (i32.const 1) (i32.const 2))) |
| 92 | + |
| 93 | + (table.set $t (i32.const 0) (array.get $arr (local.get 0) (i32.const 0))) |
| 94 | + (table.set $t (i32.const 1) (array.get $arr (local.get 0) (i32.const 1))) |
| 95 | + |
| 96 | + (call_indirect (type $f) (i32.const 0)) |
| 97 | + (call_indirect (type $f) (i32.const 1)) |
| 98 | + |
| 99 | + ) |
| 100 | +) |
| 101 | + |
| 102 | +;; Array is initialized with the correct contents. |
| 103 | +(assert_return (invoke "array-new-elem-contents") (i32.const 0xbb) (i32.const 0xcc)) |
0 commit comments