wa-lang.org/wazero@v1.0.2/internal/integration_test/spectest/v1/testdata/switch.wast (about) 1 (module 2 ;; Statement switch 3 (func (export "stmt") (param $i i32) (result i32) 4 (local $j i32) 5 (local.set $j (i32.const 100)) 6 (block $switch 7 (block $7 8 (block $default 9 (block $6 10 (block $5 11 (block $4 12 (block $3 13 (block $2 14 (block $1 15 (block $0 16 (br_table $0 $1 $2 $3 $4 $5 $6 $7 $default 17 (local.get $i) 18 ) 19 ) ;; 0 20 (return (local.get $i)) 21 ) ;; 1 22 (nop) 23 ;; fallthrough 24 ) ;; 2 25 ;; fallthrough 26 ) ;; 3 27 (local.set $j (i32.sub (i32.const 0) (local.get $i))) 28 (br $switch) 29 ) ;; 4 30 (br $switch) 31 ) ;; 5 32 (local.set $j (i32.const 101)) 33 (br $switch) 34 ) ;; 6 35 (local.set $j (i32.const 101)) 36 ;; fallthrough 37 ) ;; default 38 (local.set $j (i32.const 102)) 39 ) ;; 7 40 ;; fallthrough 41 ) 42 (return (local.get $j)) 43 ) 44 45 ;; Expression switch 46 (func (export "expr") (param $i i64) (result i64) 47 (local $j i64) 48 (local.set $j (i64.const 100)) 49 (return 50 (block $switch (result i64) 51 (block $7 52 (block $default 53 (block $4 54 (block $5 55 (block $6 56 (block $3 57 (block $2 58 (block $1 59 (block $0 60 (br_table $0 $1 $2 $3 $4 $5 $6 $7 $default 61 (i32.wrap_i64 (local.get $i)) 62 ) 63 ) ;; 0 64 (return (local.get $i)) 65 ) ;; 1 66 (nop) 67 ;; fallthrough 68 ) ;; 2 69 ;; fallthrough 70 ) ;; 3 71 (br $switch (i64.sub (i64.const 0) (local.get $i))) 72 ) ;; 6 73 (local.set $j (i64.const 101)) 74 ;; fallthrough 75 ) ;; 4 76 ;; fallthrough 77 ) ;; 5 78 ;; fallthrough 79 ) ;; default 80 (br $switch (local.get $j)) 81 ) ;; 7 82 (i64.const -5) 83 ) 84 ) 85 ) 86 87 ;; Argument switch 88 (func (export "arg") (param $i i32) (result i32) 89 (return 90 (block $2 (result i32) 91 (i32.add (i32.const 10) 92 (block $1 (result i32) 93 (i32.add (i32.const 100) 94 (block $0 (result i32) 95 (i32.add (i32.const 1000) 96 (block $default (result i32) 97 (br_table $0 $1 $2 $default 98 (i32.mul (i32.const 2) (local.get $i)) 99 (i32.and (i32.const 3) (local.get $i)) 100 ) 101 ) 102 ) 103 ) 104 ) 105 ) 106 ) 107 ) 108 ) 109 ) 110 111 ;; Corner cases 112 (func (export "corner") (result i32) 113 (block 114 (br_table 0 (i32.const 0)) 115 ) 116 (i32.const 1) 117 ) 118 ) 119 120 (assert_return (invoke "stmt" (i32.const 0)) (i32.const 0)) 121 (assert_return (invoke "stmt" (i32.const 1)) (i32.const -1)) 122 (assert_return (invoke "stmt" (i32.const 2)) (i32.const -2)) 123 (assert_return (invoke "stmt" (i32.const 3)) (i32.const -3)) 124 (assert_return (invoke "stmt" (i32.const 4)) (i32.const 100)) 125 (assert_return (invoke "stmt" (i32.const 5)) (i32.const 101)) 126 (assert_return (invoke "stmt" (i32.const 6)) (i32.const 102)) 127 (assert_return (invoke "stmt" (i32.const 7)) (i32.const 100)) 128 (assert_return (invoke "stmt" (i32.const -10)) (i32.const 102)) 129 130 (assert_return (invoke "expr" (i64.const 0)) (i64.const 0)) 131 (assert_return (invoke "expr" (i64.const 1)) (i64.const -1)) 132 (assert_return (invoke "expr" (i64.const 2)) (i64.const -2)) 133 (assert_return (invoke "expr" (i64.const 3)) (i64.const -3)) 134 (assert_return (invoke "expr" (i64.const 6)) (i64.const 101)) 135 (assert_return (invoke "expr" (i64.const 7)) (i64.const -5)) 136 (assert_return (invoke "expr" (i64.const -10)) (i64.const 100)) 137 138 (assert_return (invoke "arg" (i32.const 0)) (i32.const 110)) 139 (assert_return (invoke "arg" (i32.const 1)) (i32.const 12)) 140 (assert_return (invoke "arg" (i32.const 2)) (i32.const 4)) 141 (assert_return (invoke "arg" (i32.const 3)) (i32.const 1116)) 142 (assert_return (invoke "arg" (i32.const 4)) (i32.const 118)) 143 (assert_return (invoke "arg" (i32.const 5)) (i32.const 20)) 144 (assert_return (invoke "arg" (i32.const 6)) (i32.const 12)) 145 (assert_return (invoke "arg" (i32.const 7)) (i32.const 1124)) 146 (assert_return (invoke "arg" (i32.const 8)) (i32.const 126)) 147 148 (assert_return (invoke "corner") (i32.const 1)) 149 150 (assert_invalid (module (func (br_table 3 (i32.const 0)))) "unknown label")