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

Side by Side Diff: src/fast-codegen.cc

Issue 486008: Adding compound assignments to the top-level compiler. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years 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 | « src/fast-codegen.h ('k') | src/ia32/fast-codegen-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 493
494 494
495 void FastCodeGenerator::VisitLiteral(Literal* expr) { 495 void FastCodeGenerator::VisitLiteral(Literal* expr) {
496 Comment cmnt(masm_, "[ Literal"); 496 Comment cmnt(masm_, "[ Literal");
497 Move(expr->context(), expr); 497 Move(expr->context(), expr);
498 } 498 }
499 499
500 500
501 void FastCodeGenerator::VisitAssignment(Assignment* expr) { 501 void FastCodeGenerator::VisitAssignment(Assignment* expr) {
502 Comment cmnt(masm_, "[ Assignment"); 502 Comment cmnt(masm_, "[ Assignment");
503 ASSERT(expr->op() == Token::ASSIGN || expr->op() == Token::INIT_VAR);
504 503
505 // Record source code position of the (possible) IC call. 504 // Record source code position of the (possible) IC call.
506 SetSourcePosition(expr->position()); 505 SetSourcePosition(expr->position());
507 506
508 // Left-hand side can only be a property, a global or a (parameter or local) 507 // Left-hand side can only be a property, a global or a (parameter or local)
509 // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. 508 // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY.
510 enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; 509 enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
511 LhsKind assign_type = VARIABLE; 510 LhsKind assign_type = VARIABLE;
512 Property* prop = expr->target()->AsProperty(); 511 Property* prop = expr->target()->AsProperty();
513 // In case of a property we use the uninitialized expression context 512 // In case of a property we use the uninitialized expression context
514 // of the key to detect a named property. 513 // of the key to detect a named property.
515 if (prop != NULL) { 514 if (prop != NULL) {
516 assign_type = (prop->key()->context() == Expression::kUninitialized) 515 assign_type = (prop->key()->context() == Expression::kUninitialized)
517 ? NAMED_PROPERTY 516 ? NAMED_PROPERTY
518 : KEYED_PROPERTY; 517 : KEYED_PROPERTY;
519 } 518 }
520 519
521 Expression* rhs = expr->value(); 520 // Evaluate LHS expression.
522 ASSERT_EQ(Expression::kValue, rhs->context());
523
524 switch (assign_type) { 521 switch (assign_type) {
525 case VARIABLE: 522 case VARIABLE:
526 Visit(rhs); 523 // Nothing to do here.
527 EmitVariableAssignment(expr);
528 break; 524 break;
529 case NAMED_PROPERTY: 525 case NAMED_PROPERTY:
530 Visit(prop->obj()); 526 Visit(prop->obj());
531 ASSERT_EQ(Expression::kValue, prop->obj()->context()); 527 ASSERT_EQ(Expression::kValue, prop->obj()->context());
532 Visit(rhs);
533 EmitNamedPropertyAssignment(expr);
534 break; 528 break;
535 case KEYED_PROPERTY: 529 case KEYED_PROPERTY:
536 Visit(prop->obj()); 530 Visit(prop->obj());
537 ASSERT_EQ(Expression::kValue, prop->obj()->context()); 531 ASSERT_EQ(Expression::kValue, prop->obj()->context());
538 Visit(prop->key()); 532 Visit(prop->key());
539 ASSERT_EQ(Expression::kValue, prop->key()->context()); 533 ASSERT_EQ(Expression::kValue, prop->key()->context());
540 Visit(rhs); 534 break;
535 }
536
537 // If we have a compound assignment: Get value of LHS expression and
538 // store in on top of the stack.
539 // Note: Relies on kValue context being 'stack'.
540 if (expr->is_compound()) {
541 switch (assign_type) {
542 case VARIABLE:
543 EmitVariableLoad(expr->target()->AsVariableProxy()->var(),
544 Expression::kValue);
545 break;
546 case NAMED_PROPERTY:
547 EmitNamedPropertyLoad(prop, Expression::kValue);
548 break;
549 case KEYED_PROPERTY:
550 EmitKeyedPropertyLoad(Expression::kValue);
551 break;
552 }
553 }
554
555 // Evaluate RHS expression.
556 Expression* rhs = expr->value();
557 ASSERT_EQ(Expression::kValue, rhs->context());
558 Visit(rhs);
559
560 // If we have a compount assignment: Apply operator.
561 if (expr->is_compound()) {
562 EmitCompoundAssignmentOp(expr->binary_op(), Expression::kValue);
563 }
564
565 // Store the value.
566 switch (assign_type) {
567 case VARIABLE:
568 EmitVariableAssignment(expr);
569 break;
570 case NAMED_PROPERTY:
571 EmitNamedPropertyAssignment(expr);
572 break;
573 case KEYED_PROPERTY:
541 EmitKeyedPropertyAssignment(expr); 574 EmitKeyedPropertyAssignment(expr);
542 break; 575 break;
543 } 576 }
544 } 577 }
545 578
546 579
547 void FastCodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* expr) { 580 void FastCodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* expr) {
548 UNREACHABLE(); 581 UNREACHABLE();
549 } 582 }
550 583
551 584
552 void FastCodeGenerator::VisitThrow(Throw* expr) { 585 void FastCodeGenerator::VisitThrow(Throw* expr) {
553 UNREACHABLE(); 586 UNREACHABLE();
554 } 587 }
555 588
556 589
557 #undef __ 590 #undef __
558 591
559 592
560 } } // namespace v8::internal 593 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/fast-codegen.h ('k') | src/ia32/fast-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698