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