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: --validate-asm --allow-natives-syntax | 5 // Flags: --validate-asm --allow-natives-syntax |
6 | 6 |
7 var stdlib = this; | 7 var stdlib = this; |
8 | 8 |
9 function assertValidAsm(func) { | 9 function assertValidAsm(func) { |
10 assertTrue(%IsAsmWasmCode(func)); | 10 assertTrue(%IsAsmWasmCode(func)); |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
981 } | 981 } |
982 return 0; | 982 return 0; |
983 } | 983 } |
984 | 984 |
985 var funBin = [add, sub, sub, add]; | 985 var funBin = [add, sub, sub, add]; |
986 var fun = [inc]; | 986 var fun = [inc]; |
987 | 987 |
988 return {caller:caller}; | 988 return {caller:caller}; |
989 } | 989 } |
990 | 990 |
991 print("TestFunctionTable..."); | |
991 var module = TestFunctionTable(stdlib); | 992 var module = TestFunctionTable(stdlib); |
992 assertEquals(55, module.caller(0, 0, 33, 22)); | 993 assertEquals(55, module.caller(0, 0, 33, 22)); |
993 assertEquals(11, module.caller(0, 1, 33, 22)); | 994 assertEquals(11, module.caller(0, 1, 33, 22)); |
994 assertEquals(9, module.caller(0, 2, 54, 45)); | 995 assertEquals(9, module.caller(0, 2, 54, 45)); |
995 assertEquals(99, module.caller(0, 3, 54, 45)); | 996 assertEquals(99, module.caller(0, 3, 54, 45)); |
996 assertEquals(23, module.caller(0, 4, 12, 11)); | 997 assertEquals(23, module.caller(0, 4, 12, 11)); |
997 assertEquals(31, module.caller(1, 0, 30, 11)); | 998 assertEquals(31, module.caller(1, 0, 30, 11)); |
998 })(); | 999 })(); |
999 | 1000 |
1000 | 1001 |
(...skipping 14 matching lines...) Expand all Loading... | |
1015 return 0; | 1016 return 0; |
1016 } | 1017 } |
1017 | 1018 |
1018 return {caller:caller}; | 1019 return {caller:caller}; |
1019 } | 1020 } |
1020 | 1021 |
1021 function ffi(initial_val) { | 1022 function ffi(initial_val) { |
1022 var val = initial_val; | 1023 var val = initial_val; |
1023 | 1024 |
1024 function getVal() { | 1025 function getVal() { |
1026 print("getVal"); | |
bradnelson
2016/09/23 11:36:01
Did you still want these two?
titzer
2016/09/23 12:07:31
Done.
| |
1025 return val; | 1027 return val; |
1026 } | 1028 } |
1027 | 1029 |
1028 function setVal(new_val) { | 1030 function setVal(new_val) { |
1031 print("setVal: " + new_val); | |
1029 val = new_val; | 1032 val = new_val; |
1030 } | 1033 } |
1031 | 1034 |
1032 return {getVal:getVal, setVal:setVal}; | 1035 return {getVal:getVal, setVal:setVal}; |
1033 } | 1036 } |
1034 | 1037 |
1035 var foreign = new ffi(23); | 1038 var foreign = new ffi(23); |
1036 | 1039 |
1037 var module = AsmModule({Math: Math}, foreign, null); | 1040 var module = AsmModule({Math: Math}, foreign, null); |
1038 assertValidAsm(AsmModule); | 1041 assertValidAsm(AsmModule); |
1039 | 1042 |
1040 assertEquals(103, module.caller(23, 103)); | 1043 assertEquals(103, module.caller(23, 103)); |
1041 } | 1044 } |
1042 | 1045 |
1046 print("TestForeignFunctions..."); | |
1043 TestForeignFunctions(); | 1047 TestForeignFunctions(); |
1044 | 1048 |
1045 | 1049 |
1046 function TestForeignFunctionMultipleUse() { | 1050 function TestForeignFunctionMultipleUse() { |
1047 function AsmModule(stdlib, foreign, buffer) { | 1051 function AsmModule(stdlib, foreign, buffer) { |
1048 "use asm"; | 1052 "use asm"; |
1049 | 1053 |
1050 var getVal = foreign.getVal; | 1054 var getVal = foreign.getVal; |
1051 | 1055 |
1052 function caller(int_val, double_val) { | 1056 function caller(int_val, double_val) { |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1587 "use asm"; | 1591 "use asm"; |
1588 function add(a, b) { | 1592 function add(a, b) { |
1589 a = a | 0; | 1593 a = a | 0; |
1590 b = b | 0; | 1594 b = b | 0; |
1591 return (a + b) | 0; | 1595 return (a + b) | 0; |
1592 } | 1596 } |
1593 return add; | 1597 return add; |
1594 } | 1598 } |
1595 | 1599 |
1596 assertEquals(7, TestSingleFunctionModule()(3, 4)); | 1600 assertEquals(7, TestSingleFunctionModule()(3, 4)); |
OLD | NEW |