OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 for (var k = 0; k < rightTrees.length; ++k) { | 48 for (var k = 0; k < rightTrees.length; ++k) { |
49 var string = "(" + leftTrees[j] + op + rightTrees[k] + ")"; | 49 var string = "(" + leftTrees[j] + op + rightTrees[k] + ")"; |
50 result.push(string); | 50 result.push(string); |
51 } | 51 } |
52 } | 52 } |
53 } | 53 } |
54 return result; | 54 return result; |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 // All 429 possible bitwise OR trees with eight leaves. | 58 // All possible bitwise OR trees with six leaves, i.e. CatalanNumber[5] = 42, |
59 var identifiers = ['a','b','c','d','e','f','g','h']; | 59 // see http://mathworld.wolfram.com/CatalanNumber.html. |
| 60 var identifiers = ['a','b','c','d','e','f']; |
60 var or_trees = makeTrees("|", identifiers); | 61 var or_trees = makeTrees("|", identifiers); |
61 var and_trees = makeTrees("&", identifiers); | 62 var and_trees = makeTrees("&", identifiers); |
62 | 63 |
63 // Set up leaf masks to set 8 least-significant bits. | 64 // Set up leaf masks to set 6 least-significant bits. |
64 var a = 1 << 0; | 65 var a = 1 << 0; |
65 var b = 1 << 1; | 66 var b = 1 << 1; |
66 var c = 1 << 2; | 67 var c = 1 << 2; |
67 var d = 1 << 3; | 68 var d = 1 << 3; |
68 var e = 1 << 4; | 69 var e = 1 << 4; |
69 var f = 1 << 5; | 70 var f = 1 << 5; |
70 var g = 1 << 6; | |
71 var h = 1 << 7; | |
72 | 71 |
73 for (var i = 0; i < or_trees.length; ++i) { | 72 for (var i = 0; i < or_trees.length; ++i) { |
74 for (var j = 0; j < 8; ++j) { | 73 for (var j = 0; j < 6; ++j) { |
75 var or_fun = new Function("return " + or_trees[i]); | 74 var or_fun = new Function("return " + or_trees[i]); |
76 if (j == 0) assertEquals(255, or_fun()); | 75 if (j == 0) assertEquals(63, or_fun()); |
77 | 76 |
78 // Set the j'th variable to a string to force a bailout. | 77 // Set the j'th variable to a string to force a bailout. |
79 eval(identifiers[j] + "+= ''"); | 78 eval(identifiers[j] + "+= ''"); |
80 assertEquals(255, or_fun()); | 79 assertEquals(63, or_fun()); |
81 // Set it back to a number for the next iteration. | 80 // Set it back to a number for the next iteration. |
82 eval(identifiers[j] + "= +" + identifiers[j]); | 81 eval(identifiers[j] + "= +" + identifiers[j]); |
83 } | 82 } |
84 } | 83 } |
85 | 84 |
86 // Set up leaf masks to clear 8 least-significant bits. | 85 // Set up leaf masks to clear 6 least-significant bits. |
87 a ^= 255; | 86 a ^= 63; |
88 b ^= 255; | 87 b ^= 63; |
89 c ^= 255; | 88 c ^= 63; |
90 d ^= 255; | 89 d ^= 63; |
91 e ^= 255; | 90 e ^= 63; |
92 f ^= 255; | 91 f ^= 63; |
93 g ^= 255; | |
94 h ^= 255; | |
95 | 92 |
96 for (i = 0; i < and_trees.length; ++i) { | 93 for (i = 0; i < and_trees.length; ++i) { |
97 for (var j = 0; j < 8; ++j) { | 94 for (var j = 0; j < 6; ++j) { |
98 var and_fun = new Function("return " + and_trees[i]); | 95 var and_fun = new Function("return " + and_trees[i]); |
99 if (j == 0) assertEquals(0, and_fun()); | 96 if (j == 0) assertEquals(0, and_fun()); |
100 | 97 |
101 // Set the j'th variable to a string to force a bailout. | 98 // Set the j'th variable to a string to force a bailout. |
102 eval(identifiers[j] + "+= ''"); | 99 eval(identifiers[j] + "+= ''"); |
103 assertEquals(0, and_fun()); | 100 assertEquals(0, and_fun()); |
104 // Set it back to a number for the next iteration. | 101 // Set it back to a number for the next iteration. |
105 eval(identifiers[j] + "= +" + identifiers[j]); | 102 eval(identifiers[j] + "= +" + identifiers[j]); |
106 } | 103 } |
107 } | 104 } |
OLD | NEW |