OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "vm/parser.h" | 5 #include "vm/parser.h" |
6 #include "vm/flags.h" | 6 #include "vm/flags.h" |
7 | 7 |
8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
9 | 9 |
10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
(...skipping 7496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7507 existing_var = | 7507 existing_var = |
7508 closure_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false); | 7508 closure_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false); |
7509 ASSERT((existing_var != NULL) && existing_var->is_captured()); | 7509 ASSERT((existing_var != NULL) && existing_var->is_captured()); |
7510 existing_var = | 7510 existing_var = |
7511 closure_body->scope()->LookupVariable(Symbols::AsyncCompleter(), false); | 7511 closure_body->scope()->LookupVariable(Symbols::AsyncCompleter(), false); |
7512 ASSERT((existing_var != NULL) && existing_var->is_captured()); | 7512 ASSERT((existing_var != NULL) && existing_var->is_captured()); |
7513 existing_var = closure_body->scope()->LookupVariable( | 7513 existing_var = closure_body->scope()->LookupVariable( |
7514 Symbols::AsyncStackTraceVar(), false); | 7514 Symbols::AsyncStackTraceVar(), false); |
7515 ASSERT((existing_var != NULL) && existing_var->is_captured()); | 7515 ASSERT((existing_var != NULL) && existing_var->is_captured()); |
7516 | 7516 |
7517 // Create and return a new future that executes a closure with the current | 7517 // Create and return a new _AsyncAwaitCompleter that executes a closure with |
7518 // body. | 7518 // the current body. |
7519 | 7519 |
7520 // No need to capture parameters or other variables, since they have already | 7520 // No need to capture parameters or other variables, since they have already |
7521 // been captured in the corresponding scope as the body has been parsed within | 7521 // been captured in the corresponding scope as the body has been parsed within |
7522 // a nested block (contained in the async function's block). | 7522 // a nested block (contained in the async function's block). |
7523 const Class& future = Class::ZoneHandle(Z, I->object_store()->future_class()); | 7523 |
7524 ASSERT(!future.IsNull()); | 7524 const Library& async_lib = Library::Handle(Library::AsyncLibrary()); |
7525 const Function& constructor = Function::ZoneHandle( | 7525 |
7526 Z, future.LookupFunction(Symbols::FutureMicrotask())); | 7526 const Class& completer_class = Class::Handle( |
7527 ASSERT(!constructor.IsNull()); | 7527 Z, async_lib.LookupClassAllowPrivate(Symbols::_AsyncAwaitCompleter())); |
7528 const Class& completer = | 7528 ASSERT(!completer_class.IsNull()); |
7529 Class::ZoneHandle(Z, I->object_store()->completer_class()); | 7529 const Function& completer_constructor = |
7530 ASSERT(!completer.IsNull()); | 7530 Function::ZoneHandle(Z, completer_class.LookupConstructorAllowPrivate( |
7531 const Function& completer_constructor = Function::ZoneHandle( | 7531 Symbols::_AsyncAwaitCompleterConstructor())); |
7532 Z, completer.LookupFunction(Symbols::CompleterSyncConstructor())); | |
7533 ASSERT(!completer_constructor.IsNull()); | 7532 ASSERT(!completer_constructor.IsNull()); |
7534 | 7533 |
7535 LocalVariable* async_completer = | 7534 LocalVariable* async_completer = |
7536 current_block_->scope->LookupVariable(Symbols::AsyncCompleter(), false); | 7535 current_block_->scope->LookupVariable(Symbols::AsyncCompleter(), false); |
7537 | 7536 |
7538 const TokenPosition token_pos = ST(closure_body->token_pos()); | 7537 const TokenPosition token_pos = ST(closure_body->token_pos()); |
7539 // Add to AST: | 7538 // Add to AST: |
7540 // :async_completer = new Completer.sync(); | 7539 // :async_completer = new Completer.sync(); |
7541 ArgumentListNode* empty_args = new (Z) ArgumentListNode(token_pos); | 7540 ArgumentListNode* empty_args = new (Z) ArgumentListNode(token_pos); |
7542 ConstructorCallNode* completer_constructor_node = | 7541 ConstructorCallNode* completer_constructor_node = |
(...skipping 14 matching lines...) Expand all Loading... |
7557 // Add to AST: | 7556 // Add to AST: |
7558 // :async_op = <closure>; (containing the original body) | 7557 // :async_op = <closure>; (containing the original body) |
7559 LocalVariable* async_op_var = | 7558 LocalVariable* async_op_var = |
7560 current_block_->scope->LookupVariable(Symbols::AsyncOperation(), false); | 7559 current_block_->scope->LookupVariable(Symbols::AsyncOperation(), false); |
7561 ClosureNode* cn = | 7560 ClosureNode* cn = |
7562 new (Z) ClosureNode(token_pos, closure, NULL, closure_body->scope()); | 7561 new (Z) ClosureNode(token_pos, closure, NULL, closure_body->scope()); |
7563 StoreLocalNode* store_async_op = | 7562 StoreLocalNode* store_async_op = |
7564 new (Z) StoreLocalNode(token_pos, async_op_var, cn); | 7563 new (Z) StoreLocalNode(token_pos, async_op_var, cn); |
7565 current_block_->statements->Add(store_async_op); | 7564 current_block_->statements->Add(store_async_op); |
7566 | 7565 |
7567 const Library& async_lib = Library::Handle(Library::AsyncLibrary()); | |
7568 | |
7569 if (FLAG_causal_async_stacks) { | 7566 if (FLAG_causal_async_stacks) { |
7570 // Add to AST: | 7567 // Add to AST: |
7571 // :async_stack_trace = _asyncStackTraceHelper(); | 7568 // :async_stack_trace = _asyncStackTraceHelper(); |
7572 const Function& async_stack_trace_helper = Function::ZoneHandle( | 7569 const Function& async_stack_trace_helper = Function::ZoneHandle( |
7573 Z, | 7570 Z, |
7574 async_lib.LookupFunctionAllowPrivate(Symbols::AsyncStackTraceHelper())); | 7571 async_lib.LookupFunctionAllowPrivate(Symbols::AsyncStackTraceHelper())); |
7575 ASSERT(!async_stack_trace_helper.IsNull()); | 7572 ASSERT(!async_stack_trace_helper.IsNull()); |
7576 ArgumentListNode* async_stack_trace_helper_args = | 7573 ArgumentListNode* async_stack_trace_helper_args = |
7577 new (Z) ArgumentListNode(token_pos); | 7574 new (Z) ArgumentListNode(token_pos); |
7578 async_stack_trace_helper_args->Add( | 7575 async_stack_trace_helper_args->Add( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7620 token_pos, async_error_wrapper_helper, async_error_wrapper_helper_args); | 7617 token_pos, async_error_wrapper_helper, async_error_wrapper_helper_args); |
7621 LocalVariable* async_catch_error_callback_var = | 7618 LocalVariable* async_catch_error_callback_var = |
7622 current_block_->scope->LookupVariable(Symbols::AsyncCatchErrorCallback(), | 7619 current_block_->scope->LookupVariable(Symbols::AsyncCatchErrorCallback(), |
7623 false); | 7620 false); |
7624 StoreLocalNode* store_async_catch_error_callback = new (Z) StoreLocalNode( | 7621 StoreLocalNode* store_async_catch_error_callback = new (Z) StoreLocalNode( |
7625 token_pos, async_catch_error_callback_var, error_wrapper_call); | 7622 token_pos, async_catch_error_callback_var, error_wrapper_call); |
7626 | 7623 |
7627 current_block_->statements->Add(store_async_catch_error_callback); | 7624 current_block_->statements->Add(store_async_catch_error_callback); |
7628 | 7625 |
7629 // Add to AST: | 7626 // Add to AST: |
7630 // new Future.microtask(:async_op); | 7627 // :async_completer.start(:async_op); |
7631 ArgumentListNode* arguments = new (Z) ArgumentListNode(token_pos); | 7628 ArgumentListNode* arguments = new (Z) ArgumentListNode(token_pos); |
7632 arguments->Add(new (Z) LoadLocalNode(token_pos, async_op_var)); | 7629 arguments->Add(new (Z) LoadLocalNode(token_pos, async_op_var)); |
7633 ConstructorCallNode* future_node = new (Z) ConstructorCallNode( | 7630 InstanceCallNode* start_call = new (Z) InstanceCallNode( |
7634 token_pos, TypeArguments::ZoneHandle(Z), constructor, arguments); | 7631 token_pos, new (Z) LoadLocalNode(token_pos, async_completer), |
7635 current_block_->statements->Add(future_node); | 7632 Symbols::_AsyncAwaitStart(), arguments); |
| 7633 current_block_->statements->Add(start_call); |
7636 | 7634 |
7637 // Add to AST: | 7635 // Add to AST: |
7638 // return :async_completer.future; | 7636 // return :async_completer.future; |
7639 ReturnNode* return_node = new (Z) ReturnNode( | 7637 ReturnNode* return_node = new (Z) ReturnNode( |
7640 token_pos, | 7638 token_pos, |
7641 new (Z) InstanceGetterNode( | 7639 new (Z) InstanceGetterNode( |
7642 token_pos, new (Z) LoadLocalNode(token_pos, async_completer), | 7640 token_pos, new (Z) LoadLocalNode(token_pos, async_completer), |
7643 Symbols::CompleterFuture())); | 7641 Symbols::CompleterFuture())); |
7644 current_block_->statements->Add(return_node); | 7642 current_block_->statements->Add(return_node); |
7645 return CloseBlock(); | 7643 return CloseBlock(); |
(...skipping 7460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15106 bool Parser::FieldHasFunctionLiteralInitializer(const Field& field, | 15104 bool Parser::FieldHasFunctionLiteralInitializer(const Field& field, |
15107 TokenPosition* start, | 15105 TokenPosition* start, |
15108 TokenPosition* end) { | 15106 TokenPosition* end) { |
15109 UNREACHABLE(); | 15107 UNREACHABLE(); |
15110 return false; | 15108 return false; |
15111 } | 15109 } |
15112 | 15110 |
15113 } // namespace dart | 15111 } // namespace dart |
15114 | 15112 |
15115 #endif // DART_PRECOMPILED_RUNTIME | 15113 #endif // DART_PRECOMPILED_RUNTIME |
OLD | NEW |