Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
| 6 | 6 |
| 7 function assertWasm(expected, func, ffi) { | |
| 8 print("Testing " + func.name + "..."); | |
| 9 assertEquals(expected, Wasm.instantiateModuleFromAsm( | |
| 10 func.toString(), ffi).caller()); | |
| 11 } | |
| 12 | |
| 7 function EmptyTest() { | 13 function EmptyTest() { |
| 8 "use asm"; | 14 "use asm"; |
| 9 function caller() { | 15 function caller() { |
| 10 empty(); | 16 empty(); |
| 11 return 11; | 17 return 11; |
| 12 } | 18 } |
| 13 function empty() { | 19 function empty() { |
| 14 } | 20 } |
| 15 return {caller: caller}; | 21 return {caller: caller}; |
| 16 } | 22 } |
| 17 | 23 |
| 18 assertEquals(11, Wasm.instantiateModuleFromAsm( | 24 assertWasm(11, EmptyTest); |
| 19 EmptyTest.toString()).caller()); | |
| 20 | 25 |
| 21 | 26 |
| 27 function PosIntLiteralTest() { | |
|
bradnelson
2016/03/23 19:14:25
Can we wrap this in a closure like the ones at the
titzer
2016/03/23 19:53:05
I ended up moving this all together into a differe
| |
| 28 "use asm"; | |
| 29 function f0() { return 0; } | |
| 30 function f1() { return 1; } | |
| 31 function f4() { return 4; } | |
| 32 function f64() { return 64; } | |
| 33 function f128() { return 128; } | |
| 34 function f256() { return 256; } | |
| 35 function f1000() { return 1000; } | |
| 36 function f2000000() { return 2000000; } | |
| 37 function fmax() { return 2147483647; } | |
| 38 return {f0: f0, f1: f1, f4: f4, f64: f64, f128: f128, f256: f256, f1000: f1000 , f2000000, fmax: fmax}; | |
|
bradnelson
2016/03/23 19:14:25
wrap
| |
| 39 } | |
| 40 | |
| 41 var module = Wasm.instantiateModuleFromAsm( | |
| 42 PosIntLiteralTest.toString()); | |
| 43 | |
| 22 function IntTest() { | 44 function IntTest() { |
| 23 "use asm"; | 45 "use asm"; |
| 24 function sum(a, b) { | 46 function sum(a, b) { |
| 25 a = a|0; | 47 a = a|0; |
| 26 b = b|0; | 48 b = b|0; |
| 27 var c = (b + 1)|0 | 49 var c = (b + 1)|0 |
| 28 var d = 3.0; | 50 var d = 3.0; |
| 29 var e = ~~d; // double conversion | 51 var e = ~~d; // double conversion |
| 30 return (a + c + 1)|0; | 52 return (a + c + 1)|0; |
| 31 } | 53 } |
| 32 | 54 |
| 33 function caller() { | 55 function caller() { |
| 34 return sum(77,22) | 0; | 56 return sum(77,22) | 0; |
| 35 } | 57 } |
| 36 | 58 |
| 37 return {caller: caller}; | 59 return {caller: caller}; |
| 38 } | 60 } |
| 39 | 61 |
| 40 assertEquals(101, Wasm.instantiateModuleFromAsm( | 62 assertWasm(101,IntTest); |
| 41 IntTest.toString()).caller()); | |
| 42 | 63 |
| 43 | 64 |
| 44 function Float64Test() { | 65 function Float64Test() { |
| 45 "use asm"; | 66 "use asm"; |
| 46 function sum(a, b) { | 67 function sum(a, b) { |
| 47 a = +a; | 68 a = +a; |
| 48 b = +b; | 69 b = +b; |
| 49 return +(a + b); | 70 return +(a + b); |
| 50 } | 71 } |
| 51 | 72 |
| 52 function caller() { | 73 function caller() { |
| 53 var a = +sum(70.1,10.2); | 74 var a = +sum(70.1,10.2); |
| 54 var ret = 0|0; | 75 var ret = 0|0; |
| 55 if (a == 80.3) { | 76 if (a == 80.3) { |
| 56 ret = 1|0; | 77 ret = 1|0; |
| 57 } else { | 78 } else { |
| 58 ret = 0|0; | 79 ret = 0|0; |
| 59 } | 80 } |
| 60 return ret|0; | 81 return ret|0; |
| 61 } | 82 } |
| 62 | 83 |
| 63 return {caller: caller}; | 84 return {caller: caller}; |
| 64 } | 85 } |
| 65 | 86 |
| 66 assertEquals(1, Wasm.instantiateModuleFromAsm( | 87 assertWasm(1, Float64Test); |
| 67 Float64Test.toString()).caller()); | |
| 68 | 88 |
| 69 | 89 |
| 70 function BadModule() { | 90 function BadModule() { |
| 71 "use asm"; | 91 "use asm"; |
| 72 function caller(a, b) { | 92 function caller(a, b) { |
| 73 a = a|0; | 93 a = a|0; |
| 74 b = b+0; | 94 b = b+0; |
| 75 var c = (b + 1)|0 | 95 var c = (b + 1)|0 |
| 76 return (a + c + 1)|0; | 96 return (a + c + 1)|0; |
| 77 } | 97 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 98 return 1; | 118 return 1; |
| 99 } | 119 } |
| 100 } | 120 } |
| 101 } | 121 } |
| 102 return 0; | 122 return 0; |
| 103 } | 123 } |
| 104 | 124 |
| 105 return {caller: caller}; | 125 return {caller: caller}; |
| 106 } | 126 } |
| 107 | 127 |
| 108 assertEquals(1, Wasm.instantiateModuleFromAsm( | 128 assertWasm(1, TestReturnInBlock); |
| 109 TestReturnInBlock.toString()).caller()); | 129 |
| 130 | |
| 131 function TestAddSimple() { | |
| 132 "use asm"; | |
| 133 | |
| 134 function caller() { | |
| 135 var x = 0; | |
| 136 x = (x + 1)|0; | |
| 137 return x|0; | |
| 138 } | |
| 139 | |
| 140 return {caller: caller}; | |
| 141 } | |
| 142 | |
| 143 assertWasm(1, TestAddSimple); | |
| 110 | 144 |
| 111 | 145 |
| 112 function TestWhileSimple() { | 146 function TestWhileSimple() { |
| 113 "use asm"; | 147 "use asm"; |
| 114 | 148 |
| 115 function caller() { | 149 function caller() { |
| 116 var x = 0; | 150 var x = 0; |
| 117 while(x < 5) { | 151 while(x < 5) { |
| 118 x = (x + 1)|0; | 152 x = (x + 1)|0; |
| 119 } | 153 } |
| 120 return x|0; | 154 return x|0; |
| 121 } | 155 } |
| 122 | 156 |
| 123 return {caller: caller}; | 157 return {caller: caller}; |
| 124 } | 158 } |
| 125 | 159 |
| 126 assertEquals(5, Wasm.instantiateModuleFromAsm( | 160 assertWasm(5, TestWhileSimple); |
| 127 TestWhileSimple.toString()).caller()); | |
| 128 | 161 |
| 129 | 162 |
| 130 function TestWhileWithoutBraces() { | 163 function TestWhileWithoutBraces() { |
| 131 "use asm"; | 164 "use asm"; |
| 132 | 165 |
| 133 function caller() { | 166 function caller() { |
| 134 var x = 0; | 167 var x = 0; |
| 135 while(x <= 3) | 168 while(x <= 3) |
| 136 x = (x + 1)|0; | 169 x = (x + 1)|0; |
| 137 return x|0; | 170 return x|0; |
| 138 } | 171 } |
| 139 | 172 |
| 140 return {caller: caller}; | 173 return {caller: caller}; |
| 141 } | 174 } |
| 142 | 175 |
| 143 assertEquals(4, Wasm.instantiateModuleFromAsm( | 176 assertWasm(4, TestWhileWithoutBraces); |
| 144 TestWhileWithoutBraces.toString()).caller()); | |
| 145 | 177 |
| 146 | 178 |
| 147 function TestReturnInWhile() { | 179 function TestReturnInWhile() { |
| 148 "use asm"; | 180 "use asm"; |
| 149 | 181 |
| 150 function caller() { | 182 function caller() { |
| 151 var x = 0; | 183 var x = 0; |
| 152 while(x < 10) { | 184 while(x < 10) { |
| 153 x = (x + 6)|0; | 185 x = (x + 6)|0; |
| 154 return x|0; | 186 return x|0; |
| 155 } | 187 } |
| 156 return x|0; | 188 return x|0; |
| 157 } | 189 } |
| 158 | 190 |
| 159 return {caller: caller}; | 191 return {caller: caller}; |
| 160 } | 192 } |
| 161 | 193 |
| 162 assertEquals(6, Wasm.instantiateModuleFromAsm( | 194 assertWasm(6, TestReturnInWhile); |
| 163 TestReturnInWhile.toString()).caller()); | |
| 164 | 195 |
| 165 | 196 |
| 166 function TestReturnInWhileWithoutBraces() { | 197 function TestReturnInWhileWithoutBraces() { |
| 167 "use asm"; | 198 "use asm"; |
| 168 | 199 |
| 169 function caller() { | 200 function caller() { |
| 170 var x = 0; | 201 var x = 0; |
| 171 while(x < 5) | 202 while(x < 5) |
| 172 return 7; | 203 return 7; |
| 173 return x|0; | 204 return x|0; |
| 174 } | 205 } |
| 175 | 206 |
| 176 return {caller: caller}; | 207 return {caller: caller}; |
| 177 } | 208 } |
| 178 | 209 |
| 179 assertEquals( | 210 assertWasm(7, TestReturnInWhileWithoutBraces); |
| 180 7, Wasm.instantiateModuleFromAsm( | |
| 181 TestReturnInWhileWithoutBraces.toString()).caller()); | |
| 182 | 211 |
| 183 | 212 |
| 184 function TestBreakInWhile() { | 213 function TestBreakInWhile() { |
| 185 "use asm"; | 214 "use asm"; |
| 186 | 215 |
| 187 function caller() { | 216 function caller() { |
| 188 while(1) { | 217 while(1) { |
| 189 break; | 218 break; |
| 190 } | 219 } |
| 191 return 8; | 220 return 8; |
| 192 } | 221 } |
| 193 | 222 |
| 194 return {caller: caller}; | 223 return {caller: caller}; |
| 195 } | 224 } |
| 196 | 225 |
| 197 assertEquals(8, Wasm.instantiateModuleFromAsm( | 226 assertWasm(8, TestBreakInWhile); |
| 198 TestBreakInWhile.toString()).caller()); | |
| 199 | 227 |
| 200 | 228 |
| 201 function TestBreakInNestedWhile() { | 229 function TestBreakInNestedWhile() { |
| 202 "use asm"; | 230 "use asm"; |
| 203 | 231 |
| 204 function caller() { | 232 function caller() { |
| 205 var x = 1.0; | 233 var x = 1.0; |
| 206 while(x < 1.5) { | 234 while(x < 1.5) { |
| 207 while(1) | 235 while(1) |
| 208 break; | 236 break; |
| 209 x = +(x + 0.25); | 237 x = +(x + 0.25); |
| 210 } | 238 } |
| 211 var ret = 0; | 239 var ret = 0; |
| 212 if (x == 1.5) { | 240 if (x == 1.5) { |
| 213 ret = 9; | 241 ret = 9; |
| 214 } | 242 } |
| 215 return ret|0; | 243 return ret|0; |
| 216 } | 244 } |
| 217 | 245 |
| 218 return {caller: caller}; | 246 return {caller: caller}; |
| 219 } | 247 } |
| 220 | 248 |
| 221 assertEquals(9, Wasm.instantiateModuleFromAsm( | 249 assertWasm(9, TestBreakInNestedWhile); |
| 222 TestBreakInNestedWhile.toString()).caller()); | |
| 223 | 250 |
| 224 | 251 |
| 225 function TestBreakInBlock() { | 252 function TestBreakInBlock() { |
| 226 "use asm"; | 253 "use asm"; |
| 227 | 254 |
| 228 function caller() { | 255 function caller() { |
| 229 var x = 0; | 256 var x = 0; |
| 230 abc: { | 257 abc: { |
| 231 x = 10; | 258 x = 10; |
| 232 if (x == 10) { | 259 if (x == 10) { |
| 233 break abc; | 260 break abc; |
| 234 } | 261 } |
| 235 x = 20; | 262 x = 20; |
| 236 } | 263 } |
| 237 return x|0; | 264 return x|0; |
| 238 } | 265 } |
| 239 | 266 |
| 240 return {caller: caller}; | 267 return {caller: caller}; |
| 241 } | 268 } |
| 242 | 269 |
| 243 assertEquals(10, Wasm.instantiateModuleFromAsm( | 270 assertWasm(10, TestBreakInBlock); |
| 244 TestBreakInBlock.toString()).caller()); | |
| 245 | 271 |
| 246 | 272 |
| 247 function TestBreakInNamedWhile() { | 273 function TestBreakInNamedWhile() { |
| 248 "use asm"; | 274 "use asm"; |
| 249 | 275 |
| 250 function caller() { | 276 function caller() { |
| 251 var x = 0; | 277 var x = 0; |
| 252 outer: while (1) { | 278 outer: while (1) { |
| 253 x = (x + 1)|0; | 279 x = (x + 1)|0; |
| 254 while (x == 11) { | 280 while (x == 11) { |
| 255 break outer; | 281 break outer; |
| 256 } | 282 } |
| 257 } | 283 } |
| 258 return x|0; | 284 return x|0; |
| 259 } | 285 } |
| 260 | 286 |
| 261 return {caller: caller}; | 287 return {caller: caller}; |
| 262 } | 288 } |
| 263 | 289 |
| 264 assertEquals(11, Wasm.instantiateModuleFromAsm( | 290 assertWasm(11, TestBreakInNamedWhile); |
| 265 TestBreakInNamedWhile.toString()).caller()); | |
| 266 | 291 |
| 267 | 292 |
| 268 function TestContinue() { | 293 function TestContinue() { |
| 269 "use asm"; | 294 "use asm"; |
| 270 | 295 |
| 271 function caller() { | 296 function caller() { |
| 272 var x = 5; | 297 var x = 5; |
| 273 var ret = 0; | 298 var ret = 0; |
| 274 while (x >= 0) { | 299 while (x >= 0) { |
| 275 x = (x - 1)|0; | 300 x = (x - 1)|0; |
| 276 if (x == 2) { | 301 if (x == 2) { |
| 277 continue; | 302 continue; |
| 278 } | 303 } |
| 279 ret = (ret - 1)|0; | 304 ret = (ret - 1)|0; |
| 280 } | 305 } |
| 281 return ret|0; | 306 return ret|0; |
| 282 } | 307 } |
| 283 | 308 |
| 284 return {caller: caller}; | 309 return {caller: caller}; |
| 285 } | 310 } |
| 286 | 311 |
| 287 assertEquals(-5, Wasm.instantiateModuleFromAsm( | 312 assertWasm(-5, TestContinue); |
| 288 TestContinue.toString()).caller()); | |
| 289 | 313 |
| 290 | 314 |
| 291 function TestContinueInNamedWhile() { | 315 function TestContinueInNamedWhile() { |
| 292 "use asm"; | 316 "use asm"; |
| 293 | 317 |
| 294 function caller() { | 318 function caller() { |
| 295 var x = 5; | 319 var x = 5; |
| 296 var y = 0; | 320 var y = 0; |
| 297 var ret = 0; | 321 var ret = 0; |
| 298 outer: while (x > 0) { | 322 outer: while (x > 0) { |
| 299 x = (x - 1)|0; | 323 x = (x - 1)|0; |
| 300 y = 0; | 324 y = 0; |
| 301 while (y < 5) { | 325 while (y < 5) { |
| 302 if (x == 3) { | 326 if (x == 3) { |
| 303 continue outer; | 327 continue outer; |
| 304 } | 328 } |
| 305 ret = (ret + 1)|0; | 329 ret = (ret + 1)|0; |
| 306 y = (y + 1)|0; | 330 y = (y + 1)|0; |
| 307 } | 331 } |
| 308 } | 332 } |
| 309 return ret|0; | 333 return ret|0; |
| 310 } | 334 } |
| 311 | 335 |
| 312 return {caller: caller}; | 336 return {caller: caller}; |
| 313 } | 337 } |
| 314 | 338 |
| 315 assertEquals(20, Wasm.instantiateModuleFromAsm( | 339 assertWasm(20, TestContinueInNamedWhile); |
| 316 TestContinueInNamedWhile.toString()).caller()); | |
| 317 | 340 |
| 318 | 341 |
| 319 function TestNot() { | 342 function TestNot() { |
| 320 "use asm"; | 343 "use asm"; |
| 321 | 344 |
| 322 function caller() { | 345 function caller() { |
| 323 var a = !(2 > 3); | 346 var a = !(2 > 3); |
| 324 return a | 0; | 347 return a | 0; |
| 325 } | 348 } |
| 326 | 349 |
| 327 return {caller:caller}; | 350 return {caller:caller}; |
| 328 } | 351 } |
| 329 | 352 |
| 330 assertEquals(1, Wasm.instantiateModuleFromAsm( | 353 assertWasm(1, TestNot); |
| 331 TestNot.toString()).caller()); | |
| 332 | 354 |
| 333 | 355 |
| 334 function TestNotEquals() { | 356 function TestNotEquals() { |
| 335 "use asm"; | 357 "use asm"; |
| 336 | 358 |
| 337 function caller() { | 359 function caller() { |
| 338 var a = 3; | 360 var a = 3; |
| 339 if (a != 2) { | 361 if (a != 2) { |
| 340 return 21; | 362 return 21; |
| 341 } | 363 } |
| 342 return 0; | 364 return 0; |
| 343 } | 365 } |
| 344 | 366 |
| 345 return {caller:caller}; | 367 return {caller:caller}; |
| 346 } | 368 } |
| 347 | 369 |
| 348 assertEquals(21, Wasm.instantiateModuleFromAsm( | 370 assertWasm(21, TestNotEquals); |
| 349 TestNotEquals.toString()).caller()); | |
| 350 | 371 |
| 351 | 372 |
| 352 function TestUnsignedComparison() { | 373 function TestUnsignedComparison() { |
| 353 "use asm"; | 374 "use asm"; |
| 354 | 375 |
| 355 function caller() { | 376 function caller() { |
| 356 var a = 0xffffffff; | 377 var a = 0xffffffff; |
| 357 if ((a>>>0) > (0>>>0)) { | 378 if ((a>>>0) > (0>>>0)) { |
| 358 return 22; | 379 return 22; |
| 359 } | 380 } |
| 360 return 0; | 381 return 0; |
| 361 } | 382 } |
| 362 | 383 |
| 363 return {caller:caller}; | 384 return {caller:caller}; |
| 364 } | 385 } |
| 365 | 386 |
| 366 assertEquals(22, Wasm.instantiateModuleFromAsm( | 387 assertWasm(22, TestUnsignedComparison); |
| 367 TestUnsignedComparison.toString()).caller()); | |
| 368 | 388 |
| 369 | 389 |
| 370 function TestMixedAdd() { | 390 function TestMixedAdd() { |
| 371 "use asm"; | 391 "use asm"; |
| 372 | 392 |
| 373 function caller() { | 393 function caller() { |
| 374 var a = 0x80000000; | 394 var a = 0x80000000; |
| 375 var b = 0x7fffffff; | 395 var b = 0x7fffffff; |
| 376 var c = 0; | 396 var c = 0; |
| 377 c = ((a>>>0) + b)|0; | 397 c = ((a>>>0) + b)|0; |
| 378 if ((c >>> 0) > (0>>>0)) { | 398 if ((c >>> 0) > (0>>>0)) { |
| 379 if (c < 0) { | 399 if (c < 0) { |
| 380 return 23; | 400 return 23; |
| 381 } | 401 } |
| 382 } | 402 } |
| 383 return 0; | 403 return 0; |
| 384 } | 404 } |
| 385 | 405 |
| 386 return {caller:caller}; | 406 return {caller:caller}; |
| 387 } | 407 } |
| 388 | 408 |
| 389 assertEquals(23, Wasm.instantiateModuleFromAsm( | 409 assertWasm(23, TestMixedAdd); |
| 390 TestMixedAdd.toString()).caller()); | |
| 391 | 410 |
| 392 | 411 |
| 393 function TestInt32HeapAccess(stdlib, foreign, buffer) { | 412 function TestInt32HeapAccess(stdlib, foreign, buffer) { |
| 394 "use asm"; | 413 "use asm"; |
| 395 | 414 |
| 396 var m = new stdlib.Int32Array(buffer); | 415 var m = new stdlib.Int32Array(buffer); |
| 397 function caller() { | 416 function caller() { |
| 398 var i = 4; | 417 var i = 4; |
| 399 | 418 |
| 400 m[0] = (i + 1) | 0; | 419 m[0] = (i + 1) | 0; |
| 401 m[i >> 2] = ((m[0]|0) + 1) | 0; | 420 m[i >> 2] = ((m[0]|0) + 1) | 0; |
| 402 m[2] = ((m[i >> 2]|0) + 1) | 0; | 421 m[2] = ((m[i >> 2]|0) + 1) | 0; |
| 403 return m[2] | 0; | 422 return m[2] | 0; |
| 404 } | 423 } |
| 405 | 424 |
| 406 return {caller: caller}; | 425 return {caller: caller}; |
| 407 } | 426 } |
| 408 | 427 |
| 409 assertEquals(7, Wasm.instantiateModuleFromAsm( | 428 assertWasm(7, TestInt32HeapAccess); |
| 410 TestInt32HeapAccess.toString()).caller()); | |
| 411 | 429 |
| 412 | 430 |
| 413 function TestInt32HeapAccessExternal() { | 431 function TestInt32HeapAccessExternal() { |
| 414 var memory = new ArrayBuffer(1024); | 432 var memory = new ArrayBuffer(1024); |
| 415 var memory_int32 = new Int32Array(memory); | 433 var memory_int32 = new Int32Array(memory); |
| 416 var module = Wasm.instantiateModuleFromAsm( | 434 var module = Wasm.instantiateModuleFromAsm( |
| 417 TestInt32HeapAccess.toString(), null, memory); | 435 TestInt32HeapAccess.toString(), null, memory); |
| 418 assertEquals(7, module.caller()); | 436 assertEquals(7, module.caller()); |
| 419 assertEquals(7, memory_int32[2]); | 437 assertEquals(7, memory_int32[2]); |
| 420 } | 438 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 var a = 1.5; | 510 var a = 1.5; |
| 493 if ((~~(a + a)) == 3) { | 511 if ((~~(a + a)) == 3) { |
| 494 return 24; | 512 return 24; |
| 495 } | 513 } |
| 496 return 0; | 514 return 0; |
| 497 } | 515 } |
| 498 | 516 |
| 499 return {caller:caller}; | 517 return {caller:caller}; |
| 500 } | 518 } |
| 501 | 519 |
| 502 assertEquals(24, Wasm.instantiateModuleFromAsm( | 520 assertWasm(24, TestConvertI32); |
| 503 TestConvertI32.toString()).caller()); | |
| 504 | 521 |
| 505 | 522 |
| 506 function TestConvertF64FromInt() { | 523 function TestConvertF64FromInt() { |
| 507 "use asm"; | 524 "use asm"; |
| 508 | 525 |
| 509 function caller() { | 526 function caller() { |
| 510 var a = 1; | 527 var a = 1; |
| 511 if ((+(a + a)) > 1.5) { | 528 if ((+(a + a)) > 1.5) { |
| 512 return 25; | 529 return 25; |
| 513 } | 530 } |
| 514 return 0; | 531 return 0; |
| 515 } | 532 } |
| 516 | 533 |
| 517 return {caller:caller}; | 534 return {caller:caller}; |
| 518 } | 535 } |
| 519 | 536 |
| 520 assertEquals(25, Wasm.instantiateModuleFromAsm( | 537 assertWasm(25, TestConvertF64FromInt); |
| 521 TestConvertF64FromInt.toString()).caller()); | |
| 522 | 538 |
| 523 | 539 |
| 524 function TestConvertF64FromUnsigned() { | 540 function TestConvertF64FromUnsigned() { |
| 525 "use asm"; | 541 "use asm"; |
| 526 | 542 |
| 527 function caller() { | 543 function caller() { |
| 528 var a = 0xffffffff; | 544 var a = 0xffffffff; |
| 529 if ((+(a>>>0)) > 0.0) { | 545 if ((+(a>>>0)) > 0.0) { |
| 530 if((+a) < 0.0) { | 546 if((+a) < 0.0) { |
| 531 return 26; | 547 return 26; |
| 532 } | 548 } |
| 533 } | 549 } |
| 534 return 0; | 550 return 0; |
| 535 } | 551 } |
| 536 | 552 |
| 537 return {caller:caller}; | 553 return {caller:caller}; |
| 538 } | 554 } |
| 539 | 555 |
| 540 assertEquals(26, Wasm.instantiateModuleFromAsm( | 556 assertWasm(26, TestConvertF64FromUnsigned); |
| 541 TestConvertF64FromUnsigned.toString()).caller()); | |
| 542 | 557 |
| 543 | 558 |
| 544 function TestModInt() { | 559 function TestModInt() { |
| 545 "use asm"; | 560 "use asm"; |
| 546 | 561 |
| 547 function caller() { | 562 function caller() { |
| 548 var a = -83; | 563 var a = -83; |
| 549 var b = 28; | 564 var b = 28; |
| 550 return ((a|0)%(b|0))|0; | 565 return ((a|0)%(b|0))|0; |
| 551 } | 566 } |
| 552 | 567 |
| 553 return {caller:caller}; | 568 return {caller:caller}; |
| 554 } | 569 } |
| 555 | 570 |
| 556 assertEquals(-27, Wasm.instantiateModuleFromAsm( | 571 assertWasm(-27,TestModInt); |
| 557 TestModInt.toString()).caller()); | |
| 558 | 572 |
| 559 | 573 |
| 560 function TestModUnsignedInt() { | 574 function TestModUnsignedInt() { |
| 561 "use asm"; | 575 "use asm"; |
| 562 | 576 |
| 563 function caller() { | 577 function caller() { |
| 564 var a = 0x80000000; //2147483648 | 578 var a = 0x80000000; //2147483648 |
| 565 var b = 10; | 579 var b = 10; |
| 566 return ((a>>>0)%(b>>>0))|0; | 580 return ((a>>>0)%(b>>>0))|0; |
| 567 } | 581 } |
| 568 | 582 |
| 569 return {caller:caller}; | 583 return {caller:caller}; |
| 570 } | 584 } |
| 571 | 585 |
| 572 assertEquals(8, Wasm.instantiateModuleFromAsm( | 586 assertWasm(8, TestModUnsignedInt); |
| 573 TestModUnsignedInt.toString()).caller()); | |
| 574 | 587 |
| 575 | 588 |
| 576 function TestModDouble() { | 589 function TestModDouble() { |
| 577 "use asm"; | 590 "use asm"; |
| 578 | 591 |
| 579 function caller() { | 592 function caller() { |
| 580 var a = 5.25; | 593 var a = 5.25; |
| 581 var b = 2.5; | 594 var b = 2.5; |
| 582 if (a%b == 0.25) { | 595 if (a%b == 0.25) { |
| 583 return 28; | 596 return 28; |
| 584 } | 597 } |
| 585 return 0; | 598 return 0; |
| 586 } | 599 } |
| 587 | 600 |
| 588 return {caller:caller}; | 601 return {caller:caller}; |
| 589 } | 602 } |
| 590 | 603 |
| 591 assertEquals(28, Wasm.instantiateModuleFromAsm( | 604 assertWasm(28, TestModDouble); |
| 592 TestModDouble.toString()).caller()); | |
| 593 | 605 |
| 594 | 606 |
| 595 /* | 607 /* |
| 596 TODO: Fix parsing of negative doubles | 608 TODO: Fix parsing of negative doubles |
| 597 Fix code to use trunc instead of casts | 609 Fix code to use trunc instead of casts |
| 598 function TestModDoubleNegative() { | 610 function TestModDoubleNegative() { |
| 599 "use asm"; | 611 "use asm"; |
| 600 | 612 |
| 601 function caller() { | 613 function caller() { |
| 602 var a = -34359738368.25; | 614 var a = -34359738368.25; |
| 603 var b = 2.5; | 615 var b = 2.5; |
| 604 if (a%b == -0.75) { | 616 if (a%b == -0.75) { |
| 605 return 28; | 617 return 28; |
| 606 } | 618 } |
| 607 return 0; | 619 return 0; |
| 608 } | 620 } |
| 609 | 621 |
| 610 return {caller:caller}; | 622 return {caller:caller}; |
| 611 } | 623 } |
| 612 | 624 |
| 613 assertEquals(28, Wasm.instantiateModuleFromAsm( | 625 assertWasm(28, TestModDoubleNegative); |
| 614 TestModDoubleNegative.toString()).caller()); | |
| 615 */ | 626 */ |
| 616 | 627 |
| 617 | 628 |
| 618 function TestNamedFunctions() { | 629 function TestNamedFunctions() { |
| 619 "use asm"; | 630 "use asm"; |
| 620 | 631 |
| 621 var a = 0.0; | 632 var a = 0.0; |
| 622 var b = 0.0; | 633 var b = 0.0; |
| 623 | 634 |
| 624 function add() { | 635 function add() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 var i = 0; | 675 var i = 0; |
| 665 for (i = 2; i <= 10; i = (i+1)|0) { | 676 for (i = 2; i <= 10; i = (i+1)|0) { |
| 666 ret = (ret + i) | 0; | 677 ret = (ret + i) | 0; |
| 667 } | 678 } |
| 668 return ret|0; | 679 return ret|0; |
| 669 } | 680 } |
| 670 | 681 |
| 671 return {caller:caller}; | 682 return {caller:caller}; |
| 672 } | 683 } |
| 673 | 684 |
| 674 assertEquals(54, Wasm.instantiateModuleFromAsm( | 685 assertWasm(54, TestForLoop); |
| 675 TestForLoop.toString()).caller()); | |
| 676 | 686 |
| 677 | 687 |
| 678 function TestForLoopWithoutInit() { | 688 function TestForLoopWithoutInit() { |
| 679 "use asm" | 689 "use asm" |
| 680 | 690 |
| 681 function caller() { | 691 function caller() { |
| 682 var ret = 0; | 692 var ret = 0; |
| 683 var i = 0; | 693 var i = 0; |
| 684 for (; i < 10; i = (i+1)|0) { | 694 for (; i < 10; i = (i+1)|0) { |
| 685 ret = (ret + 10) | 0; | 695 ret = (ret + 10) | 0; |
| 686 } | 696 } |
| 687 return ret|0; | 697 return ret|0; |
| 688 } | 698 } |
| 689 | 699 |
| 690 return {caller:caller}; | 700 return {caller:caller}; |
| 691 } | 701 } |
| 692 | 702 |
| 693 assertEquals(100, Wasm.instantiateModuleFromAsm( | 703 assertWasm(100,TestForLoopWithoutInit); |
| 694 TestForLoopWithoutInit.toString()).caller()); | |
| 695 | 704 |
| 696 | 705 |
| 697 function TestForLoopWithoutCondition() { | 706 function TestForLoopWithoutCondition() { |
| 698 "use asm" | 707 "use asm" |
| 699 | 708 |
| 700 function caller() { | 709 function caller() { |
| 701 var ret = 0; | 710 var ret = 0; |
| 702 var i = 0; | 711 var i = 0; |
| 703 for (i=1;; i = (i+1)|0) { | 712 for (i=1;; i = (i+1)|0) { |
| 704 ret = (ret + i) | 0; | 713 ret = (ret + i) | 0; |
| 705 if (i == 11) { | 714 if (i == 11) { |
| 706 break; | 715 break; |
| 707 } | 716 } |
| 708 } | 717 } |
| 709 return ret|0; | 718 return ret|0; |
| 710 } | 719 } |
| 711 | 720 |
| 712 return {caller:caller}; | 721 return {caller:caller}; |
| 713 } | 722 } |
| 714 | 723 |
| 715 assertEquals(66, Wasm.instantiateModuleFromAsm( | 724 assertWasm(66, TestForLoopWithoutCondition); |
| 716 TestForLoopWithoutCondition.toString()).caller()); | |
| 717 | 725 |
| 718 | 726 |
| 719 function TestForLoopWithoutNext() { | 727 function TestForLoopWithoutNext() { |
| 720 "use asm" | 728 "use asm" |
| 721 | 729 |
| 722 function caller() { | 730 function caller() { |
| 723 var i = 0; | 731 var i = 0; |
| 724 for (i=1; i < 41;) { | 732 for (i=1; i < 41;) { |
| 725 i = (i + 1) | 0; | 733 i = (i + 1) | 0; |
| 726 } | 734 } |
| 727 return i|0; | 735 return i|0; |
| 728 } | 736 } |
| 729 | 737 |
| 730 return {caller:caller}; | 738 return {caller:caller}; |
| 731 } | 739 } |
| 732 | 740 |
| 733 assertEquals(41, Wasm.instantiateModuleFromAsm( | 741 assertWasm(41, TestForLoopWithoutNext); |
| 734 TestForLoopWithoutNext.toString()).caller()); | |
| 735 | 742 |
| 736 | 743 |
| 737 function TestForLoopWithoutBody() { | 744 function TestForLoopWithoutBody() { |
| 738 "use asm" | 745 "use asm" |
| 739 | 746 |
| 740 function caller() { | 747 function caller() { |
| 741 var i = 0; | 748 var i = 0; |
| 742 for (i=1; i < 45 ; i = (i+1)|0) { | 749 for (i=1; i < 45 ; i = (i+1)|0) { |
| 743 } | 750 } |
| 744 return i|0; | 751 return i|0; |
| 745 } | 752 } |
| 746 | 753 |
| 747 return {caller:caller}; | 754 return {caller:caller}; |
| 748 } | 755 } |
| 749 | 756 |
| 750 assertEquals(45, Wasm.instantiateModuleFromAsm( | 757 assertWasm(45, TestForLoopWithoutBody); |
| 751 TestForLoopWithoutBody.toString()).caller()); | |
| 752 | 758 |
| 753 | 759 |
| 754 function TestDoWhile() { | 760 function TestDoWhile() { |
| 755 "use asm" | 761 "use asm" |
| 756 | 762 |
| 757 function caller() { | 763 function caller() { |
| 758 var i = 0; | 764 var i = 0; |
| 759 var ret = 21; | 765 var ret = 21; |
| 760 do { | 766 do { |
| 761 ret = (ret + ret)|0; | 767 ret = (ret + ret)|0; |
| 762 i = (i + 1)|0; | 768 i = (i + 1)|0; |
| 763 } while (i < 2); | 769 } while (i < 2); |
| 764 return ret|0; | 770 return ret|0; |
| 765 } | 771 } |
| 766 | 772 |
| 767 return {caller:caller}; | 773 return {caller:caller}; |
| 768 } | 774 } |
| 769 | 775 |
| 770 assertEquals(84, Wasm.instantiateModuleFromAsm( | 776 assertWasm(84, TestDoWhile); |
| 771 TestDoWhile.toString()).caller()); | |
| 772 | 777 |
| 773 | 778 |
| 774 function TestConditional() { | 779 function TestConditional() { |
| 775 "use asm" | 780 "use asm" |
| 776 | 781 |
| 777 function caller() { | 782 function caller() { |
| 778 var x = 1; | 783 var x = 1; |
| 779 return ((x > 0) ? 41 : 71)|0; | 784 return ((x > 0) ? 41 : 71)|0; |
| 780 } | 785 } |
| 781 | 786 |
| 782 return {caller:caller}; | 787 return {caller:caller}; |
| 783 } | 788 } |
| 784 | 789 |
| 785 assertEquals(41, Wasm.instantiateModuleFromAsm( | 790 assertWasm(41, TestConditional); |
| 786 TestConditional.toString()).caller()); | |
| 787 | 791 |
| 788 | 792 |
| 789 function TestSwitch() { | 793 function TestSwitch() { |
| 790 "use asm" | 794 "use asm" |
| 791 | 795 |
| 792 function caller() { | 796 function caller() { |
| 793 var ret = 0; | 797 var ret = 0; |
| 794 var x = 7; | 798 var x = 7; |
| 795 switch (x) { | 799 switch (x) { |
| 796 case 1: return 0; | 800 case 1: return 0; |
| 797 case 7: { | 801 case 7: { |
| 798 ret = 12; | 802 ret = 12; |
| 799 break; | 803 break; |
| 800 } | 804 } |
| 801 default: return 0; | 805 default: return 0; |
| 802 } | 806 } |
| 803 switch (x) { | 807 switch (x) { |
| 804 case 1: return 0; | 808 case 1: return 0; |
| 805 case 8: return 0; | 809 case 8: return 0; |
| 806 default: ret = (ret + 11)|0; | 810 default: ret = (ret + 11)|0; |
| 807 } | 811 } |
| 808 return ret|0; | 812 return ret|0; |
| 809 } | 813 } |
| 810 | 814 |
| 811 return {caller:caller}; | 815 return {caller:caller}; |
| 812 } | 816 } |
| 813 | 817 |
| 814 assertEquals(23, Wasm.instantiateModuleFromAsm( | 818 assertWasm(23, TestSwitch); |
| 815 TestSwitch.toString()).caller()); | |
| 816 | 819 |
| 817 | 820 |
| 818 function TestSwitchFallthrough() { | 821 function TestSwitchFallthrough() { |
| 819 "use asm" | 822 "use asm" |
| 820 | 823 |
| 821 function caller() { | 824 function caller() { |
| 822 var x = 17; | 825 var x = 17; |
| 823 var ret = 0; | 826 var ret = 0; |
| 824 switch (x) { | 827 switch (x) { |
| 825 case 17: | 828 case 17: |
| 826 case 14: ret = 39; | 829 case 14: ret = 39; |
| 827 case 1: ret = (ret + 3)|0; | 830 case 1: ret = (ret + 3)|0; |
| 828 case 4: break; | 831 case 4: break; |
| 829 default: ret = (ret + 1)|0; | 832 default: ret = (ret + 1)|0; |
| 830 } | 833 } |
| 831 return ret|0; | 834 return ret|0; |
| 832 } | 835 } |
| 833 | 836 |
| 834 return {caller:caller}; | 837 return {caller:caller}; |
| 835 } | 838 } |
| 836 | 839 |
| 837 assertEquals(42, Wasm.instantiateModuleFromAsm( | 840 assertWasm(42, TestSwitchFallthrough); |
| 838 TestSwitchFallthrough.toString()).caller()); | |
| 839 | 841 |
| 840 | 842 |
| 841 function TestNestedSwitch() { | 843 function TestNestedSwitch() { |
| 842 "use asm" | 844 "use asm" |
| 843 | 845 |
| 844 function caller() { | 846 function caller() { |
| 845 var x = 3; | 847 var x = 3; |
| 846 var y = -13; | 848 var y = -13; |
| 847 switch (x) { | 849 switch (x) { |
| 848 case 1: return 0; | 850 case 1: return 0; |
| 849 case 3: { | 851 case 3: { |
| 850 switch (y) { | 852 switch (y) { |
| 851 case 2: return 0; | 853 case 2: return 0; |
| 852 case -13: return 43; | 854 case -13: return 43; |
| 853 default: return 0; | 855 default: return 0; |
| 854 } | 856 } |
| 855 } | 857 } |
| 856 default: return 0; | 858 default: return 0; |
| 857 } | 859 } |
| 858 return 0; | 860 return 0; |
| 859 } | 861 } |
| 860 | 862 |
| 861 return {caller:caller}; | 863 return {caller:caller}; |
| 862 } | 864 } |
| 863 | 865 |
| 864 assertEquals(43, Wasm.instantiateModuleFromAsm( | 866 assertWasm(43, TestNestedSwitch); |
| 865 TestNestedSwitch.toString()).caller()); | |
| 866 | 867 |
| 867 | 868 |
| 868 function TestInitFunctionWithNoGlobals() { | 869 function TestInitFunctionWithNoGlobals() { |
| 869 "use asm"; | 870 "use asm"; |
| 870 function caller() { | 871 function caller() { |
| 871 return 51; | 872 return 51; |
| 872 } | 873 } |
| 873 return {caller}; | 874 return {caller}; |
| 874 } | 875 } |
| 875 | 876 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 900 | 901 |
| 901 function caller() { | 902 function caller() { |
| 902 return function_table[0&0]() | 0; | 903 return function_table[0&0]() | 0; |
| 903 } | 904 } |
| 904 | 905 |
| 905 var function_table = [dummy] | 906 var function_table = [dummy] |
| 906 | 907 |
| 907 return {caller:caller}; | 908 return {caller:caller}; |
| 908 } | 909 } |
| 909 | 910 |
| 910 assertEquals(71, Wasm.instantiateModuleFromAsm( | 911 assertWasm(71, TestFunctionTableSingleFunction); |
| 911 TestFunctionTableSingleFunction.toString()).caller()); | |
| 912 | 912 |
| 913 | 913 |
| 914 function TestFunctionTableMultipleFunctions() { | 914 function TestFunctionTableMultipleFunctions() { |
| 915 "use asm"; | 915 "use asm"; |
| 916 | 916 |
| 917 function inc1(x) { | 917 function inc1(x) { |
| 918 x = x|0; | 918 x = x|0; |
| 919 return (x+1)|0; | 919 return (x+1)|0; |
| 920 } | 920 } |
| 921 | 921 |
| 922 function inc2(x) { | 922 function inc2(x) { |
| 923 x = x|0; | 923 x = x|0; |
| 924 return (x+2)|0; | 924 return (x+2)|0; |
| 925 } | 925 } |
| 926 | 926 |
| 927 function caller() { | 927 function caller() { |
| 928 if (function_table[0&1](50) == 51) { | 928 if (function_table[0&1](50) == 51) { |
| 929 if (function_table[1&1](60) == 62) { | 929 if (function_table[1&1](60) == 62) { |
| 930 return 73; | 930 return 73; |
| 931 } | 931 } |
| 932 } | 932 } |
| 933 return 0; | 933 return 0; |
| 934 } | 934 } |
| 935 | 935 |
| 936 var function_table = [inc1, inc2] | 936 var function_table = [inc1, inc2] |
| 937 | 937 |
| 938 return {caller:caller}; | 938 return {caller:caller}; |
| 939 } | 939 } |
| 940 | 940 |
| 941 assertEquals(73, Wasm.instantiateModuleFromAsm( | 941 assertWasm(73, TestFunctionTableMultipleFunctions); |
| 942 TestFunctionTableMultipleFunctions.toString()).caller()); | |
| 943 | 942 |
| 944 | 943 |
| 945 function TestFunctionTable() { | 944 function TestFunctionTable() { |
| 946 "use asm"; | 945 "use asm"; |
| 947 | 946 |
| 948 function add(a, b) { | 947 function add(a, b) { |
| 949 a = a|0; | 948 a = a|0; |
| 950 b = b|0; | 949 b = b|0; |
| 951 return (a+b)|0; | 950 return (a+b)|0; |
| 952 } | 951 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1096 } | 1095 } |
| 1097 | 1096 |
| 1098 function getf2() { | 1097 function getf2() { |
| 1099 return +f2; | 1098 return +f2; |
| 1100 } | 1099 } |
| 1101 | 1100 |
| 1102 return {geti1:geti1, getf1:getf1, geti2:geti2, getf2:getf2}; | 1101 return {geti1:geti1, getf1:getf1, geti2:geti2, getf2:getf2}; |
| 1103 } | 1102 } |
| 1104 | 1103 |
| 1105 function TestCase(env, i1, f1, i2, f2) { | 1104 function TestCase(env, i1, f1, i2, f2) { |
| 1105 print("Testing foreign variables..."); | |
|
bradnelson
2016/03/23 19:14:25
You mean to leave this in?
titzer
2016/03/23 19:53:05
I crashed here a couple times and it was useful to
| |
| 1106 var module = Wasm.instantiateModuleFromAsm( | 1106 var module = Wasm.instantiateModuleFromAsm( |
| 1107 AsmModule.toString(), env); | 1107 AsmModule.toString(), env); |
| 1108 assertEquals(i1, module.geti1()); | 1108 assertEquals(i1, module.geti1()); |
| 1109 assertEquals(f1, module.getf1()); | 1109 assertEquals(f1, module.getf1()); |
| 1110 assertEquals(i2, module.geti2()); | 1110 assertEquals(i2, module.geti2()); |
| 1111 assertEquals(f2, module.getf2()); | 1111 assertEquals(f2, module.getf2()); |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 // Check normal operation. | 1114 // Check normal operation. |
| 1115 TestCase({foo: 123, bar: 234.5, baz: 345.7}, 123, 234.5, 345, 345.7); | 1115 TestCase({foo: 123, bar: 234.5, baz: 345.7}, 123, 234.5, 345, 345.7); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1205 m.storeb(22, 77); | 1205 m.storeb(22, 77); |
| 1206 assertEquals(123, m.load(20)); | 1206 assertEquals(123, m.load(20)); |
| 1207 assertEquals(42, m.load(21)); | 1207 assertEquals(42, m.load(21)); |
| 1208 assertEquals(77, m.load(22)); | 1208 assertEquals(77, m.load(22)); |
| 1209 assertEquals(123, m.iload(0)); | 1209 assertEquals(123, m.iload(0)); |
| 1210 assertEquals(42, m.iload(4)); | 1210 assertEquals(42, m.iload(4)); |
| 1211 assertEquals(77, m.iload(8)); | 1211 assertEquals(77, m.iload(8)); |
| 1212 })(); | 1212 })(); |
| 1213 | 1213 |
| 1214 | 1214 |
| 1215 (function TestGlobalBlock() { | 1215 function TestGlobalBlock(stdlib, foreign, buffer) { |
| 1216 function Module(stdlib, foreign, buffer) { | 1216 "use asm"; |
| 1217 "use asm"; | |
| 1218 | 1217 |
| 1219 var x = foreign.x | 0, y = foreign.y | 0; | 1218 var x = foreign.x | 0, y = foreign.y | 0; |
| 1220 | 1219 |
| 1221 function test() { | 1220 function test() { |
| 1222 return (x + y) | 0; | 1221 return (x + y) | 0; |
| 1223 } | |
| 1224 | |
| 1225 return {test: test}; | |
| 1226 } | 1222 } |
| 1227 | 1223 |
| 1228 var m = Wasm.instantiateModuleFromAsm( | 1224 return {caller: test}; |
| 1229 Module.toString(), { x: 4, y: 11 }); | 1225 } |
| 1230 assertEquals(15, m.test()); | |
| 1231 })(); | |
| 1232 | 1226 |
| 1227 assertWasm(15, TestGlobalBlock, { x: 4, y: 11 }); | |
| 1233 | 1228 |
| 1234 (function TestComma() { | 1229 (function TestComma() { |
| 1235 function CommaModule() { | 1230 function CommaModule() { |
| 1236 "use asm"; | 1231 "use asm"; |
| 1237 | 1232 |
| 1238 function ifunc(a, b) { | 1233 function ifunc(a, b) { |
| 1239 a = +a; | 1234 a = +a; |
| 1240 b = b | 0; | 1235 b = b | 0; |
| 1241 return (a, b) | 0; | 1236 return (a, b) | 0; |
| 1242 } | 1237 } |
| 1243 | 1238 |
| 1244 function dfunc(a, b) { | 1239 function dfunc(a, b) { |
| 1245 a = a | 0; | 1240 a = a | 0; |
| 1246 b = +b; | 1241 b = +b; |
| 1247 return +(a, b); | 1242 return +(a, b); |
| 1248 } | 1243 } |
| 1249 | 1244 |
| 1250 return {ifunc: ifunc, dfunc: dfunc}; | 1245 return {ifunc: ifunc, dfunc: dfunc}; |
| 1251 } | 1246 } |
| 1252 | 1247 |
| 1253 var m = Wasm.instantiateModuleFromAsm(CommaModule.toString()); | 1248 var m = Wasm.instantiateModuleFromAsm(CommaModule.toString()); |
| 1254 assertEquals(123, m.ifunc(456.7, 123)); | 1249 assertEquals(123, m.ifunc(456.7, 123)); |
| 1255 assertEquals(123.4, m.dfunc(456, 123.4)); | 1250 assertEquals(123.4, m.dfunc(456, 123.4)); |
| 1256 })(); | 1251 })(); |
| 1257 | 1252 |
| 1258 | 1253 |
| 1259 (function TestFloatAsDouble() { | 1254 function TestFloatAsDouble(stdlib) { |
| 1260 function Module(stdlib) { | 1255 "use asm"; |
| 1261 "use asm"; | 1256 var fround = stdlib.Math.fround; |
| 1262 var fround = stdlib.Math.fround; | 1257 function func() { |
| 1263 function func() { | 1258 var x = fround(1.0); |
| 1264 var x = fround(1.0); | 1259 return +fround(x); |
| 1265 return +fround(x); | |
| 1266 } | |
| 1267 return {func:func}; | |
| 1268 } | 1260 } |
| 1269 var m = Wasm.instantiateModuleFromAsm(Module.toString()); | 1261 return {caller: func}; |
| 1270 assertEquals(1, m.func()); | 1262 } |
| 1271 })(); | 1263 assertWasm(1, TestFloatAsDouble); |
| 1272 | 1264 |
| 1273 | 1265 |
| 1274 (function TestOr() { | 1266 function TestOr() { |
| 1275 function Module() { | 1267 "use asm"; |
| 1276 "use asm"; | 1268 function func() { |
| 1277 function func() { | 1269 var x = 1; |
| 1278 var x = 1; | 1270 var y = 2; |
| 1279 var y = 2; | 1271 return (x | y) | 0; |
| 1280 return (x | y) | 0; | |
| 1281 } | |
| 1282 return {func: func}; | |
| 1283 } | 1272 } |
| 1273 return {caller: func}; | |
| 1274 } | |
| 1284 | 1275 |
| 1285 var m = Wasm.instantiateModuleFromAsm(Module.toString()); | 1276 assertWasm(3, TestOr); |
| 1286 assertEquals(3, m.func()); | |
| 1287 })(); | |
| 1288 | 1277 |
| 1289 | 1278 |
| 1290 (function TestAnd() { | 1279 function TestAnd() { |
| 1291 function Module() { | 1280 "use asm"; |
| 1292 "use asm"; | 1281 function func() { |
| 1293 function func() { | 1282 var x = 3; |
| 1294 var x = 3; | 1283 var y = 2; |
| 1295 var y = 2; | 1284 return (x & y) | 0; |
| 1296 return (x & y) | 0; | |
| 1297 } | |
| 1298 return {func: func}; | |
| 1299 } | 1285 } |
| 1286 return {caller: func}; | |
| 1287 } | |
| 1300 | 1288 |
| 1301 var m = Wasm.instantiateModuleFromAsm(Module.toString()); | 1289 assertWasm(2, TestAnd); |
| 1302 assertEquals(2, m.func()); | |
| 1303 })(); | |
| 1304 | 1290 |
| 1305 | 1291 |
| 1306 (function TestXor() { | 1292 function TestXor() { |
| 1307 function Module() { | 1293 "use asm"; |
| 1308 "use asm"; | 1294 function func() { |
| 1309 function func() { | 1295 var x = 3; |
| 1310 var x = 3; | 1296 var y = 2; |
| 1311 var y = 2; | 1297 return (x ^ y) | 0; |
| 1312 return (x ^ y) | 0; | |
| 1313 } | |
| 1314 return {func: func}; | |
| 1315 } | 1298 } |
| 1299 return {caller: func}; | |
| 1300 } | |
| 1316 | 1301 |
| 1317 var m = Wasm.instantiateModuleFromAsm(Module.toString()); | 1302 assertWasm(1, TestXor); |
| 1318 assertEquals(1, m.func()); | |
| 1319 })(); | |
| 1320 | 1303 |
| 1321 | 1304 |
| 1322 (function TestIntishAssignment() { | 1305 (function TestIntishAssignment() { |
| 1323 function Module(stdlib, foreign, heap) { | 1306 function Module(stdlib, foreign, heap) { |
| 1324 "use asm"; | 1307 "use asm"; |
| 1325 var HEAP32 = new stdlib.Int32Array(heap); | 1308 var HEAP32 = new stdlib.Int32Array(heap); |
| 1326 function func() { | 1309 function func() { |
| 1327 var a = 1; | 1310 var a = 1; |
| 1328 var b = 2; | 1311 var b = 2; |
| 1329 HEAP32[0] = a + b; | 1312 HEAP32[0] = a + b; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1478 var a = 0; | 1461 var a = 0; |
| 1479 f = 5616315000.000001; | 1462 f = 5616315000.000001; |
| 1480 a = ~~f >>>0; | 1463 a = ~~f >>>0; |
| 1481 return a | 0; | 1464 return a | 0; |
| 1482 } | 1465 } |
| 1483 return { main : aaa }; | 1466 return { main : aaa }; |
| 1484 } | 1467 } |
| 1485 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); | 1468 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); |
| 1486 assertEquals(1321347704, wasm.main()); | 1469 assertEquals(1321347704, wasm.main()); |
| 1487 })(); | 1470 })(); |
| OLD | NEW |