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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/interpreter/bytecode-array-builder.cc ('k') | src/interpreter/bytecodes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-generator.cc
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc
index 2eb235df04c701bbbedcca3656b62b6eb6d33b88..cf20652a58a93dbf1ce6f3acc7a13883e5914e93 100644
--- a/src/interpreter/bytecode-generator.cc
+++ b/src/interpreter/bytecode-generator.cc
@@ -9,6 +9,7 @@
#include "src/compiler.h"
#include "src/interpreter/control-flow-builders.h"
#include "src/objects.h"
+#include "src/parser.h"
#include "src/scopes.h"
#include "src/token.h"
@@ -501,7 +502,45 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
void BytecodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
- UNIMPLEMENTED();
+ // Deep-copy the literal boilerplate.
+ expr->BuildConstantElements(isolate());
+ builder()
+ ->LoadLiteral(expr->constant_elements())
+ .CreateArrayLiteral(expr->literal_index(), expr->ComputeFlags(true));
+
+ TemporaryRegisterScope temporary_register_scope(builder());
+ Register index, literal_array;
+
+ // Create nodes to evaluate all the non-constant subexpressions and to store
+ // them into the newly cloned array.
+ bool literal_array_in_accumulator = true;
+ for (int array_index = 0; array_index < expr->values()->length();
+ array_index++) {
+ Expression* subexpr = expr->values()->at(array_index);
+ if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
+ if (subexpr->IsSpread()) {
+ // TODO(rmcilroy): Deal with spread expressions.
+ UNIMPLEMENTED();
+ }
+
+ if (literal_array_in_accumulator) {
+ index = temporary_register_scope.NewRegister();
+ literal_array = temporary_register_scope.NewRegister();
+ builder()->StoreAccumulatorInRegister(literal_array);
+ literal_array_in_accumulator = false;
+ }
+
+ builder()
+ ->LoadLiteral(Smi::FromInt(array_index))
+ .StoreAccumulatorInRegister(index);
+ Visit(subexpr);
+ builder()->GenericStoreKeyedProperty(literal_array, index);
+ }
+
+ if (!literal_array_in_accumulator) {
+ // Restore literal array into accumulator.
+ builder()->LoadAccumulatorWithRegister(literal_array);
+ }
}
« 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