OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // Test various optimizations and deoptimizations of optimizing compiler.. | |
5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr | |
6 | |
7 import "package:expect/expect.dart"; | |
8 | |
9 addThem(a, b) { | |
10 return a + b; | |
11 } | |
12 | |
13 isItInt(a) { | |
14 return a is int; | |
15 } | |
16 | |
17 doNeg(a) { | |
18 return -a; | |
19 } | |
20 | |
21 doNeg2(a) { | |
22 return -a; | |
23 } | |
24 | |
25 doNot(a) { | |
26 return !a; | |
27 } | |
28 | |
29 doBitNot(a) { | |
30 return ~a; | |
31 } | |
32 | |
33 doStore1(a, v) { | |
34 a[1] = v; | |
35 } | |
36 | |
37 doStore2(a, v) { | |
38 a[2] = v; | |
39 } | |
40 | |
41 class StringPlus { | |
42 const StringPlus(String this._val); | |
43 operator + (right) => new StringPlus("${_val}${right}"); | |
44 toString() => _val; | |
45 | |
46 final String _val; | |
47 } | |
48 | |
49 main() { | |
50 for (int i = 0; i < 20; i++) { | |
51 Expect.stringEquals("HI 5", addThem(const StringPlus("HI "), 5).toString()); | |
52 Expect.equals(true, isItInt(5)); | |
53 } | |
54 Expect.equals(8, addThem(3, 5)); | |
55 for (int i = 0; i < 20; i++) { | |
56 Expect.stringEquals("HI 5", addThem(const StringPlus("HI "), 5).toString()); | |
57 Expect.equals(8, addThem(3, 5)); | |
58 } | |
59 for (int i = -10; i < 10; i++) { | |
60 var r = doNeg(i); | |
61 var p = doNeg(r); | |
62 Expect.equals(i, p); | |
63 } | |
64 var maxSmi = (1 << 30) - 1; | |
65 Expect.equals(maxSmi, doNeg(doNeg(maxSmi))); | |
66 // Deoptimize because of overflow. | |
67 var minInt = -(1 << 30); | |
68 Expect.equals(minInt, doNeg(doNeg(minInt))); | |
69 | |
70 for (int i = 0; i < 20; i++) { | |
71 Expect.equals(false, doNot(true)); | |
72 Expect.equals(true, doNot(doNot(true))); | |
73 } | |
74 for (int i = 0; i < 20; i++) { | |
75 Expect.equals(-57, doBitNot(56)); | |
76 Expect.equals(55, doBitNot(-56)); | |
77 } | |
78 | |
79 for (int i = 0; i < 20; i++) { | |
80 Expect.equals(-2.2, doNeg2(2.2)); | |
81 } | |
82 // Deoptimize. | |
83 Expect.equals(-5, doNeg2(5)); | |
84 | |
85 var fixed = new List(10); | |
86 var growable = [1, 2, 3, 4, 5]; | |
87 | |
88 for (int i = 0; i < 20; i++) { | |
89 doStore1(fixed, 7); | |
90 Expect.equals(7, fixed[1]); | |
91 doStore2(growable, 12); | |
92 Expect.equals(12, growable[2]); | |
93 } | |
94 | |
95 // Deoptimize. | |
96 doStore1(growable, 8); | |
97 Expect.equals(8, growable[1]); | |
98 doStore2(fixed, 101); | |
99 Expect.equals(101, fixed[2]); | |
100 } | |
OLD | NEW |