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

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

Issue 890573002: VM: Simplify dispatcher code for closure calls. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 ASSERT(desc.Count() > 0); 1425 ASSERT(desc.Count() > 0);
1426 1426
1427 // Set up scope for this function. 1427 // Set up scope for this function.
1428 BuildDispatcherScope(func, desc, default_values); 1428 BuildDispatcherScope(func, desc, default_values);
1429 1429
1430 // Receiver is local 0. 1430 // Receiver is local 0.
1431 LocalScope* scope = current_block_->scope; 1431 LocalScope* scope = current_block_->scope;
1432 ArgumentListNode* no_args = new ArgumentListNode(token_pos); 1432 ArgumentListNode* no_args = new ArgumentListNode(token_pos);
1433 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0)); 1433 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0));
1434 1434
1435 const Class& owner = Class::Handle(Z, func.Owner());
1436 ASSERT(!owner.IsNull());
1435 const String& name = String::Handle(Z, func.name()); 1437 const String& name = String::Handle(Z, func.name());
1436 const String& getter_name = String::ZoneHandle(Z, 1438 AstNode* function_object = NULL;
1437 Symbols::New(String::Handle(Z, Field::GetterName(name)))); 1439 if (owner.IsSignatureClass() && name.Equals(Symbols::Call())) {
1438 InstanceCallNode* getter_call = new(Z) InstanceCallNode( 1440 function_object = receiver;
1439 token_pos, receiver, getter_name, no_args); 1441 } else {
1442 const String& getter_name = String::ZoneHandle(Z,
1443 Symbols::New(String::Handle(Z, Field::GetterName(name))));
1444 function_object = new(Z) InstanceCallNode(
1445 token_pos, receiver, getter_name, no_args);
1446 }
1440 1447
1441 // Pass arguments 1..n to the closure call. 1448 // Pass arguments 1..n to the closure call.
1442 ArgumentListNode* args = new(Z) ArgumentListNode(token_pos); 1449 ArgumentListNode* args = new(Z) ArgumentListNode(token_pos);
1443 const Array& names = Array::Handle( 1450 const Array& names = Array::Handle(
1444 Z, Array::New(desc.NamedCount(), Heap::kOld)); 1451 Z, Array::New(desc.NamedCount(), Heap::kOld));
1445 // Positional parameters. 1452 // Positional parameters.
1446 intptr_t i = 1; 1453 intptr_t i = 1;
1447 for (; i < desc.PositionalCount(); ++i) { 1454 for (; i < desc.PositionalCount(); ++i) {
1448 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); 1455 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i)));
1449 } 1456 }
1450 // Named parameters. 1457 // Named parameters.
1451 for (; i < desc.Count(); i++) { 1458 for (; i < desc.Count(); i++) {
1452 args->Add(new(Z) LoadLocalNode(token_pos, scope->VariableAt(i))); 1459 args->Add(new(Z) LoadLocalNode(token_pos, scope->VariableAt(i)));
1453 intptr_t index = i - desc.PositionalCount(); 1460 intptr_t index = i - desc.PositionalCount();
1454 names.SetAt(index, String::Handle(Z, desc.NameAt(index))); 1461 names.SetAt(index, String::Handle(Z, desc.NameAt(index)));
1455 } 1462 }
1456 args->set_names(names); 1463 args->set_names(names);
1457 1464
1458 const Class& owner = Class::Handle(Z, func.Owner());
1459 ASSERT(!owner.IsNull());
1460 AstNode* result = NULL; 1465 AstNode* result = NULL;
1461 if (owner.IsSignatureClass() && name.Equals(Symbols::Call())) { 1466 if (owner.IsSignatureClass() && name.Equals(Symbols::Call())) {
1462 result = new ClosureCallNode(token_pos, getter_call, args); 1467 result = new ClosureCallNode(token_pos, function_object, args);
1463 } else { 1468 } else {
1464 result = BuildClosureCall(token_pos, getter_call, args); 1469 result = BuildClosureCall(token_pos, function_object, args);
1465 } 1470 }
1466 1471
1467 ReturnNode* return_node = new ReturnNode(token_pos, result); 1472 ReturnNode* return_node = new ReturnNode(token_pos, result);
1468 current_block_->statements->Add(return_node); 1473 current_block_->statements->Add(return_node);
1469 return CloseBlock(); 1474 return CloseBlock();
1470 } 1475 }
1471 1476
1472 1477
1473 AstNode* Parser::BuildClosureCall(intptr_t token_pos, 1478 AstNode* Parser::BuildClosureCall(intptr_t token_pos,
1474 AstNode* closure, 1479 AstNode* closure,
(...skipping 10749 matching lines...) Expand 10 before | Expand all | Expand 10 after
12224 void Parser::SkipQualIdent() { 12229 void Parser::SkipQualIdent() {
12225 ASSERT(IsIdentifier()); 12230 ASSERT(IsIdentifier());
12226 ConsumeToken(); 12231 ConsumeToken();
12227 if (CurrentToken() == Token::kPERIOD) { 12232 if (CurrentToken() == Token::kPERIOD) {
12228 ConsumeToken(); // Consume the kPERIOD token. 12233 ConsumeToken(); // Consume the kPERIOD token.
12229 ExpectIdentifier("identifier expected after '.'"); 12234 ExpectIdentifier("identifier expected after '.'");
12230 } 12235 }
12231 } 12236 }
12232 12237
12233 } // namespace dart 12238 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698