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

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: 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
Index: src/interpreter/bytecode-generator.cc
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc
index d5f77a81d29890fe481c4a4b092fd9513ac261d3..3579a8ac294fef5e6771840eef8da22d9fe65b62 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"
@@ -458,7 +459,8 @@ void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
TemporaryRegisterScope temporary_register_scope(builder());
Register shared = temporary_register_scope.NewRegister();
- builder()->LoadLiteral(shared_info)
+ builder()
+ ->LoadLiteral(shared_info)
.StoreAccumulatorInRegister(shared)
.CallRuntime(function_id, shared, 1);
}
@@ -509,7 +511,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);
+ }
}
@@ -748,8 +788,7 @@ void BytecodeGenerator::VisitCall(Call* expr) {
case Call::OTHER_CALL: {
Visit(callee_expr);
builder()->StoreAccumulatorInRegister(callee);
- builder()->LoadUndefined()
- .StoreAccumulatorInRegister(receiver);
+ builder()->LoadUndefined().StoreAccumulatorInRegister(receiver);
break;
}
case Call::LOOKUP_SLOT_CALL:

Powered by Google App Engine
This is Rietveld 408576698