OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 } | 1008 } |
1009 | 1009 |
1010 if (result_saved) { | 1010 if (result_saved) { |
1011 ApplyTOS(context_); | 1011 ApplyTOS(context_); |
1012 } else { | 1012 } else { |
1013 Apply(context_, rax); | 1013 Apply(context_, rax); |
1014 } | 1014 } |
1015 } | 1015 } |
1016 | 1016 |
1017 | 1017 |
| 1018 void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
| 1019 Comment cmnt(masm_, "[ Assignment"); |
| 1020 ASSERT(expr->op() != Token::INIT_CONST); |
| 1021 // Left-hand side can only be a property, a global or a (parameter or local) |
| 1022 // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 1023 enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1024 LhsKind assign_type = VARIABLE; |
| 1025 Property* prop = expr->target()->AsProperty(); |
| 1026 if (prop != NULL) { |
| 1027 assign_type = |
| 1028 (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; |
| 1029 } |
| 1030 |
| 1031 // Evaluate LHS expression. |
| 1032 switch (assign_type) { |
| 1033 case VARIABLE: |
| 1034 // Nothing to do here. |
| 1035 break; |
| 1036 case NAMED_PROPERTY: |
| 1037 if (expr->is_compound()) { |
| 1038 // We need the receiver both on the stack and in the accumulator. |
| 1039 VisitForValue(prop->obj(), kAccumulator); |
| 1040 __ push(result_register()); |
| 1041 } else { |
| 1042 VisitForValue(prop->obj(), kStack); |
| 1043 } |
| 1044 break; |
| 1045 case KEYED_PROPERTY: |
| 1046 VisitForValue(prop->obj(), kStack); |
| 1047 VisitForValue(prop->key(), kStack); |
| 1048 break; |
| 1049 } |
| 1050 |
| 1051 // If we have a compound assignment: Get value of LHS expression and |
| 1052 // store in on top of the stack. |
| 1053 if (expr->is_compound()) { |
| 1054 Location saved_location = location_; |
| 1055 location_ = kStack; |
| 1056 switch (assign_type) { |
| 1057 case VARIABLE: |
| 1058 EmitVariableLoad(expr->target()->AsVariableProxy()->var(), |
| 1059 Expression::kValue); |
| 1060 break; |
| 1061 case NAMED_PROPERTY: |
| 1062 EmitNamedPropertyLoad(prop); |
| 1063 __ push(result_register()); |
| 1064 break; |
| 1065 case KEYED_PROPERTY: |
| 1066 EmitKeyedPropertyLoad(prop); |
| 1067 __ push(result_register()); |
| 1068 break; |
| 1069 } |
| 1070 location_ = saved_location; |
| 1071 } |
| 1072 |
| 1073 // Evaluate RHS expression. |
| 1074 Expression* rhs = expr->value(); |
| 1075 VisitForValue(rhs, kAccumulator); |
| 1076 |
| 1077 // If we have a compound assignment: Apply operator. |
| 1078 if (expr->is_compound()) { |
| 1079 Location saved_location = location_; |
| 1080 location_ = kAccumulator; |
| 1081 EmitBinaryOp(expr->binary_op(), Expression::kValue); |
| 1082 location_ = saved_location; |
| 1083 } |
| 1084 |
| 1085 // Record source position before possible IC call. |
| 1086 SetSourcePosition(expr->position()); |
| 1087 |
| 1088 // Store the value. |
| 1089 switch (assign_type) { |
| 1090 case VARIABLE: |
| 1091 EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
| 1092 context_); |
| 1093 break; |
| 1094 case NAMED_PROPERTY: |
| 1095 EmitNamedPropertyAssignment(expr); |
| 1096 break; |
| 1097 case KEYED_PROPERTY: |
| 1098 EmitKeyedPropertyAssignment(expr); |
| 1099 break; |
| 1100 } |
| 1101 } |
| 1102 |
| 1103 |
1018 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { | 1104 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
1019 SetSourcePosition(prop->position()); | 1105 SetSourcePosition(prop->position()); |
1020 Literal* key = prop->key()->AsLiteral(); | 1106 Literal* key = prop->key()->AsLiteral(); |
1021 __ Move(rcx, key->handle()); | 1107 __ Move(rcx, key->handle()); |
1022 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); | 1108 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
1023 __ Call(ic, RelocInfo::CODE_TARGET); | 1109 __ Call(ic, RelocInfo::CODE_TARGET); |
1024 __ nop(); | 1110 __ nop(); |
1025 } | 1111 } |
1026 | 1112 |
1027 | 1113 |
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1896 __ movq(Operand(rsp, 0), rdx); | 1982 __ movq(Operand(rsp, 0), rdx); |
1897 // And return. | 1983 // And return. |
1898 __ ret(0); | 1984 __ ret(0); |
1899 } | 1985 } |
1900 | 1986 |
1901 | 1987 |
1902 #undef __ | 1988 #undef __ |
1903 | 1989 |
1904 | 1990 |
1905 } } // namespace v8::internal | 1991 } } // namespace v8::internal |
OLD | NEW |