| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
| 6 | 6 |
| 7 #include <stack> | 7 #include <stack> |
| 8 | 8 |
| 9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
| 10 #include "src/objects.h" | 10 #include "src/objects.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 if (scope()->is_function_scope() && scope()->function() != NULL) { | 38 if (scope()->is_function_scope() && scope()->function() != NULL) { |
| 39 VisitVariableDeclaration(scope()->function()); | 39 VisitVariableDeclaration(scope()->function()); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Visit declarations within the function scope. | 42 // Visit declarations within the function scope. |
| 43 VisitDeclarations(scope()->declarations()); | 43 VisitDeclarations(scope()->declarations()); |
| 44 | 44 |
| 45 // Visit statements in the function body. | 45 // Visit statements in the function body. |
| 46 VisitStatements(info->literal()->body()); | 46 VisitStatements(info->literal()->body()); |
| 47 | 47 |
| 48 // If the last bytecode wasn't a return, then return 'undefined' to avoid |
| 49 // falling off the end. |
| 50 if (!builder_.HasExplicitReturn()) { |
| 51 builder_.LoadUndefined(); |
| 52 builder_.Return(); |
| 53 } |
| 54 |
| 48 set_scope(nullptr); | 55 set_scope(nullptr); |
| 49 set_info(nullptr); | 56 set_info(nullptr); |
| 50 return builder_.ToBytecodeArray(); | 57 return builder_.ToBytecodeArray(); |
| 51 } | 58 } |
| 52 | 59 |
| 53 | 60 |
| 54 void BytecodeGenerator::VisitBlock(Block* node) { | 61 void BytecodeGenerator::VisitBlock(Block* node) { |
| 55 if (node->scope() == NULL) { | 62 if (node->scope() == NULL) { |
| 56 // Visit statements in the same scope, no declarations. | 63 // Visit statements in the same scope, no declarations. |
| 57 VisitStatements(node->statements()); | 64 VisitStatements(node->statements()); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 case VariableLocation::UNALLOCATED: | 263 case VariableLocation::UNALLOCATED: |
| 257 case VariableLocation::CONTEXT: | 264 case VariableLocation::CONTEXT: |
| 258 case VariableLocation::LOOKUP: | 265 case VariableLocation::LOOKUP: |
| 259 UNIMPLEMENTED(); | 266 UNIMPLEMENTED(); |
| 260 } | 267 } |
| 261 } | 268 } |
| 262 | 269 |
| 263 | 270 |
| 264 void BytecodeGenerator::VisitAssignment(Assignment* expr) { | 271 void BytecodeGenerator::VisitAssignment(Assignment* expr) { |
| 265 DCHECK(expr->target()->IsValidReferenceExpression()); | 272 DCHECK(expr->target()->IsValidReferenceExpression()); |
| 273 TemporaryRegisterScope temporary_register_scope(&builder_); |
| 274 Register object, key; |
| 266 | 275 |
| 267 // Left-hand side can only be a property, a global or a variable slot. | 276 // Left-hand side can only be a property, a global or a variable slot. |
| 268 Property* property = expr->target()->AsProperty(); | 277 Property* property = expr->target()->AsProperty(); |
| 269 LhsKind assign_type = Property::GetAssignType(property); | 278 LhsKind assign_type = Property::GetAssignType(property); |
| 270 | 279 |
| 271 DCHECK(!expr->is_compound()); | 280 // Evaluate LHS expression. |
| 272 Visit(expr->value()); | 281 switch (assign_type) { |
| 282 case VARIABLE: |
| 283 // Nothing to do to evaluate variable assignment LHS. |
| 284 break; |
| 285 case NAMED_PROPERTY: |
| 286 object = temporary_register_scope.NewRegister(); |
| 287 key = temporary_register_scope.NewRegister(); |
| 288 Visit(property->obj()); |
| 289 builder().StoreAccumulatorInRegister(object); |
| 290 builder().LoadLiteral(property->key()->AsLiteral()->AsPropertyName()); |
| 291 builder().StoreAccumulatorInRegister(key); |
| 292 break; |
| 293 case KEYED_PROPERTY: |
| 294 object = temporary_register_scope.NewRegister(); |
| 295 key = temporary_register_scope.NewRegister(); |
| 296 Visit(property->obj()); |
| 297 builder().StoreAccumulatorInRegister(object); |
| 298 Visit(property->key()); |
| 299 builder().StoreAccumulatorInRegister(key); |
| 300 break; |
| 301 case NAMED_SUPER_PROPERTY: |
| 302 case KEYED_SUPER_PROPERTY: |
| 303 UNIMPLEMENTED(); |
| 304 } |
| 273 | 305 |
| 306 // Evaluate the value and potentially handle compound assignments by loading |
| 307 // the left-hand side value and performing a binary operation. |
| 308 if (expr->is_compound()) { |
| 309 UNIMPLEMENTED(); |
| 310 } else { |
| 311 Visit(expr->value()); |
| 312 } |
| 313 |
| 314 // Store the value. |
| 315 FeedbackVectorICSlot slot = expr->AssignmentSlot(); |
| 274 switch (assign_type) { | 316 switch (assign_type) { |
| 275 case VARIABLE: { | 317 case VARIABLE: { |
| 276 Variable* variable = expr->target()->AsVariableProxy()->var(); | 318 Variable* variable = expr->target()->AsVariableProxy()->var(); |
| 277 DCHECK(variable->location() == VariableLocation::LOCAL); | 319 DCHECK(variable->location() == VariableLocation::LOCAL); |
| 278 Register destination(variable->index()); | 320 Register destination(variable->index()); |
| 279 builder().StoreAccumulatorInRegister(destination); | 321 builder().StoreAccumulatorInRegister(destination); |
| 280 break; | 322 break; |
| 281 } | 323 } |
| 282 case NAMED_PROPERTY: | 324 case NAMED_PROPERTY: |
| 325 builder().StoreNamedProperty(object, key, feedback_index(slot), |
| 326 language_mode()); |
| 327 break; |
| 283 case KEYED_PROPERTY: | 328 case KEYED_PROPERTY: |
| 329 builder().StoreKeyedProperty(object, key, feedback_index(slot), |
| 330 language_mode()); |
| 331 break; |
| 284 case NAMED_SUPER_PROPERTY: | 332 case NAMED_SUPER_PROPERTY: |
| 285 case KEYED_SUPER_PROPERTY: | 333 case KEYED_SUPER_PROPERTY: |
| 286 UNIMPLEMENTED(); | 334 UNIMPLEMENTED(); |
| 287 } | 335 } |
| 288 } | 336 } |
| 289 | 337 |
| 290 | 338 |
| 291 void BytecodeGenerator::VisitYield(Yield* expr) { UNIMPLEMENTED(); } | 339 void BytecodeGenerator::VisitYield(Yield* expr) { UNIMPLEMENTED(); } |
| 292 | 340 |
| 293 | 341 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 } | 456 } |
| 409 | 457 |
| 410 | 458 |
| 411 int BytecodeGenerator::feedback_index(FeedbackVectorICSlot slot) const { | 459 int BytecodeGenerator::feedback_index(FeedbackVectorICSlot slot) const { |
| 412 return info()->feedback_vector()->GetIndex(slot); | 460 return info()->feedback_vector()->GetIndex(slot); |
| 413 } | 461 } |
| 414 | 462 |
| 415 } // namespace interpreter | 463 } // namespace interpreter |
| 416 } // namespace internal | 464 } // namespace internal |
| 417 } // namespace v8 | 465 } // namespace v8 |
| OLD | NEW |