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 "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
9 #include "src/interpreter/bytecode-register-allocator.h" | 9 #include "src/interpreter/bytecode-register-allocator.h" |
10 #include "src/interpreter/control-flow-builders.h" | 10 #include "src/interpreter/control-flow-builders.h" |
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1219 Handle<SharedFunctionInfo> shared_info = | 1219 Handle<SharedFunctionInfo> shared_info = |
1220 Compiler::GetSharedFunctionInfo(expr, info()->script(), info()); | 1220 Compiler::GetSharedFunctionInfo(expr, info()->script(), info()); |
1221 CHECK(!shared_info.is_null()); // TODO(rmcilroy): Set stack overflow? | 1221 CHECK(!shared_info.is_null()); // TODO(rmcilroy): Set stack overflow? |
1222 builder()->CreateClosure(shared_info, | 1222 builder()->CreateClosure(shared_info, |
1223 expr->pretenure() ? TENURED : NOT_TENURED); | 1223 expr->pretenure() ? TENURED : NOT_TENURED); |
1224 execution_result()->SetResultInAccumulator(); | 1224 execution_result()->SetResultInAccumulator(); |
1225 } | 1225 } |
1226 | 1226 |
1227 | 1227 |
1228 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) { | 1228 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) { |
1229 UNIMPLEMENTED(); | 1229 if (expr->scope()->ContextLocalCount() > 0) { |
1230 VisitNewLocalBlockContext(expr->scope()); | |
1231 ContextScope scope(this, expr->scope()); | |
1232 VisitDeclarations(expr->scope()->declarations()); | |
1233 VisitClassLiteralContents(expr); | |
1234 } else { | |
1235 VisitDeclarations(expr->scope()->declarations()); | |
1236 VisitClassLiteralContents(expr); | |
1237 } | |
1230 } | 1238 } |
1231 | 1239 |
1240 void BytecodeGenerator::VisitClassLiteralContents(ClassLiteral* expr) { | |
1241 VisitClassLiteralForRuntimeDefinition(expr); | |
1242 // The prototype is ensured to exist by Runtime_DefineClass in | |
1243 // VisitClassForRuntimeDefinition. No access check is needed here | |
1244 // since the constructor is created by the class literal. | |
1245 register_allocator()->PrepareForConsecutiveAllocations(2); | |
1246 Register literal = register_allocator()->NextConsecutiveRegister(); | |
1247 Register prototype = register_allocator()->NextConsecutiveRegister(); | |
1248 builder()->StoreAccumulatorInRegister(literal); | |
1249 builder()->LoadPrototypeOrInitialMap(); | |
rmcilroy
2016/02/04 14:56:41
nit - chain builders (in functions below too) ?
oth
2016/02/04 16:59:48
Done.
| |
1250 builder()->StoreAccumulatorInRegister(prototype); | |
1251 VisitClassLiteralProperties(expr, literal, prototype); | |
1252 | |
1253 // Set both the prototype and constructor to have fast properties, and also | |
1254 // freeze them in strong mode. | |
rmcilroy
2016/02/04 14:56:41
Remove the comment about strong mode (we don't sup
oth
2016/02/04 16:59:48
Done.
| |
1255 builder()->CallRuntime(Runtime::kFinalizeClassDefinition, literal, 2); | |
1256 // Assign to class variable. | |
1257 if (expr->class_variable_proxy() != nullptr) { | |
1258 Variable* var = expr->class_variable_proxy()->var(); | |
1259 FeedbackVectorSlot slot = expr->NeedsProxySlot() | |
1260 ? expr->ProxySlot() | |
1261 : FeedbackVectorSlot::Invalid(); | |
1262 VisitVariableAssignment(var, slot); | |
1263 } | |
1264 execution_result()->SetResultInAccumulator(); | |
1265 } | |
1266 | |
1267 void BytecodeGenerator::VisitClassLiteralForRuntimeDefinition( | |
1268 ClassLiteral* expr) { | |
1269 AccumulatorResultScope result_scope(this); | |
1270 register_allocator()->PrepareForConsecutiveAllocations(4); | |
1271 Register extends = register_allocator()->NextConsecutiveRegister(); | |
1272 Register constructor = register_allocator()->NextConsecutiveRegister(); | |
1273 Register start_position = register_allocator()->NextConsecutiveRegister(); | |
1274 Register end_position = register_allocator()->NextConsecutiveRegister(); | |
1275 VisitForAccumulatorValueOrTheHole(expr->extends()); | |
rmcilroy
2016/02/04 14:56:41
nit - newline above (bit of a wall of text otherwi
oth
2016/02/04 16:59:48
Done.
| |
1276 builder()->StoreAccumulatorInRegister(extends); | |
1277 VisitForAccumulatorValue(expr->constructor()); | |
1278 builder()->StoreAccumulatorInRegister(constructor); | |
1279 builder()->LoadLiteral(Smi::FromInt(expr->start_position())); | |
1280 builder()->StoreAccumulatorInRegister(start_position); | |
1281 builder()->LoadLiteral(Smi::FromInt(expr->end_position())); | |
1282 builder()->StoreAccumulatorInRegister(end_position); | |
1283 builder()->CallRuntime(Runtime::kDefineClass, extends, 4); | |
1284 result_scope.SetResultInAccumulator(); | |
1285 } | |
1286 | |
1287 void BytecodeGenerator::VisitClassLiteralProperties(ClassLiteral* expr, | |
1288 Register literal, | |
1289 Register prototype) { | |
1290 EffectResultScope result_scope(this); | |
rmcilroy
2016/02/04 14:56:41
Remove please (or replace with a RegisterAllocatio
oth
2016/02/04 16:59:48
Done.
| |
1291 | |
1292 register_allocator()->PrepareForConsecutiveAllocations(4); | |
1293 Register receiver = register_allocator()->NextConsecutiveRegister(); | |
1294 Register key = register_allocator()->NextConsecutiveRegister(); | |
1295 Register value = register_allocator()->NextConsecutiveRegister(); | |
1296 Register attr = register_allocator()->NextConsecutiveRegister(); | |
1297 | |
1298 bool attr_assigned = false; | |
1299 Register old_receiver = Register::invalid_value(); | |
1300 | |
1301 // Create nodes to store method values into the literal. | |
1302 for (int i = 0; i < expr->properties()->length(); i++) { | |
1303 ObjectLiteral::Property* property = expr->properties()->at(i); | |
1304 | |
1305 // Set-up receiver. | |
1306 Register new_receiver = property->is_static() ? literal : prototype; | |
1307 if (new_receiver != old_receiver) { | |
1308 builder()->MoveRegister(new_receiver, receiver); | |
1309 old_receiver = new_receiver; | |
1310 } | |
1311 | |
1312 VisitForAccumulatorValue(property->key()); | |
1313 builder()->CastAccumulatorToName(); | |
1314 builder()->StoreAccumulatorInRegister(key); | |
1315 // The static prototype property is read only. We handle the non computed | |
1316 // property name case in the parser. Since this is the only case where we | |
1317 // need to check for an own read only property we special case this so we do | |
1318 // not need to do this for every property. | |
rmcilroy
2016/02/04 14:56:40
I think this comment might make more sense in Visi
oth
2016/02/04 16:59:48
It seems like the right place as it explains the p
rmcilroy
2016/02/04 17:37:06
Yeah sorry you are right, it belongs here.
| |
1319 if (property->is_static() && property->is_computed_name()) { | |
1320 VisitClassLiteralStaticPrototypeWithComputedName(key); | |
1321 } | |
1322 VisitForAccumulatorValue(property->value()); | |
1323 builder()->StoreAccumulatorInRegister(value); | |
1324 | |
1325 VisitSetHomeObject(value, receiver, property); | |
1326 | |
1327 if ((property->kind() == ObjectLiteral::Property::GETTER || | |
1328 property->kind() == ObjectLiteral::Property::SETTER) && | |
1329 !attr_assigned) { | |
1330 builder() | |
1331 ->LoadLiteral(Smi::FromInt(DONT_ENUM)) | |
1332 .StoreAccumulatorInRegister(attr); | |
1333 attr_assigned = true; | |
1334 } | |
1335 | |
1336 switch (property->kind()) { | |
1337 case ObjectLiteral::Property::CONSTANT: | |
1338 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
1339 case ObjectLiteral::Property::PROTOTYPE: | |
1340 UNREACHABLE(); | |
rmcilroy
2016/02/04 14:56:41
nit - comment on why this should be unreachable an
oth
2016/02/04 16:59:48
Done.
| |
1341 case ObjectLiteral::Property::COMPUTED: { | |
1342 builder()->CallRuntime(Runtime::kDefineClassMethod, receiver, 3); | |
1343 break; | |
1344 } | |
1345 case ObjectLiteral::Property::GETTER: { | |
1346 builder()->CallRuntime(Runtime::kDefineGetterPropertyUnchecked, | |
1347 receiver, 4); | |
1348 break; | |
1349 } | |
1350 case ObjectLiteral::Property::SETTER: { | |
1351 builder()->CallRuntime(Runtime::kDefineSetterPropertyUnchecked, | |
1352 receiver, 4); | |
1353 break; | |
1354 } | |
1355 } | |
1356 } | |
1357 } | |
1358 | |
1359 void BytecodeGenerator::VisitClassLiteralStaticPrototypeWithComputedName( | |
1360 Register key) { | |
1361 BytecodeLabel done; | |
1362 builder()->LoadLiteral(isolate()->factory()->prototype_string()); | |
1363 builder()->CompareOperation(Token::Value::EQ_STRICT, key, Strength::WEAK); | |
1364 builder()->JumpIfFalse(&done); | |
1365 builder()->CallRuntime(Runtime::kThrowStaticPrototypeError, Register(0), 0); | |
1366 builder()->Bind(&done); | |
1367 } | |
1232 | 1368 |
1233 void BytecodeGenerator::VisitNativeFunctionLiteral( | 1369 void BytecodeGenerator::VisitNativeFunctionLiteral( |
1234 NativeFunctionLiteral* expr) { | 1370 NativeFunctionLiteral* expr) { |
1235 // Find or build a shared function info for the native function template. | 1371 // Find or build a shared function info for the native function template. |
1236 Handle<SharedFunctionInfo> shared_info = | 1372 Handle<SharedFunctionInfo> shared_info = |
1237 Compiler::GetSharedFunctionInfoForNative(expr->extension(), expr->name()); | 1373 Compiler::GetSharedFunctionInfoForNative(expr->extension(), expr->name()); |
1238 builder()->CreateClosure(shared_info, NOT_TENURED); | 1374 builder()->CreateClosure(shared_info, NOT_TENURED); |
1239 execution_result()->SetResultInAccumulator(); | 1375 execution_result()->SetResultInAccumulator(); |
1240 } | 1376 } |
1241 | 1377 |
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2511 execution_result()->SetResultInAccumulator(); | 2647 execution_result()->SetResultInAccumulator(); |
2512 } | 2648 } |
2513 | 2649 |
2514 | 2650 |
2515 // Visits the expression |expr| and places the result in the accumulator. | 2651 // Visits the expression |expr| and places the result in the accumulator. |
2516 void BytecodeGenerator::VisitForAccumulatorValue(Expression* expr) { | 2652 void BytecodeGenerator::VisitForAccumulatorValue(Expression* expr) { |
2517 AccumulatorResultScope accumulator_scope(this); | 2653 AccumulatorResultScope accumulator_scope(this); |
2518 Visit(expr); | 2654 Visit(expr); |
2519 } | 2655 } |
2520 | 2656 |
2657 void BytecodeGenerator::VisitForAccumulatorValueOrTheHole(Expression* expr) { | |
2658 if (expr == nullptr) { | |
2659 builder()->LoadTheHole(); | |
2660 } else { | |
2661 VisitForAccumulatorValue(expr); | |
2662 } | |
2663 } | |
2521 | 2664 |
2522 // Visits the expression |expr| and discards the result. | 2665 // Visits the expression |expr| and discards the result. |
2523 void BytecodeGenerator::VisitForEffect(Expression* expr) { | 2666 void BytecodeGenerator::VisitForEffect(Expression* expr) { |
2524 EffectResultScope effect_scope(this); | 2667 EffectResultScope effect_scope(this); |
2525 Visit(expr); | 2668 Visit(expr); |
2526 } | 2669 } |
2527 | 2670 |
2528 | 2671 |
2529 // Visits the expression |expr| and returns the register containing | 2672 // Visits the expression |expr| and returns the register containing |
2530 // the expression result. | 2673 // the expression result. |
(...skipping 21 matching lines...) Expand all Loading... | |
2552 } | 2695 } |
2553 | 2696 |
2554 | 2697 |
2555 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 2698 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
2556 return info()->feedback_vector()->GetIndex(slot); | 2699 return info()->feedback_vector()->GetIndex(slot); |
2557 } | 2700 } |
2558 | 2701 |
2559 } // namespace interpreter | 2702 } // namespace interpreter |
2560 } // namespace internal | 2703 } // namespace internal |
2561 } // namespace v8 | 2704 } // namespace v8 |
OLD | NEW |