| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 | 5 |
| 6 #include "vm/ast_printer.h" | 6 #include "vm/ast_printer.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
| 9 #include "vm/longjump.h" | 9 #include "vm/longjump.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 EXPECT_VALID(lib); | 263 EXPECT_VALID(lib); |
| 264 EXPECT_STREQ( | 264 EXPECT_STREQ( |
| 265 // function f uses one ctx var at (0); doesn't save ctx. | 265 // function f uses one ctx var at (0); doesn't save ctx. |
| 266 "main.f\n" | 266 "main.f\n" |
| 267 " 0 ContextVar level=0 begin=14 end=28 name=value\n" | 267 " 0 ContextVar level=0 begin=14 end=28 name=value\n" |
| 268 " 1 StackVar scope=1 begin=16 end=28 name=param\n" | 268 " 1 StackVar scope=1 begin=16 end=28 name=param\n" |
| 269 " 2 CurrentCtx scope=0 begin=0 end=0" | 269 " 2 CurrentCtx scope=0 begin=0 end=0" |
| 270 " name=:current_context_var\n" | 270 " name=:current_context_var\n" |
| 271 | 271 |
| 272 // Closure call saves current context. | 272 // Closure call saves current context. |
| 273 "_FunctionImpl.call\n" | 273 "_Closure.call\n" |
| 274 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 274 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 275 " 1 CurrentCtx scope=0 begin=0 end=0" | 275 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 276 " name=:current_context_var\n" | 276 " name=:current_context_var\n" |
| 277 | 277 |
| 278 // function main uses one ctx var at (1); saves caller ctx. | 278 // function main uses one ctx var at (1); saves caller ctx. |
| 279 "main\n" | 279 "main\n" |
| 280 " 0 CurrentCtx scope=0 begin=0 end=0" | 280 " 0 CurrentCtx scope=0 begin=0 end=0" |
| 281 " name=:current_context_var\n" | 281 " name=:current_context_var\n" |
| 282 " 1 ContextLevel level=1 scope=2 begin=4 end=37\n" | 282 " 1 ContextLevel level=1 scope=2 begin=4 end=37\n" |
| 283 " 2 ContextVar level=1 begin=10 end=37 name=value\n" | 283 " 2 ContextVar level=1 begin=10 end=37 name=value\n" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 302 EXPECT_VALID(lib); | 302 EXPECT_VALID(lib); |
| 303 EXPECT_STREQ( | 303 EXPECT_STREQ( |
| 304 // Innermost function uses captured variable 'value' from middle | 304 // Innermost function uses captured variable 'value' from middle |
| 305 // function. | 305 // function. |
| 306 "a.b.c\n" | 306 "a.b.c\n" |
| 307 " 0 ContextVar level=0 begin=20 end=30 name=value\n" | 307 " 0 ContextVar level=0 begin=20 end=30 name=value\n" |
| 308 " 1 CurrentCtx scope=0 begin=0 end=0" | 308 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 309 " name=:current_context_var\n" | 309 " name=:current_context_var\n" |
| 310 | 310 |
| 311 // Closure call saves current context. | 311 // Closure call saves current context. |
| 312 "_FunctionImpl.call\n" | 312 "_Closure.call\n" |
| 313 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 313 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 314 " 1 CurrentCtx scope=0 begin=0 end=0" | 314 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 315 " name=:current_context_var\n" | 315 " name=:current_context_var\n" |
| 316 | 316 |
| 317 // Middle function saves the entry context. Notice that this | 317 // Middle function saves the entry context. Notice that this |
| 318 // happens here and not in the outermost function. We always | 318 // happens here and not in the outermost function. We always |
| 319 // save the entry context at the last possible moment. | 319 // save the entry context at the last possible moment. |
| 320 "a.b\n" | 320 "a.b\n" |
| 321 " 0 CurrentCtx scope=0 begin=0 end=0" | 321 " 0 CurrentCtx scope=0 begin=0 end=0" |
| 322 " name=:current_context_var\n" | 322 " name=:current_context_var\n" |
| 323 " 1 ContextLevel level=1 scope=2 begin=10 end=38\n" | 323 " 1 ContextLevel level=1 scope=2 begin=10 end=38\n" |
| 324 " 2 ContextVar level=1 begin=16 end=38 name=value\n" | 324 " 2 ContextVar level=1 begin=16 end=38 name=value\n" |
| 325 " 3 StackVar scope=2 begin=18 end=38 name=c\n" | 325 " 3 StackVar scope=2 begin=18 end=38 name=c\n" |
| 326 | 326 |
| 327 // Closure call saves current context. | 327 // Closure call saves current context. |
| 328 "_FunctionImpl.call\n" | 328 "_Closure.call\n" |
| 329 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 329 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 330 " 1 CurrentCtx scope=0 begin=0 end=0" | 330 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 331 " name=:current_context_var\n" | 331 " name=:current_context_var\n" |
| 332 | 332 |
| 333 // Outermost function neglects to save the entry context. We | 333 // Outermost function neglects to save the entry context. We |
| 334 // don't save the entry context if the function has no captured | 334 // don't save the entry context if the function has no captured |
| 335 // variables. | 335 // variables. |
| 336 "a\n" | 336 "a\n" |
| 337 " 0 CurrentCtx scope=0 begin=0 end=0" | 337 " 0 CurrentCtx scope=0 begin=0 end=0" |
| 338 " name=:current_context_var\n" | 338 " name=:current_context_var\n" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 361 EXPECT_VALID(lib); | 361 EXPECT_VALID(lib); |
| 362 | 362 |
| 363 EXPECT_STREQ( | 363 EXPECT_STREQ( |
| 364 // bb captures only value2 from aa. No others. | 364 // bb captures only value2 from aa. No others. |
| 365 "a.b.aa.bb\n" | 365 "a.b.aa.bb\n" |
| 366 " 0 ContextVar level=0 begin=33 end=43 name=value2\n" | 366 " 0 ContextVar level=0 begin=33 end=43 name=value2\n" |
| 367 " 1 CurrentCtx scope=0 begin=0 end=0" | 367 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 368 " name=:current_context_var\n" | 368 " name=:current_context_var\n" |
| 369 | 369 |
| 370 // Closure call saves current context. | 370 // Closure call saves current context. |
| 371 "_FunctionImpl.call\n" | 371 "_Closure.call\n" |
| 372 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 372 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 373 " 1 CurrentCtx scope=0 begin=0 end=0" | 373 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 374 " name=:current_context_var\n" | 374 " name=:current_context_var\n" |
| 375 | 375 |
| 376 // aa shares value2. Notice that we save the entry ctx instead | 376 // aa shares value2. Notice that we save the entry ctx instead |
| 377 // of chaining from b. This keeps us from holding onto closures | 377 // of chaining from b. This keeps us from holding onto closures |
| 378 // that we would never access. | 378 // that we would never access. |
| 379 "a.b.aa\n" | 379 "a.b.aa\n" |
| 380 " 0 CurrentCtx scope=0 begin=0 end=0" | 380 " 0 CurrentCtx scope=0 begin=0 end=0" |
| 381 " name=:current_context_var\n" | 381 " name=:current_context_var\n" |
| 382 " 1 ContextLevel level=1 scope=2 begin=22 end=52\n" | 382 " 1 ContextLevel level=1 scope=2 begin=22 end=52\n" |
| 383 " 2 ContextVar level=1 begin=28 end=52 name=value2\n" | 383 " 2 ContextVar level=1 begin=28 end=52 name=value2\n" |
| 384 " 3 StackVar scope=2 begin=30 end=52 name=bb\n" | 384 " 3 StackVar scope=2 begin=30 end=52 name=bb\n" |
| 385 | 385 |
| 386 // Closure call saves current context. | 386 // Closure call saves current context. |
| 387 "_FunctionImpl.call\n" | 387 "_Closure.call\n" |
| 388 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 388 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 389 " 1 CurrentCtx scope=0 begin=0 end=0" | 389 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 390 " name=:current_context_var\n" | 390 " name=:current_context_var\n" |
| 391 | 391 |
| 392 // b captures value1 from a. | 392 // b captures value1 from a. |
| 393 "a.b\n" | 393 "a.b\n" |
| 394 " 0 ContextVar level=0 begin=14 end=62 name=value1\n" | 394 " 0 ContextVar level=0 begin=14 end=62 name=value1\n" |
| 395 " 1 CurrentCtx scope=0 begin=0 end=0" | 395 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 396 " name=:current_context_var\n" | 396 " name=:current_context_var\n" |
| 397 " 2 StackVar scope=2 begin=18 end=62 name=aa\n" | 397 " 2 StackVar scope=2 begin=18 end=62 name=aa\n" |
| 398 | 398 |
| 399 // Closure call saves current context. | 399 // Closure call saves current context. |
| 400 "_FunctionImpl.call\n" | 400 "_Closure.call\n" |
| 401 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 401 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 402 " 1 CurrentCtx scope=0 begin=0 end=0" | 402 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 403 " name=:current_context_var\n" | 403 " name=:current_context_var\n" |
| 404 | 404 |
| 405 // a shares value1, saves entry ctx. | 405 // a shares value1, saves entry ctx. |
| 406 "a\n" | 406 "a\n" |
| 407 " 0 CurrentCtx scope=0 begin=0 end=0" | 407 " 0 CurrentCtx scope=0 begin=0 end=0" |
| 408 " name=:current_context_var\n" | 408 " name=:current_context_var\n" |
| 409 " 1 ContextLevel level=1 scope=2 begin=4 end=70\n" | 409 " 1 ContextLevel level=1 scope=2 begin=4 end=70\n" |
| 410 " 2 ContextVar level=1 begin=10 end=70 name=value1\n" | 410 " 2 ContextVar level=1 begin=10 end=70 name=value1\n" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 EXPECT_VALID(lib); | 443 EXPECT_VALID(lib); |
| 444 EXPECT_STREQ( | 444 EXPECT_STREQ( |
| 445 // This frame saves the entry context instead of chaining. Good. | 445 // This frame saves the entry context instead of chaining. Good. |
| 446 "doIt.<anonymous closure>\n" | 446 "doIt.<anonymous closure>\n" |
| 447 " 0 ContextLevel level=1 scope=1 begin=41 end=62\n" | 447 " 0 ContextLevel level=1 scope=1 begin=41 end=62\n" |
| 448 " 1 ContextVar level=1 begin=42 end=62 name=y\n" | 448 " 1 ContextVar level=1 begin=42 end=62 name=y\n" |
| 449 " 2 CurrentCtx scope=0 begin=0 end=0" | 449 " 2 CurrentCtx scope=0 begin=0 end=0" |
| 450 " name=:current_context_var\n" | 450 " name=:current_context_var\n" |
| 451 | 451 |
| 452 // Closure call saves current context. | 452 // Closure call saves current context. |
| 453 "_FunctionImpl.call\n" | 453 "_Closure.call\n" |
| 454 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 454 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 455 " 1 CurrentCtx scope=0 begin=0 end=0" | 455 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 456 " name=:current_context_var\n" | 456 " name=:current_context_var\n" |
| 457 | 457 |
| 458 "X.onX\n" | 458 "X.onX\n" |
| 459 " 0 StackVar scope=1 begin=0 end=0 name=this\n" | 459 " 0 StackVar scope=1 begin=0 end=0 name=this\n" |
| 460 " 1 CurrentCtx scope=0 begin=0 end=0" | 460 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 461 " name=:current_context_var\n" | 461 " name=:current_context_var\n" |
| 462 | 462 |
| 463 // No context is saved here since no vars are captured. | 463 // No context is saved here since no vars are captured. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 488 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 488 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 489 EXPECT_VALID(lib); | 489 EXPECT_VALID(lib); |
| 490 EXPECT_STREQ( | 490 EXPECT_STREQ( |
| 491 // inner function captures variable value. That's fine. | 491 // inner function captures variable value. That's fine. |
| 492 "outer.inner\n" | 492 "outer.inner\n" |
| 493 " 0 ContextVar level=0 begin=32 end=42 name=value\n" | 493 " 0 ContextVar level=0 begin=32 end=42 name=value\n" |
| 494 " 1 CurrentCtx scope=0 begin=0 end=0" | 494 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 495 " name=:current_context_var\n" | 495 " name=:current_context_var\n" |
| 496 | 496 |
| 497 // Closure call saves current context. | 497 // Closure call saves current context. |
| 498 "_FunctionImpl.call\n" | 498 "_Closure.call\n" |
| 499 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 499 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 500 " 1 CurrentCtx scope=0 begin=0 end=0" | 500 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 501 " name=:current_context_var\n" | 501 " name=:current_context_var\n" |
| 502 | 502 |
| 503 // The outer function saves the entry context, even though the | 503 // The outer function saves the entry context, even though the |
| 504 // captured variable is in a loop. Good. | 504 // captured variable is in a loop. Good. |
| 505 "outer\n" | 505 "outer\n" |
| 506 " 0 CurrentCtx scope=0 begin=0 end=0" | 506 " 0 CurrentCtx scope=0 begin=0 end=0" |
| 507 " name=:current_context_var\n" | 507 " name=:current_context_var\n" |
| 508 " 1 StackVar scope=3 begin=12 end=50 name=i\n" | 508 " 1 StackVar scope=3 begin=12 end=50 name=i\n" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 529 " }\n" | 529 " }\n" |
| 530 " return b();\n" | 530 " return b();\n" |
| 531 "}\n"; | 531 "}\n"; |
| 532 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 532 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 533 EXPECT_VALID(lib); | 533 EXPECT_VALID(lib); |
| 534 EXPECT_STREQ( | 534 EXPECT_STREQ( |
| 535 "a.b.c\n" | 535 "a.b.c\n" |
| 536 " 0 ContextVar level=0 begin=50 end=62 name=x\n" | 536 " 0 ContextVar level=0 begin=50 end=62 name=x\n" |
| 537 " 1 CurrentCtx scope=0 begin=0 end=0" | 537 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 538 " name=:current_context_var\n" | 538 " name=:current_context_var\n" |
| 539 "_FunctionImpl.call\n" | 539 "_Closure.call\n" |
| 540 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 540 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 541 " 1 CurrentCtx scope=0 begin=0 end=0" | 541 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 542 " name=:current_context_var\n" | 542 " name=:current_context_var\n" |
| 543 | 543 |
| 544 // Doesn't save the entry context. Chains to parent instead. | 544 // Doesn't save the entry context. Chains to parent instead. |
| 545 "a.b\n" | 545 "a.b\n" |
| 546 " 0 ContextVar level=0 begin=12 end=71 name=x\n" | 546 " 0 ContextVar level=0 begin=12 end=71 name=x\n" |
| 547 " 1 CurrentCtx scope=0 begin=0 end=0" | 547 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 548 " name=:current_context_var\n" | 548 " name=:current_context_var\n" |
| 549 " 2 StackVar scope=2 begin=47 end=71 name=c\n" | 549 " 2 StackVar scope=2 begin=47 end=71 name=c\n" |
| 550 " 3 ContextLevel level=1 scope=3 begin=18 end=47\n" | 550 " 3 ContextLevel level=1 scope=3 begin=18 end=47\n" |
| 551 " 4 ContextVar level=1 begin=22 end=47 name=i\n" | 551 " 4 ContextVar level=1 begin=22 end=47 name=i\n" |
| 552 " 5 StackVar scope=4 begin=32 end=47 name=d\n" | 552 " 5 StackVar scope=4 begin=32 end=47 name=d\n" |
| 553 | 553 |
| 554 "_FunctionImpl.call\n" | 554 "_Closure.call\n" |
| 555 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 555 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 556 " 1 CurrentCtx scope=0 begin=0 end=0" | 556 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 557 " name=:current_context_var\n" | 557 " name=:current_context_var\n" |
| 558 | 558 |
| 559 "a\n" | 559 "a\n" |
| 560 " 0 CurrentCtx scope=0 begin=0 end=0" | 560 " 0 CurrentCtx scope=0 begin=0 end=0" |
| 561 " name=:current_context_var\n" | 561 " name=:current_context_var\n" |
| 562 " 1 ContextLevel level=1 scope=2 begin=3 end=79\n" | 562 " 1 ContextLevel level=1 scope=2 begin=3 end=79\n" |
| 563 " 2 ContextVar level=1 begin=9 end=79 name=x\n" | 563 " 2 ContextVar level=1 begin=9 end=79 name=x\n" |
| 564 " 3 StackVar scope=2 begin=11 end=79 name=b\n", | 564 " 3 StackVar scope=2 begin=11 end=79 name=b\n", |
| 565 CaptureVarsAtLine(lib, "a", 10)); | 565 CaptureVarsAtLine(lib, "a", 10)); |
| 566 } | 566 } |
| 567 | 567 |
| 568 } // namespace dart | 568 } // namespace dart |
| OLD | NEW |