wa-lang.org/wazero@v1.0.2/internal/integration_test/spectest/v2/testdata/stack.wast (about) 1 (module 2 (func (export "fac-expr") (param $n i64) (result i64) 3 (local $i i64) 4 (local $res i64) 5 (local.set $i (local.get $n)) 6 (local.set $res (i64.const 1)) 7 (block $done 8 (loop $loop 9 (if 10 (i64.eq (local.get $i) (i64.const 0)) 11 (then (br $done)) 12 (else 13 (local.set $res (i64.mul (local.get $i) (local.get $res))) 14 (local.set $i (i64.sub (local.get $i) (i64.const 1))) 15 ) 16 ) 17 (br $loop) 18 ) 19 ) 20 (local.get $res) 21 ) 22 23 (func (export "fac-stack") (param $n i64) (result i64) 24 (local $i i64) 25 (local $res i64) 26 (local.get $n) 27 (local.set $i) 28 (i64.const 1) 29 (local.set $res) 30 (block $done 31 (loop $loop 32 (local.get $i) 33 (i64.const 0) 34 (i64.eq) 35 (if 36 (then (br $done)) 37 (else 38 (local.get $i) 39 (local.get $res) 40 (i64.mul) 41 (local.set $res) 42 (local.get $i) 43 (i64.const 1) 44 (i64.sub) 45 (local.set $i) 46 ) 47 ) 48 (br $loop) 49 ) 50 ) 51 (local.get $res) 52 ) 53 54 (func (export "fac-stack-raw") (param $n i64) (result i64) 55 (local $i i64) 56 (local $res i64) 57 local.get $n 58 local.set $i 59 i64.const 1 60 local.set $res 61 block $done 62 loop $loop 63 local.get $i 64 i64.const 0 65 i64.eq 66 if $body 67 br $done 68 else $body 69 local.get $i 70 local.get $res 71 i64.mul 72 local.set $res 73 local.get $i 74 i64.const 1 75 i64.sub 76 local.set $i 77 end $body 78 br $loop 79 end $loop 80 end $done 81 local.get $res 82 ) 83 84 (func (export "fac-mixed") (param $n i64) (result i64) 85 (local $i i64) 86 (local $res i64) 87 (local.set $i (local.get $n)) 88 (local.set $res (i64.const 1)) 89 (block $done 90 (loop $loop 91 (i64.eq (local.get $i) (i64.const 0)) 92 (if 93 (then (br $done)) 94 (else 95 (i64.mul (local.get $i) (local.get $res)) 96 (local.set $res) 97 (i64.sub (local.get $i) (i64.const 1)) 98 (local.set $i) 99 ) 100 ) 101 (br $loop) 102 ) 103 ) 104 (local.get $res) 105 ) 106 107 (func (export "fac-mixed-raw") (param $n i64) (result i64) 108 (local $i i64) 109 (local $res i64) 110 (local.set $i (local.get $n)) 111 (local.set $res (i64.const 1)) 112 block $done 113 loop $loop 114 (i64.eq (local.get $i) (i64.const 0)) 115 if 116 br $done 117 else 118 (i64.mul (local.get $i) (local.get $res)) 119 local.set $res 120 (i64.sub (local.get $i) (i64.const 1)) 121 local.set $i 122 end 123 br $loop 124 end 125 end 126 local.get $res 127 ) 128 129 (global $temp (mut i32) (i32.const 0)) 130 (func $add_one_to_global (result i32) 131 (local i32) 132 (global.set $temp (i32.add (i32.const 1) (global.get $temp))) 133 (global.get $temp) 134 ) 135 (func $add_one_to_global_and_drop 136 (drop (call $add_one_to_global)) 137 ) 138 (func (export "not-quite-a-tree") (result i32) 139 call $add_one_to_global 140 call $add_one_to_global 141 call $add_one_to_global_and_drop 142 i32.add 143 ) 144 ) 145 146 (assert_return (invoke "fac-expr" (i64.const 25)) (i64.const 7034535277573963776)) 147 (assert_return (invoke "fac-stack" (i64.const 25)) (i64.const 7034535277573963776)) 148 (assert_return (invoke "fac-mixed" (i64.const 25)) (i64.const 7034535277573963776)) 149 150 (assert_return (invoke "not-quite-a-tree") (i32.const 3)) 151 (assert_return (invoke "not-quite-a-tree") (i32.const 9)) 152 153 154 ;; Syntax of flat call_indirect 155 156 (module 157 (type $proc (func)) 158 (table 1 funcref) 159 160 (func 161 (block i32.const 0 call_indirect) 162 (loop i32.const 0 call_indirect) 163 (if (i32.const 0) (then i32.const 0 call_indirect)) 164 (if (i32.const 0) 165 (then i32.const 0 call_indirect) 166 (else i32.const 0 call_indirect) 167 ) 168 (block i32.const 0 call_indirect (type $proc)) 169 (loop i32.const 0 call_indirect (type $proc)) 170 (if (i32.const 0) (then i32.const 0 call_indirect (type $proc))) 171 (if (i32.const 0) 172 (then i32.const 0 call_indirect (type $proc)) 173 (else i32.const 0 call_indirect (type $proc)) 174 ) 175 (block i32.const 0 i32.const 0 call_indirect (param i32)) 176 (loop i32.const 0 i32.const 0 call_indirect (param i32)) 177 (if (i32.const 0) (then i32.const 0 i32.const 0 call_indirect (param i32))) 178 (if (i32.const 0) 179 (then i32.const 0 i32.const 0 call_indirect (param i32)) 180 (else i32.const 0 i32.const 0 call_indirect (param i32)) 181 ) 182 (block (result i32) i32.const 0 call_indirect (result i32)) (drop) 183 (loop (result i32) i32.const 0 call_indirect (result i32)) (drop) 184 (if (result i32) (i32.const 0) 185 (then i32.const 0 call_indirect (result i32)) 186 (else i32.const 0 call_indirect (result i32)) 187 ) (drop) 188 (block i32.const 0 call_indirect (type $proc) (param) (result)) 189 (loop i32.const 0 call_indirect (type $proc) (param) (result)) 190 (if (i32.const 0) 191 (then i32.const 0 call_indirect (type $proc) (param) (result)) 192 ) 193 (if (i32.const 0) 194 (then i32.const 0 call_indirect (type $proc) (param) (param) (result)) 195 (else i32.const 0 call_indirect (type $proc) (param) (result) (result)) 196 ) 197 198 block i32.const 0 call_indirect end 199 loop i32.const 0 call_indirect end 200 i32.const 0 if i32.const 0 call_indirect end 201 i32.const 0 if i32.const 0 call_indirect else i32.const 0 call_indirect end 202 block i32.const 0 call_indirect (type $proc) end 203 loop i32.const 0 call_indirect (type $proc) end 204 i32.const 0 if i32.const 0 call_indirect (type $proc) end 205 i32.const 0 206 if 207 i32.const 0 call_indirect (type $proc) 208 else 209 i32.const 0 call_indirect (type $proc) 210 end 211 block i32.const 0 i32.const 0 call_indirect (param i32) end 212 loop i32.const 0 i32.const 0 call_indirect (param i32) end 213 i32.const 0 if i32.const 0 i32.const 0 call_indirect (param i32) end 214 i32.const 0 215 if 216 i32.const 0 i32.const 0 call_indirect (param i32) 217 else 218 i32.const 0 i32.const 0 call_indirect (param i32) 219 end 220 block (result i32) i32.const 0 call_indirect (result i32) end drop 221 loop (result i32) i32.const 0 call_indirect (result i32) end drop 222 i32.const 0 223 if (result i32) 224 i32.const 0 call_indirect (result i32) 225 else 226 i32.const 0 call_indirect (result i32) 227 end drop 228 block i32.const 0 call_indirect (type $proc) (param) (result) end 229 loop i32.const 0 call_indirect (type $proc) (param) (result) end 230 i32.const 0 if i32.const 0 call_indirect (type $proc) (param) (result) end 231 i32.const 0 232 if 233 i32.const 0 call_indirect (type $proc) (param) (result) 234 else 235 i32.const 0 call_indirect (type $proc) (param) (param) (result) (result) 236 end 237 i32.const 0 call_indirect 238 ) 239 )