| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import '../mock_compiler.dart'; | 6 import '../mock_compiler.dart'; |
| 7 import 'sexpr_unstringifier.dart'; | 7 import 'sexpr_unstringifier.dart'; |
| 8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart'; | 10 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // } else { | 24 // } else { |
| 25 // j = 3; | 25 // j = 3; |
| 26 // } | 26 // } |
| 27 // return j; | 27 // return j; |
| 28 // } | 28 // } |
| 29 | 29 |
| 30 String CP1_IN = """ | 30 String CP1_IN = """ |
| 31 (FunctionDefinition main () return () | 31 (FunctionDefinition main () return () |
| 32 (LetPrim (v0 (Constant (Int 1))) | 32 (LetPrim (v0 (Constant (Int 1))) |
| 33 (LetPrim (v1 (Constant (Int 1))) | 33 (LetPrim (v1 (Constant (Int 1))) |
| 34 (LetCont | 34 (LetCont (k0 (v2) |
| 35 ((k0 (v2) | 35 (LetCont (k1 () |
| 36 (LetCont | 36 (LetPrim (v3 (Constant (Int 2))) |
| 37 ((k1 () | 37 (InvokeContinuation return (v3)))) |
| 38 (LetPrim (v3 (Constant (Int 2))) | 38 (LetCont (k2 () |
| 39 (InvokeContinuation return (v3)))) | |
| 40 (k2 () | |
| 41 (LetPrim (v4 (Constant (Int 3))) | 39 (LetPrim (v4 (Constant (Int 3))) |
| 42 (InvokeContinuation return (v4))))) | 40 (InvokeContinuation return (v4)))) |
| 43 (Branch (IsTrue v2) k1 k2)))) | 41 (Branch (IsTrue v2) k1 k2)))) |
| 44 (InvokeMethod v0 == (v1) k0))))) | 42 (InvokeMethod v0 == (v1) k0))))) |
| 45 """; | 43 """; |
| 46 String CP1_OUT = """ | 44 String CP1_OUT = """ |
| 47 (FunctionDefinition main () return () | 45 (FunctionDefinition main () return () |
| 48 (LetPrim (v0 (Constant (Int 1))) | 46 (LetPrim (v0 (Constant (Int 1))) |
| 49 (LetPrim (v1 (Constant (Int 1))) | 47 (LetPrim (v1 (Constant (Int 1))) |
| 50 (LetCont | 48 (LetCont (k0 (v2) |
| 51 ((k0 (v2) | 49 (LetCont (k1 () |
| 52 (LetCont | 50 (LetPrim (v3 (Constant (Int 2))) |
| 53 ((k1 () | 51 (InvokeContinuation return (v3)))) |
| 54 (LetPrim (v3 (Constant (Int 2))) | 52 (LetCont (k2 () |
| 55 (InvokeContinuation return (v3)))) | |
| 56 (k2 () | |
| 57 (LetPrim (v4 (Constant (Int 3))) | 53 (LetPrim (v4 (Constant (Int 3))) |
| 58 (InvokeContinuation return (v4))))) | 54 (InvokeContinuation return (v4)))) |
| 59 (InvokeContinuation k1 ())))) | 55 (InvokeContinuation k1 ())))) |
| 60 (LetPrim (v5 (Constant (Bool true))) | 56 (LetPrim (v5 (Constant (Bool true))) |
| 61 (InvokeContinuation k0 (v5))))))) | 57 (InvokeContinuation k0 (v5))))))) |
| 62 """; | 58 """; |
| 63 | 59 |
| 64 // CP2 represents the following incoming dart code: | 60 // CP2 represents the following incoming dart code: |
| 65 // | 61 // |
| 66 // int main() { | 62 // int main() { |
| 67 // int i = 1; | 63 // int i = 1; |
| 68 // while (true) { | 64 // while (true) { |
| 69 // if (false || false) { | 65 // if (false || false) { |
| 70 // return i; | 66 // return i; |
| 71 // } | 67 // } |
| 72 // if (true && i == 1) { | 68 // if (true && i == 1) { |
| 73 // return i; | 69 // return i; |
| 74 // } | 70 // } |
| 75 // } | 71 // } |
| 76 // return 42; | 72 // return 42; |
| 77 // } | 73 // } |
| 78 | 74 |
| 79 String CP2_IN = """ | 75 String CP2_IN = """ |
| 80 (FunctionDefinition main () return () | 76 (FunctionDefinition main () return () |
| 81 (LetPrim (v0 (Constant (Int 1))) | 77 (LetPrim (v0 (Constant (Int 1))) |
| 82 (LetCont | 78 (LetCont* (k0 () |
| 83 ((rec k0 () | 79 (LetCont (k1 () |
| 84 (LetCont | 80 (LetPrim (v1 (Constant (Int 42))) |
| 85 ((k1 () | 81 (InvokeContinuation return (v1)))) |
| 86 (LetPrim (v1 (Constant (Int 42))) | 82 (LetCont (k2 () |
| 87 (InvokeContinuation return (v1)))) | 83 (LetPrim (v2 (Constant (Bool false))) |
| 88 (k2 () | 84 (LetCont (k3 (v3) |
| 89 (LetPrim (v2 (Constant (Bool false))) | 85 (LetCont (k4 () |
| 90 (LetCont | 86 (InvokeContinuation return (v0))) |
| 91 ((k3 (v3) | 87 (LetCont (k5 () |
| 92 (LetCont | 88 (LetPrim (v4 (Constant (Bool true))) |
| 93 ((k4 () | 89 (LetCont (k6 (v5) |
| 94 (InvokeContinuation return (v0))) | 90 (LetCont (k7 () |
| 95 (k5 () | 91 (InvokeContinuation return (v0))) |
| 96 (LetPrim (v4 (Constant (Bool true))) | 92 (LetCont (k8 () |
| 97 (LetCont | 93 (InvokeContinuation* k0 ())) |
| 98 ((k6 (v5) | 94 (Branch (IsTrue v5) k7 k8)))) |
| 99 (LetCont | 95 (LetCont (k9 () |
| 100 ((k7 () | 96 (LetPrim (v6 (Constant (Int 1))) |
| 101 (InvokeContinuation return (v0)
)) | 97 (LetCont (k10 (v7) |
| 102 (k8 () | 98 (LetCont (k11 () |
| 103 (InvokeContinuation* k0 ()))) | 99 (LetPrim (v8 (Constant (Bool true))) |
| 104 (Branch (IsTrue v5) k7 k8)))) | 100 (InvokeContinuation k6 (v8)))) |
| 105 (LetCont | 101 (LetCont (k12 () |
| 106 ((k9 () | 102 (LetPrim (v9 (Constant (Bool false
))) |
| 107 (LetPrim (v6 (Constant (Int 1))) | 103 (InvokeContinuation k6 (v9)))) |
| 108 (LetCont | 104 (Branch (IsTrue v7) k11 k12)))) |
| 109 ((k10 (v7) | 105 (InvokeMethod v0 == (v6) k10)))) |
| 110 (LetCont | 106 (LetCont (k13 () |
| 111 ((k11 () | 107 (LetPrim (v10 (Constant (Bool false))) |
| 112 (LetPrim (v8 (Const
ant (Bool true))) | 108 (InvokeContinuation k6 (v10)))) |
| 113 (InvokeContinuati
on k6 (v8)))) | 109 (Branch (IsTrue v4) k9 k13)))))) |
| 114 (k12 () | 110 (Branch (IsTrue v3) k4 k5)))) |
| 115 (LetPrim (v9 (Const
ant (Bool false))) | 111 (LetCont (k14 () |
| 116 (InvokeContinuati
on k6 (v9))))) | 112 (LetPrim (v11 (Constant (Bool true))) |
| 117 (Branch (IsTrue v7) k11
k12)))) | 113 (InvokeContinuation k3 (v11)))) |
| 118 (InvokeMethod v0 == (v6) k10)))
) | 114 (LetCont (k15 () |
| 119 (k13 () | 115 (LetPrim (v12 (Constant (Bool false))) |
| 120 (LetPrim (v10 (Constant (Bool false
))) | 116 (LetCont (k16 () |
| 121 (InvokeContinuation k6 (v10))))) | 117 (LetPrim (v13 (Constant (Bool true))) |
| 122 (Branch (IsTrue v4) k9 k13)))))) | 118 (InvokeContinuation k3 (v13)))) |
| 123 (Branch (IsTrue v3) k4 k5)))) | 119 (LetCont (k17 () |
| 124 (LetCont | 120 (LetPrim (v14 (Constant (Bool false))) |
| 125 ((k14 () | 121 (InvokeContinuation k3 (v14)))) |
| 126 (LetPrim (v11 (Constant (Bool true))) | 122 (Branch (IsTrue v12) k16 k17))))) |
| 127 (InvokeContinuation k3 (v11)))) | 123 (Branch (IsTrue v2) k14 k15)))))) |
| 128 (k15 () | 124 (LetPrim (v15 (Constant (Bool true))) |
| 129 (LetPrim (v12 (Constant (Bool false))) | 125 (Branch (IsTrue v15) k2 k1))))) |
| 130 (LetCont | 126 (InvokeContinuation k0 ())))) |
| 131 ((k16 () | |
| 132 (LetPrim (v13 (Constant (Bool true))) | |
| 133 (InvokeContinuation k3 (v13)))) | |
| 134 (k17 () | |
| 135 (LetPrim (v14 (Constant (Bool false))) | |
| 136 (InvokeContinuation k3 (v14))))) | |
| 137 (Branch (IsTrue v12) k16 k17))))) | |
| 138 (Branch (IsTrue v2) k14 k15)))))) | |
| 139 (LetPrim (v15 (Constant (Bool true))) | |
| 140 (Branch (IsTrue v15) k2 k1))))) | |
| 141 (InvokeContinuation k0 ())))() | |
| 142 """; | 127 """; |
| 143 String CP2_OUT = """ | 128 String CP2_OUT = """ |
| 144 (FunctionDefinition main () return () | 129 (FunctionDefinition main () return () |
| 145 (LetPrim (v0 (Constant (Int 1))) | 130 (LetPrim (v0 (Constant (Int 1))) |
| 146 (LetCont | 131 (LetCont* (k0 () |
| 147 ((rec k0 () | 132 (LetCont (k1 () |
| 148 (LetCont | 133 (LetPrim (v1 (Constant (Int 42))) |
| 149 ((k1 () | 134 (InvokeContinuation return (v1)))) |
| 150 (LetPrim (v1 (Constant (Int 42))) | 135 (LetCont (k2 () |
| 151 (InvokeContinuation return (v1)))) | 136 (LetPrim (v2 (Constant (Bool false))) |
| 152 (k2 () | 137 (LetCont (k3 (v3) |
| 153 (LetPrim (v2 (Constant (Bool false))) | 138 (LetCont (k4 () |
| 154 (LetCont | 139 (InvokeContinuation return (v0))) |
| 155 ((k3 (v3) | 140 (LetCont (k5 () |
| 156 (LetCont | 141 (LetPrim (v4 (Constant (Bool true))) |
| 157 ((k4 () | 142 (LetCont (k6 (v5) |
| 158 (InvokeContinuation return (v0))) | 143 (LetCont (k7 () |
| 159 (k5 () | 144 (InvokeContinuation return (v0))) |
| 160 (LetPrim (v4 (Constant (Bool true))) | 145 (LetCont (k8 () |
| 161 (LetCont | 146 (InvokeContinuation* k0 ())) |
| 162 ((k6 (v5) | 147 (InvokeContinuation k7 ())))) |
| 163 (LetCont | 148 (LetCont (k9 () |
| 164 ((k7 () | 149 (LetPrim (v6 (Constant (Int 1))) |
| 165 (InvokeContinuation return (v0
))) | 150 (LetCont (k10 (v7) |
| 166 (k8 () | 151 (LetCont (k11 () |
| 167 (InvokeContinuation* k0 ()))) | 152 (LetPrim (v8 (Constant (Bool true))) |
| 168 (InvokeContinuation k7 ())))) | 153 (InvokeContinuation k6 (v8)))) |
| 169 (LetCont | 154 (LetCont (k12 () |
| 170 ((k9 () | 155 (LetPrim (v9 (Constant (Bool false
))) |
| 171 (LetPrim (v6 (Constant (Int 1))) | 156 (InvokeContinuation k6 (v9)))) |
| 172 (LetCont | 157 (InvokeContinuation k11 ())))) |
| 173 ((k10 (v7) | 158 (LetPrim (v10 (Constant (Bool true))) |
| 174 (LetCont | 159 (InvokeContinuation k10 (v10)))))) |
| 175 ((k11 () | 160 (LetCont (k13 () |
| 176 (LetPrim (v8 (Const
ant (Bool true))) | 161 (LetPrim (v11 (Constant (Bool false))) |
| 177 (InvokeContinuati
on k6 (v8)))) | 162 (InvokeContinuation k6 (v11)))) |
| 178 (k12 () | 163 (InvokeContinuation k9 ())))))) |
| 179 (LetPrim (v9 (Const
ant (Bool false))) | 164 (InvokeContinuation k5 ())))) |
| 180 (InvokeContinuati
on k6 (v9))))) | 165 (LetCont (k14 () |
| 181 (InvokeContinuation k11
())))) | 166 (LetPrim (v12 (Constant (Bool true))) |
| 182 (LetPrim (v10 (Constant (Bool t
rue))) | 167 (InvokeContinuation k3 (v12)))) |
| 183 (InvokeContinuation k10 (v10)
))))) | 168 (LetCont (k15 () |
| 184 (k13 () | 169 (LetPrim (v13 (Constant (Bool false))) |
| 185 (LetPrim (v11 (Constant (Bool false
))) | 170 (LetCont (k16 () |
| 186 (InvokeContinuation k6 (v11))))) | 171 (LetPrim (v14 (Constant (Bool true))) |
| 187 (InvokeContinuation k9 ())))))) | 172 (InvokeContinuation k3 (v14)))) |
| 188 (InvokeContinuation k5 ())))) | 173 (LetCont (k17 () |
| 189 (LetCont | 174 (LetPrim (v15 (Constant (Bool false))) |
| 190 ((k14 () | 175 (InvokeContinuation k3 (v15)))) |
| 191 (LetPrim (v12 (Constant (Bool true))) | 176 (InvokeContinuation k17 ()))))) |
| 192 (InvokeContinuation k3 (v12)))) | 177 (InvokeContinuation k15 ())))))) |
| 193 (k15 () | 178 (LetPrim (v16 (Constant (Bool true))) |
| 194 (LetPrim (v13 (Constant (Bool false))) | 179 (InvokeContinuation k2 ()))))) |
| 195 (LetCont | |
| 196 ((k16 () | |
| 197 (LetPrim (v14 (Constant (Bool true))) | |
| 198 (InvokeContinuation k3 (v14)))) | |
| 199 (k17 () | |
| 200 (LetPrim (v15 (Constant (Bool false))) | |
| 201 (InvokeContinuation k3 (v15))))) | |
| 202 (InvokeContinuation k17 ()))))) | |
| 203 (InvokeContinuation k15 ())))))) | |
| 204 (LetPrim (v16 (Constant (Bool true))) | |
| 205 (InvokeContinuation k2 ()))))) | |
| 206 (InvokeContinuation k0 ())))) | 180 (InvokeContinuation k0 ())))) |
| 207 """; | 181 """; |
| 208 | 182 |
| 209 // CP3 represents the following incoming dart code: | 183 // CP3 represents the following incoming dart code: |
| 210 // | 184 // |
| 211 // int main() { | 185 // int main() { |
| 212 // int i = 1; | 186 // int i = 1; |
| 213 // i = f(); | 187 // i = f(); |
| 214 // if (i == 1) { | 188 // if (i == 1) { |
| 215 // return 42; | 189 // return 42; |
| 216 // } | 190 // } |
| 217 // return i; | 191 // return i; |
| 218 // } | 192 // } |
| 219 | 193 |
| 220 String CP3_IN = """ | 194 String CP3_IN = """ |
| 221 (FunctionDefinition main () return () | 195 (FunctionDefinition main () return () |
| 222 (LetPrim (v0 (Constant (Int 1))) | 196 (LetPrim (v0 (Constant (Int 1))) |
| 223 (LetCont | 197 (LetCont (k0 (v1) |
| 224 ((k0 (v1) | 198 (LetPrim (v2 (Constant (Int 1))) |
| 225 (LetPrim (v2 (Constant (Int 1))) | 199 (LetCont (k1 (v3) |
| 226 (LetCont | 200 (LetCont (k2 () |
| 227 ((k1 (v3) | 201 (LetPrim (v4 (Constant (Int 42))) |
| 228 (LetCont | 202 (InvokeContinuation return (v4)))) |
| 229 ((k2 () | 203 (LetCont (k3 () |
| 230 (LetPrim (v4 (Constant (Int 42))) | 204 (InvokeContinuation return (v1))) |
| 231 (InvokeContinuation return (v4)))) | 205 (Branch (IsTrue v3) k2 k3)))) |
| 232 (k3 () | 206 (InvokeMethod v1 == (v2) k1)))) |
| 233 (InvokeContinuation return (v1)))) | |
| 234 (Branch (IsTrue v3) k2 k3)))) | |
| 235 (InvokeMethod v1 == (v2) k1))))) | |
| 236 (InvokeStatic f () k0)))) | 207 (InvokeStatic f () k0)))) |
| 237 """; | 208 """; |
| 238 String CP3_OUT = CP3_IN; | 209 String CP3_OUT = CP3_IN; |
| 239 | 210 |
| 240 // Addition. | 211 // Addition. |
| 241 | 212 |
| 242 String CP4_IN = """ | 213 String CP4_IN = """ |
| 243 (FunctionDefinition main () return () | 214 (FunctionDefinition main () return () |
| 244 (LetPrim (v0 (Constant (Int 1))) | 215 (LetPrim (v0 (Constant (Int 1))) |
| 245 (LetPrim (v1 (Constant (Int 2))) | 216 (LetPrim (v1 (Constant (Int 2))) |
| 246 (LetCont | 217 (LetCont (k0 (v2) |
| 247 ((k0 (v2) | 218 (InvokeContinuation return (v2))) |
| 248 (InvokeContinuation return (v2)))) | |
| 249 (InvokeMethod v0 + (v1) k0))))) | 219 (InvokeMethod v0 + (v1) k0))))) |
| 250 """; | 220 """; |
| 251 String CP4_OUT = """ | 221 String CP4_OUT = """ |
| 252 (FunctionDefinition main () return () | 222 (FunctionDefinition main () return () |
| 253 (LetPrim (v0 (Constant (Int 1))) | 223 (LetPrim (v0 (Constant (Int 1))) |
| 254 (LetPrim (v1 (Constant (Int 2))) | 224 (LetPrim (v1 (Constant (Int 2))) |
| 255 (LetCont | 225 (LetCont (k0 (v2) |
| 256 ((k0 (v2) | 226 (InvokeContinuation return (v2))) |
| 257 (InvokeContinuation return (v2)))) | |
| 258 (LetPrim (v3 (Constant (Int 3))) | 227 (LetPrim (v3 (Constant (Int 3))) |
| 259 (InvokeContinuation k0 (v3))))))) | 228 (InvokeContinuation k0 (v3))))))) |
| 260 """; | 229 """; |
| 261 | 230 |
| 262 // Array access operator (no optimization). | 231 // Array access operator (no optimization). |
| 263 | 232 |
| 264 String CP5_IN = """ | 233 String CP5_IN = """ |
| 265 (FunctionDefinition main () return () | 234 (FunctionDefinition main () return () |
| 266 (LetPrim (v0 (Constant (Int 1))) | 235 (LetPrim (v0 (Constant (Int 1))) |
| 267 (LetPrim (v1 (Constant (Int 2))) | 236 (LetPrim (v1 (Constant (Int 2))) |
| 268 (LetCont | 237 (LetCont (k0 (v2) |
| 269 ((k0 (v2) | 238 (InvokeContinuation return (v2))) |
| 270 (InvokeContinuation return (v2)))) | |
| 271 (InvokeMethod v0 [] (v1) k0))))) | 239 (InvokeMethod v0 [] (v1) k0))))) |
| 272 """; | 240 """; |
| 273 String CP5_OUT = CP5_IN; | 241 String CP5_OUT = CP5_IN; |
| 274 | 242 |
| 275 // Division by 0. | 243 // Division by 0. |
| 276 | 244 |
| 277 String CP6_IN = """ | 245 String CP6_IN = """ |
| 278 (FunctionDefinition main () return () | 246 (FunctionDefinition main () return () |
| 279 (LetPrim (v0 (Constant (Int 1))) | 247 (LetPrim (v0 (Constant (Int 1))) |
| 280 (LetPrim (v1 (Constant (Int 0))) | 248 (LetPrim (v1 (Constant (Int 0))) |
| 281 (LetCont | 249 (LetCont (k0 (v2) |
| 282 ((k0 (v2) | 250 (InvokeContinuation return (v2))) |
| 283 (InvokeContinuation return (v2)))) | 251 (InvokeMethod v0 / (v1) k0))))) |
| 284 (InvokeMethod v0 / (v1) k0))))) | |
| 285 """; | 252 """; |
| 286 String CP6_OUT = """ | 253 String CP6_OUT = """ |
| 287 (FunctionDefinition main () return () | 254 (FunctionDefinition main () return () |
| 288 (LetPrim (v0 (Constant (Int 1))) | 255 (LetPrim (v0 (Constant (Int 1))) |
| 289 (LetPrim (v1 (Constant (Int 0))) | 256 (LetPrim (v1 (Constant (Int 0))) |
| 290 (LetCont | 257 (LetCont (k0 (v2) |
| 291 ((k0 (v2) | 258 (InvokeContinuation return (v2))) |
| 292 (InvokeContinuation return (v2)))) | |
| 293 (LetPrim (v3 (Constant (Double Infinity))) | 259 (LetPrim (v3 (Constant (Double Infinity))) |
| 294 (InvokeContinuation k0 (v3))))))) | 260 (InvokeContinuation k0 (v3))))))) |
| 295 """; | 261 """; |
| 296 | 262 |
| 297 // Concatenate strings. | 263 // Concatenate strings. |
| 298 | 264 |
| 299 String CP7_IN = """ | 265 String CP7_IN = """ |
| 300 (FunctionDefinition main () return () | 266 (FunctionDefinition main () return () |
| 301 (LetPrim (v0 (Constant (String "b"))) | 267 (LetPrim (v0 (Constant (String "b"))) |
| 302 (LetPrim (v1 (Constant (String "d"))) | 268 (LetPrim (v1 (Constant (String "d"))) |
| 303 (LetPrim (v2 (Constant (String "a"))) | 269 (LetPrim (v2 (Constant (String "a"))) |
| 304 (LetPrim (v3 (Constant (String "c"))) | 270 (LetPrim (v3 (Constant (String "c"))) |
| 305 (LetPrim (v4 (Constant (String ""))) | 271 (LetPrim (v4 (Constant (String ""))) |
| 306 (LetCont | 272 (LetCont (k0 (v5) |
| 307 ((k0 (v5) | 273 (LetCont (k1 (v6) |
| 308 (LetCont | 274 (InvokeContinuation return (v6))) |
| 309 ((k1 (v6) | 275 (InvokeMethod v5 length () k1))) |
| 310 (InvokeContinuation return (v6)))) | |
| 311 (InvokeMethod v5 length () k1)))) | |
| 312 (ConcatenateStrings (v2 v0 v3 v1 v4) k0)))))))) | 276 (ConcatenateStrings (v2 v0 v3 v1 v4) k0)))))))) |
| 313 """; | 277 """; |
| 314 String CP7_OUT = """ | 278 String CP7_OUT = """ |
| 315 (FunctionDefinition main () return () | 279 (FunctionDefinition main () return () |
| 316 (LetPrim (v0 (Constant (String "b"))) | 280 (LetPrim (v0 (Constant (String "b"))) |
| 317 (LetPrim (v1 (Constant (String "d"))) | 281 (LetPrim (v1 (Constant (String "d"))) |
| 318 (LetPrim (v2 (Constant (String "a"))) | 282 (LetPrim (v2 (Constant (String "a"))) |
| 319 (LetPrim (v3 (Constant (String "c"))) | 283 (LetPrim (v3 (Constant (String "c"))) |
| 320 (LetPrim (v4 (Constant (String ""))) | 284 (LetPrim (v4 (Constant (String ""))) |
| 321 (LetCont | 285 (LetCont (k0 (v5) |
| 322 ((k0 (v5) | 286 (LetCont (k1 (v6) |
| 323 (LetCont | 287 (InvokeContinuation return (v6))) |
| 324 ((k1 (v6) | 288 (InvokeMethod v5 length () k1))) |
| 325 (InvokeContinuation return (v6)))) | |
| 326 (InvokeMethod v5 length () k1)))) | |
| 327 (LetPrim (v7 (Constant (String "abcd"))) | 289 (LetPrim (v7 (Constant (String "abcd"))) |
| 328 (InvokeContinuation k0 (v7)))))))))) | 290 (InvokeContinuation k0 (v7)))))))))) |
| 329 """; | 291 """; |
| 330 | 292 |
| 331 // TODO(jgruber): We can't test is-check optimization because the unstringifier | 293 // TODO(jgruber): We can't test is-check optimization because the unstringifier |
| 332 // does not recreate accurate types for the TypeOperator node. | 294 // does not recreate accurate types for the TypeOperator node. |
| 333 | 295 |
| 334 // Simple branch removal. | 296 // Simple branch removal. |
| 335 | 297 |
| 336 String CP8_IN = """ | 298 String CP8_IN = """ |
| 337 (FunctionDefinition main () return () | 299 (FunctionDefinition main () return () |
| 338 (LetPrim (v0 (Constant (Int 1))) | 300 (LetPrim (v0 (Constant (Int 1))) |
| 339 (LetPrim (v1 (Constant (Int 1))) | 301 (LetPrim (v1 (Constant (Int 1))) |
| 340 (LetCont | 302 (LetCont (k0 (v2) |
| 341 ((k0 (v2) | 303 (LetCont (k1 () |
| 342 (LetCont | 304 (LetPrim (v3 (Constant (Int 42))) |
| 343 ((k1 () | 305 (InvokeContinuation return (v3)))) |
| 344 (LetPrim (v3 (Constant (Int 42))) | 306 (LetCont (k2 () |
| 345 (InvokeContinuation return (v3)))) | 307 (InvokeContinuation return (v0))) |
| 346 (k2 () | 308 (Branch (IsTrue v2) k1 k2)))) |
| 347 (InvokeContinuation return (v0)))) | |
| 348 (Branch (IsTrue v2) k1 k2)))) | |
| 349 (InvokeMethod v0 == (v1) k0))))) | 309 (InvokeMethod v0 == (v1) k0))))) |
| 350 """; | 310 """; |
| 351 String CP8_OUT = """ | 311 String CP8_OUT = """ |
| 352 (FunctionDefinition main () return () | 312 (FunctionDefinition main () return () |
| 353 (LetPrim (v0 (Constant (Int 1))) | 313 (LetPrim (v0 (Constant (Int 1))) |
| 354 (LetPrim (v1 (Constant (Int 1))) | 314 (LetPrim (v1 (Constant (Int 1))) |
| 355 (LetCont | 315 (LetCont (k0 (v2) |
| 356 ((k0 (v2) | 316 (LetCont (k1 () |
| 357 (LetCont | 317 (LetPrim (v3 (Constant (Int 42))) |
| 358 ((k1 () | 318 (InvokeContinuation return (v3)))) |
| 359 (LetPrim (v3 (Constant (Int 42))) | 319 (LetCont (k2 () |
| 360 (InvokeContinuation return (v3)))) | 320 (InvokeContinuation return (v0))) |
| 361 (k2 () | 321 (InvokeContinuation k1 ())))) |
| 362 (InvokeContinuation return (v0)))) | |
| 363 (InvokeContinuation k1 ())))) | |
| 364 (LetPrim (v4 (Constant (Bool true))) | 322 (LetPrim (v4 (Constant (Bool true))) |
| 365 (InvokeContinuation k0 (v4))))))) | 323 (InvokeContinuation k0 (v4))))))) |
| 366 """; | 324 """; |
| 367 | 325 |
| 368 // While loop. | 326 // While loop. |
| 369 | 327 |
| 370 String CP9_IN = """ | 328 String CP9_IN = """ |
| 371 (FunctionDefinition main () return () | 329 (FunctionDefinition main () return () |
| 372 (LetPrim (v0 (Constant (Int 1))) | 330 (LetPrim (v0 (Constant (Int 1))) |
| 373 (LetCont | 331 (LetCont* (k0 (v1) |
| 374 ((rec k0 (v1) | 332 (LetCont (k1 () |
| 375 (LetCont | 333 (InvokeContinuation return (v1))) |
| 376 ((k1 () | 334 (LetCont (k2 () |
| 377 (InvokeContinuation return (v1))) | 335 (LetPrim (v2 (Constant (Int 1))) |
| 378 (k2 () | 336 (LetCont (k3 (v3) |
| 379 (LetPrim (v2 (Constant (Int 1))) | 337 (LetCont (k4 (v4) |
| 380 (LetCont | 338 (LetCont (k5 () |
| 381 ((k3 (v3) | 339 (LetPrim (v5 (Constant (Int 42))) |
| 382 (LetCont | 340 (InvokeContinuation return (v5)))) |
| 383 ((k4 (v4) | 341 (LetCont (k6 () |
| 384 (LetCont | 342 (LetPrim (v6 (Constant (Int 1))) |
| 385 ((k5 () | 343 (LetCont (k7 (v7) |
| 386 (LetPrim (v5 (Constant (Int 42))) | 344 (InvokeContinuation* k0 (v7))) |
| 387 (InvokeContinuation return (v5)))) | 345 (InvokeMethod v1 + (v6) k7)))) |
| 388 (k6 () | 346 (Branch (IsTrue v4) k5 k6)))) |
| 389 (LetPrim (v6 (Constant (Int 1))) | 347 (LetCont (k8 () |
| 390 (LetCont | 348 (LetPrim (v8 (Constant (Bool false))) |
| 391 ((k7 (v7) | 349 (InvokeContinuation k4 (v8)))) |
| 392 (InvokeContinuation* k0 (v7)))
) | 350 (LetCont (k9 () |
| 393 (InvokeMethod v1 + (v6) k7))))) | 351 (LetPrim (v9 (Constant (Bool true))) |
| 394 (Branch (IsTrue v4) k5 k6)))) | 352 (InvokeContinuation k4 (v9)))) |
| 395 (LetCont | 353 (Branch (IsTrue v3) k8 k9))))) |
| 396 ((k8 () | 354 (InvokeMethod v1 == (v2) k3)))) |
| 397 (LetPrim (v8 (Constant (Bool false))) | 355 (LetPrim (v10 (Constant (Bool true))) |
| 398 (InvokeContinuation k4 (v8)))) | 356 (Branch (IsTrue v10) k2 k1))))) |
| 399 (k9 () | |
| 400 (LetPrim (v9 (Constant (Bool true))) | |
| 401 (InvokeContinuation k4 (v9))))) | |
| 402 (Branch (IsTrue v3) k8 k9))))) | |
| 403 (InvokeMethod v1 == (v2) k3))))) | |
| 404 (LetPrim (v10 (Constant (Bool true))) | |
| 405 (Branch (IsTrue v10) k2 k1))))) | |
| 406 (InvokeContinuation k0 (v0))))) | 357 (InvokeContinuation k0 (v0))))) |
| 407 """; | 358 """; |
| 408 String CP9_OUT = """ | 359 String CP9_OUT = """ |
| 409 (FunctionDefinition main () return () | 360 (FunctionDefinition main () return () |
| 410 (LetPrim (v0 (Constant (Int 1))) | 361 (LetPrim (v0 (Constant (Int 1))) |
| 411 (LetCont | 362 (LetCont* (k0 (v1) |
| 412 ((rec k0 (v1) | 363 (LetCont (k1 () |
| 413 (LetCont | 364 (InvokeContinuation return (v1))) |
| 414 ((k1 () | 365 (LetCont (k2 () |
| 415 (InvokeContinuation return (v1))) | 366 (LetPrim (v2 (Constant (Int 1))) |
| 416 (k2 () | 367 (LetCont (k3 (v3) |
| 417 (LetPrim (v2 (Constant (Int 1))) | 368 (LetCont (k4 (v4) |
| 418 (LetCont | 369 (LetCont (k5 () |
| 419 ((k3 (v3) | 370 (LetPrim (v5 (Constant (Int 42))) |
| 420 (LetCont | 371 (InvokeContinuation return (v5)))) |
| 421 ((k4 (v4) | 372 (LetCont (k6 () |
| 422 (LetCont | 373 (LetPrim (v6 (Constant (Int 1))) |
| 423 ((k5 () | 374 (LetCont (k7 (v7) |
| 424 (LetPrim (v5 (Constant (Int 42))) | 375 (InvokeContinuation* k0 (v7))) |
| 425 (InvokeContinuation return (v5)))) | 376 (InvokeMethod v1 + (v6) k7)))) |
| 426 (k6 () | 377 (Branch (IsTrue v4) k5 k6)))) |
| 427 (LetPrim (v6 (Constant (Int 1))) | 378 (LetCont (k8 () |
| 428 (LetCont | 379 (LetPrim (v8 (Constant (Bool false))) |
| 429 ((k7 (v7) | 380 (InvokeContinuation k4 (v8)))) |
| 430 (InvokeContinuation* k0 (v7)))) | 381 (LetCont (k9 () |
| 431 (InvokeMethod v1 + (v6) k7))))) | 382 (LetPrim (v9 (Constant (Bool true))) |
| 432 (Branch (IsTrue v4) k5 k6)))) | 383 (InvokeContinuation k4 (v9)))) |
| 433 (LetCont | 384 (Branch (IsTrue v3) k8 k9))))) |
| 434 ((k8 () | 385 (InvokeMethod v1 == (v2) k3)))) |
| 435 (LetPrim (v8 (Constant (Bool false))) | 386 (LetPrim (v10 (Constant (Bool true))) |
| 436 (InvokeContinuation k4 (v8)))) | 387 (InvokeContinuation k2 ()))))) |
| 437 (k9 () | |
| 438 (LetPrim (v9 (Constant (Bool true))) | |
| 439 (InvokeContinuation k4 (v9))))) | |
| 440 (Branch (IsTrue v3) k8 k9))))) | |
| 441 (InvokeMethod v1 == (v2) k3))))) | |
| 442 (LetPrim (v10 (Constant (Bool true))) | |
| 443 (InvokeContinuation k2 ()))))) | |
| 444 (InvokeContinuation k0 (v0))))) | 388 (InvokeContinuation k0 (v0))))) |
| 445 """; | 389 """; |
| 446 | 390 |
| 447 // While loop, from: | 391 // While loop, from: |
| 448 // | 392 // |
| 449 // int main() { | 393 // int main() { |
| 450 // for (int i = 0; i < 2; i++) { | 394 // for (int i = 0; i < 2; i++) { |
| 451 // print(42 + i); | 395 // print(42 + i); |
| 452 // } | 396 // } |
| 453 // } | 397 // } |
| 454 | 398 |
| 455 String CP10_IN = """ | 399 String CP10_IN = """ |
| 456 (FunctionDefinition main () return () | 400 (FunctionDefinition main () return () |
| 457 (LetPrim (v0 (Constant (Int 0))) | 401 (LetPrim (v0 (Constant (Int 0))) |
| 458 (LetCont | 402 (LetCont* (k0 (v1) |
| 459 ((rec k0 (v1) | 403 (LetCont (k1 () |
| 460 (LetCont | 404 (LetPrim (v2 (Constant (Null))) |
| 461 ((k1 () | 405 (InvokeContinuation return (v2)))) |
| 462 (LetPrim (v2 (Constant (Null))) | 406 (LetCont (k2 () |
| 463 (InvokeContinuation return (v2)))) | 407 (LetPrim (v3 (Constant (Int 42))) |
| 464 (k2 () | 408 (LetCont (k3 (v4) |
| 465 (LetPrim (v3 (Constant (Int 42))) | 409 (LetCont (k4 (v5) |
| 466 (LetCont | 410 (LetPrim (v6 (Constant (Int 1))) |
| 467 ((k3 (v4) | 411 (LetCont (k5 (v7) |
| 468 (LetCont | 412 (InvokeContinuation* k0 (v7))) |
| 469 ((k4 (v5) | 413 (InvokeMethod v1 + (v6) k5)))) |
| 470 (LetPrim (v6 (Constant (Int 1))) | 414 (InvokeStatic print (v4) k4))) |
| 471 (LetCont | 415 (InvokeMethod v3 + (v1) k3)))) |
| 472 ((k5 (v7) | 416 (LetPrim (v8 (Constant (Int 2))) |
| 473 (InvokeContinuation* k0 (v7)))) | 417 (LetCont (k6 (v9) |
| 474 (InvokeMethod v1 + (v6) k5))))) | 418 (Branch (IsTrue v9) k2 k1)) |
| 475 (InvokeStatic print (v4) k4)))) | 419 (InvokeMethod v1 < (v8) k6)))))) |
| 476 (InvokeMethod v3 + (v1) k3))))) | |
| 477 (LetPrim (v8 (Constant (Int 2))) | |
| 478 (LetCont | |
| 479 ((k6 (v9) | |
| 480 (Branch (IsTrue v9) k2 k1))) | |
| 481 (InvokeMethod v1 < (v8) k6)))))) | |
| 482 (InvokeContinuation k0 (v0))))) | 420 (InvokeContinuation k0 (v0))))) |
| 483 """; | 421 """; |
| 484 String CP10_OUT = CP10_IN; | 422 String CP10_OUT = CP10_IN; |
| 485 | 423 |
| 486 /// Normalizes whitespace by replacing all whitespace sequences by a single | 424 /// Normalizes whitespace by replacing all whitespace sequences by a single |
| 487 /// space and trimming leading and trailing whitespace. | 425 /// space and trimming leading and trailing whitespace. |
| 488 String normalizeSExpr(String input) { | 426 String normalizeSExpr(String input) { |
| 489 return input.replaceAll(new RegExp(r'[ \n\t]+'), ' ').trim(); | 427 return input.replaceAll(new RegExp(r'[ \n\t]+'), ' ').trim(); |
| 490 } | 428 } |
| 491 | 429 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 519 asyncTest(() => testConstantPropagator(CP2_IN, CP2_OUT)); | 457 asyncTest(() => testConstantPropagator(CP2_IN, CP2_OUT)); |
| 520 asyncTest(() => testConstantPropagator(CP3_IN, CP3_OUT)); | 458 asyncTest(() => testConstantPropagator(CP3_IN, CP3_OUT)); |
| 521 asyncTest(() => testConstantPropagator(CP4_IN, CP4_OUT)); | 459 asyncTest(() => testConstantPropagator(CP4_IN, CP4_OUT)); |
| 522 asyncTest(() => testConstantPropagator(CP5_IN, CP5_OUT)); | 460 asyncTest(() => testConstantPropagator(CP5_IN, CP5_OUT)); |
| 523 asyncTest(() => testConstantPropagator(CP6_IN, CP6_OUT)); | 461 asyncTest(() => testConstantPropagator(CP6_IN, CP6_OUT)); |
| 524 asyncTest(() => testConstantPropagator(CP7_IN, CP7_OUT)); | 462 asyncTest(() => testConstantPropagator(CP7_IN, CP7_OUT)); |
| 525 asyncTest(() => testConstantPropagator(CP8_IN, CP8_OUT)); | 463 asyncTest(() => testConstantPropagator(CP8_IN, CP8_OUT)); |
| 526 asyncTest(() => testConstantPropagator(CP9_IN, CP9_OUT)); | 464 asyncTest(() => testConstantPropagator(CP9_IN, CP9_OUT)); |
| 527 asyncTest(() => testConstantPropagator(CP10_IN, CP10_OUT)); | 465 asyncTest(() => testConstantPropagator(CP10_IN, CP10_OUT)); |
| 528 } | 466 } |
| OLD | NEW |