Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: runtime/vm/parser.cc

Issue 484933003: Await it! (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/ast_transformer.h" 9 #include "vm/ast_transformer.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 5408 matching lines...) Expand 10 before | Expand all | Expand 10 after
5419 current_block_->scope->function_level() + 1, 5419 current_block_->scope->function_level() + 1,
5420 0); 5420 0);
5421 } 5421 }
5422 ChainNewBlock(outer_scope); 5422 ChainNewBlock(outer_scope);
5423 } 5423 }
5424 5424
5425 5425
5426 void Parser::OpenAsyncClosure() { 5426 void Parser::OpenAsyncClosure() {
5427 TRACE_PARSER("OpenAsyncClosure"); 5427 TRACE_PARSER("OpenAsyncClosure");
5428 parsed_function()->set_await_temps_scope(current_block_->scope); 5428 parsed_function()->set_await_temps_scope(current_block_->scope);
5429 // TODO(mlippautz): Set up explicit jump table for await continuations.
5430 } 5429 }
5431 5430
5432 5431
5433 RawFunction* Parser::OpenAsyncFunction(intptr_t formal_param_pos) { 5432 RawFunction* Parser::OpenAsyncFunction(intptr_t formal_param_pos) {
5434 TRACE_PARSER("OpenAsyncFunction"); 5433 TRACE_PARSER("OpenAsyncFunction");
5435 // Create the closure containing the old body of this function. 5434 // Create the closure containing the old body of this function.
5436 Class& sig_cls = Class::ZoneHandle(I); 5435 Class& sig_cls = Class::ZoneHandle(I);
5437 Type& sig_type = Type::ZoneHandle(I); 5436 Type& sig_type = Type::ZoneHandle(I);
5438 Function& closure = Function::ZoneHandle(I); 5437 Function& closure = Function::ZoneHandle(I);
5439 String& sig = String::ZoneHandle(I); 5438 String& sig = String::ZoneHandle(I);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
5516 const Class& completer = Class::ZoneHandle(I, 5515 const Class& completer = Class::ZoneHandle(I,
5517 GetClassForAsync(Symbols::Completer())); 5516 GetClassForAsync(Symbols::Completer()));
5518 ASSERT(!completer.IsNull()); 5517 ASSERT(!completer.IsNull());
5519 const Function& completer_constructor = Function::ZoneHandle(I, 5518 const Function& completer_constructor = Function::ZoneHandle(I,
5520 completer.LookupFunction(Symbols::CompleterConstructor())); 5519 completer.LookupFunction(Symbols::CompleterConstructor()));
5521 ASSERT(!completer_constructor.IsNull()); 5520 ASSERT(!completer_constructor.IsNull());
5522 5521
5523 // Add to AST: 5522 // Add to AST:
5524 // var :async_op; 5523 // var :async_op;
5525 // var :async_completer; 5524 // var :async_completer;
5525 // var :await_jump_var;
5526 // var :await_ctx_var;
5526 LocalVariable* async_op_var = new (I) LocalVariable( 5527 LocalVariable* async_op_var = new (I) LocalVariable(
5527 Scanner::kNoSourcePos, 5528 Scanner::kNoSourcePos,
5528 Symbols::AsyncOperation(), 5529 Symbols::AsyncOperation(),
5529 Type::ZoneHandle(I, Type::DynamicType())); 5530 Type::ZoneHandle(I, Type::DynamicType()));
5530 current_block_->scope->AddVariable(async_op_var); 5531 current_block_->scope->AddVariable(async_op_var);
5531 found = closure_body->scope()->CaptureVariable(Symbols::AsyncOperation()); 5532 found = closure_body->scope()->CaptureVariable(Symbols::AsyncOperation());
5532 ASSERT(found); 5533 ASSERT(found);
5533 LocalVariable* async_completer = new (I) LocalVariable( 5534 LocalVariable* async_completer = new (I) LocalVariable(
5534 Scanner::kNoSourcePos, 5535 Scanner::kNoSourcePos,
5535 Symbols::AsyncCompleter(), 5536 Symbols::AsyncCompleter(),
5536 Type::ZoneHandle(I, Type::DynamicType())); 5537 Type::ZoneHandle(I, Type::DynamicType()));
5537 current_block_->scope->AddVariable(async_completer); 5538 current_block_->scope->AddVariable(async_completer);
5538 found = closure_body->scope()->CaptureVariable(Symbols::AsyncCompleter()); 5539 found = closure_body->scope()->CaptureVariable(Symbols::AsyncCompleter());
5539 ASSERT(found); 5540 ASSERT(found);
5541 LocalVariable* await_jump_var = new (I) LocalVariable(
5542 Scanner::kNoSourcePos,
5543 Symbols::AwaitJumpVar(),
5544 Type::ZoneHandle(I, Type::DynamicType()));
5545 current_block_->scope->AddVariable(await_jump_var);
5546 found = closure_body->scope()->CaptureVariable(Symbols::AwaitJumpVar());
5547 ASSERT(found);
5548 LocalVariable* await_ctx_var = new (I) LocalVariable(
5549 Scanner::kNoSourcePos,
5550 Symbols::AwaitContextVar(),
5551 Type::ZoneHandle(I, Type::DynamicType()));
5552 current_block_->scope->AddVariable(await_ctx_var);
5553 found = closure_body->scope()->CaptureVariable(Symbols::AwaitContextVar());
5554 ASSERT(found);
5540 5555
5541 // Add to AST: 5556 // Add to AST:
5542 // :async_completer = new Completer(); 5557 // :async_completer = new Completer();
5543 ArgumentListNode* empty_args = new (I) ArgumentListNode( 5558 ArgumentListNode* empty_args =
5544 Scanner::kNoSourcePos); 5559 new (I) ArgumentListNode(Scanner::kNoSourcePos);
5545 ConstructorCallNode* completer_constructor_node = new (I) ConstructorCallNode( 5560 ConstructorCallNode* completer_constructor_node = new (I) ConstructorCallNode(
5546 Scanner::kNoSourcePos, 5561 Scanner::kNoSourcePos,
5547 TypeArguments::ZoneHandle(I), 5562 TypeArguments::ZoneHandle(I),
5548 completer_constructor, 5563 completer_constructor,
5549 empty_args); 5564 empty_args);
5550 StoreLocalNode* store_completer = new (I) StoreLocalNode( 5565 StoreLocalNode* store_completer = new (I) StoreLocalNode(
5551 Scanner::kNoSourcePos, 5566 Scanner::kNoSourcePos,
5552 async_completer, 5567 async_completer,
5553 completer_constructor_node); 5568 completer_constructor_node);
5554 current_block_->statements->Add(store_completer); 5569 current_block_->statements->Add(store_completer);
(...skipping 30 matching lines...) Expand all
5585 Symbols::CompleterFuture())); 5600 Symbols::CompleterFuture()));
5586 current_block_->statements->Add(return_node); 5601 current_block_->statements->Add(return_node);
5587 return CloseBlock(); 5602 return CloseBlock();
5588 } 5603 }
5589 5604
5590 5605
5591 void Parser::CloseAsyncClosure(SequenceNode* body) { 5606 void Parser::CloseAsyncClosure(SequenceNode* body) {
5592 TRACE_PARSER("CloseAsyncClosure"); 5607 TRACE_PARSER("CloseAsyncClosure");
5593 // We need a temporary expression to store intermediate return values. 5608 // We need a temporary expression to store intermediate return values.
5594 parsed_function()->EnsureExpressionTemp(); 5609 parsed_function()->EnsureExpressionTemp();
5610 // Implicitly mark those variables below as captured. We currently mark all
5611 // variables of all scopes as captured (below), but as soon as we do something
5612 // smarter we rely on these internal variables to be available.
5613 body->scope()->LookupVariable(Symbols::Completer(), false);
5614 body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false);
5615 body->scope()->LookupVariable(Symbols::AwaitContextVar(), false);
5616 body->scope()->RecursivelyCaptureAllVariables();
5595 } 5617 }
5596 5618
5597 5619
5598 // Set up default values for all optional parameters to the function. 5620 // Set up default values for all optional parameters to the function.
5599 void Parser::SetupDefaultsForOptionalParams(const ParamList* params, 5621 void Parser::SetupDefaultsForOptionalParams(const ParamList* params,
5600 Array* default_values) { 5622 Array* default_values) {
5601 if (params->num_optional_parameters > 0) { 5623 if (params->num_optional_parameters > 0) {
5602 // Build array of default parameter values. 5624 // Build array of default parameter values.
5603 ParamDesc* param = 5625 ParamDesc* param =
5604 params->parameters->data() + params->num_fixed_parameters; 5626 params->parameters->data() + params->num_fixed_parameters;
(...skipping 5653 matching lines...) Expand 10 before | Expand all | Expand 10 after
11258 void Parser::SkipQualIdent() { 11280 void Parser::SkipQualIdent() {
11259 ASSERT(IsIdentifier()); 11281 ASSERT(IsIdentifier());
11260 ConsumeToken(); 11282 ConsumeToken();
11261 if (CurrentToken() == Token::kPERIOD) { 11283 if (CurrentToken() == Token::kPERIOD) {
11262 ConsumeToken(); // Consume the kPERIOD token. 11284 ConsumeToken(); // Consume the kPERIOD token.
11263 ExpectIdentifier("identifier expected after '.'"); 11285 ExpectIdentifier("identifier expected after '.'");
11264 } 11286 }
11265 } 11287 }
11266 11288
11267 } // namespace dart 11289 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698