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

Side by Side Diff: src/interpreter/bytecode-generator.cc

Issue 1400753003: [Interpreter] Add array literal support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_literal
Patch Set: Rebase Created 5 years, 2 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
« no previous file with comments | « src/interpreter/bytecode-array-builder.cc ('k') | src/interpreter/bytecodes.h » ('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 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/interpreter/control-flow-builders.h" 10 #include "src/interpreter/control-flow-builders.h"
11 #include "src/objects.h" 11 #include "src/objects.h"
12 #include "src/parser.h"
12 #include "src/scopes.h" 13 #include "src/scopes.h"
13 #include "src/token.h" 14 #include "src/token.h"
14 15
15 namespace v8 { 16 namespace v8 {
16 namespace internal { 17 namespace internal {
17 namespace interpreter { 18 namespace interpreter {
18 19
19 20
20 // Scoped class tracking context objects created by the visitor. Represents 21 // Scoped class tracking context objects created by the visitor. Represents
21 // mutations of the context chain within the function body, allowing pushing and 22 // mutations of the context chain within the function body, allowing pushing and
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 UNIMPLEMENTED(); 495 UNIMPLEMENTED();
495 } 496 }
496 497
497 498
498 void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { 499 void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
499 UNIMPLEMENTED(); 500 UNIMPLEMENTED();
500 } 501 }
501 502
502 503
503 void BytecodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { 504 void BytecodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
504 UNIMPLEMENTED(); 505 // Deep-copy the literal boilerplate.
506 expr->BuildConstantElements(isolate());
507 builder()
508 ->LoadLiteral(expr->constant_elements())
509 .CreateArrayLiteral(expr->literal_index(), expr->ComputeFlags(true));
510
511 TemporaryRegisterScope temporary_register_scope(builder());
512 Register index, literal_array;
513
514 // Create nodes to evaluate all the non-constant subexpressions and to store
515 // them into the newly cloned array.
516 bool literal_array_in_accumulator = true;
517 for (int array_index = 0; array_index < expr->values()->length();
518 array_index++) {
519 Expression* subexpr = expr->values()->at(array_index);
520 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
521 if (subexpr->IsSpread()) {
522 // TODO(rmcilroy): Deal with spread expressions.
523 UNIMPLEMENTED();
524 }
525
526 if (literal_array_in_accumulator) {
527 index = temporary_register_scope.NewRegister();
528 literal_array = temporary_register_scope.NewRegister();
529 builder()->StoreAccumulatorInRegister(literal_array);
530 literal_array_in_accumulator = false;
531 }
532
533 builder()
534 ->LoadLiteral(Smi::FromInt(array_index))
535 .StoreAccumulatorInRegister(index);
536 Visit(subexpr);
537 builder()->GenericStoreKeyedProperty(literal_array, index);
538 }
539
540 if (!literal_array_in_accumulator) {
541 // Restore literal array into accumulator.
542 builder()->LoadAccumulatorWithRegister(literal_array);
543 }
505 } 544 }
506 545
507 546
508 void BytecodeGenerator::VisitVariableProxy(VariableProxy* proxy) { 547 void BytecodeGenerator::VisitVariableProxy(VariableProxy* proxy) {
509 VisitVariableLoad(proxy->var(), proxy->VariableFeedbackSlot()); 548 VisitVariableLoad(proxy->var(), proxy->VariableFeedbackSlot());
510 } 549 }
511 550
512 551
513 void BytecodeGenerator::VisitVariableLoad(Variable* variable, 552 void BytecodeGenerator::VisitVariableLoad(Variable* variable,
514 FeedbackVectorSlot slot) { 553 FeedbackVectorSlot slot) {
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 } 989 }
951 990
952 991
953 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 992 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
954 return info()->feedback_vector()->GetIndex(slot); 993 return info()->feedback_vector()->GetIndex(slot);
955 } 994 }
956 995
957 } // namespace interpreter 996 } // namespace interpreter
958 } // namespace internal 997 } // namespace internal
959 } // namespace v8 998 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-array-builder.cc ('k') | src/interpreter/bytecodes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698