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

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

Issue 2209573002: Separate Scope into DeclarationScope and Scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Cleanup diff Created 4 years, 4 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
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 "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/interpreter/bytecode-flags.h" 10 #include "src/interpreter/bytecode-flags.h"
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 // contain jumps to unbound labels (resume points that will never be used). 649 // contain jumps to unbound labels (resume points that will never be used).
650 // We bind these now. 650 // We bind these now.
651 for (auto& label : generator_resume_points_) { 651 for (auto& label : generator_resume_points_) {
652 if (!label.is_bound()) builder()->Bind(&label); 652 if (!label.is_bound()) builder()->Bind(&label);
653 } 653 }
654 654
655 builder()->EnsureReturn(); 655 builder()->EnsureReturn();
656 } 656 }
657 657
658 void BytecodeGenerator::GenerateBytecodeBody() { 658 void BytecodeGenerator::GenerateBytecodeBody() {
659 DCHECK_EQ(scope(), info()->scope());
Michael Starzinger 2016/08/03 13:02:19 nit: Can we change BytecodeGenerator::scope() to r
659 // Build the arguments object if it is used. 660 // Build the arguments object if it is used.
660 VisitArgumentsObject(scope()->arguments()); 661 VisitArgumentsObject(info()->scope()->arguments());
661 662
662 // Build rest arguments array if it is used. 663 // Build rest arguments array if it is used.
663 int rest_index; 664 int rest_index;
664 Variable* rest_parameter = scope()->rest_parameter(&rest_index); 665 Variable* rest_parameter = info()->scope()->rest_parameter(&rest_index);
665 VisitRestArgumentsArray(rest_parameter); 666 VisitRestArgumentsArray(rest_parameter);
666 667
667 // Build assignment to {.this_function} variable if it is used. 668 // Build assignment to {.this_function} variable if it is used.
668 VisitThisFunctionVariable(scope()->this_function_var()); 669 VisitThisFunctionVariable(info()->scope()->this_function_var());
669 670
670 // Build assignment to {new.target} variable if it is used. 671 // Build assignment to {new.target} variable if it is used.
671 VisitNewTargetVariable(scope()->new_target_var()); 672 VisitNewTargetVariable(info()->scope()->new_target_var());
672 673
673 // TODO(rmcilroy): Emit tracing call if requested to do so. 674 // TODO(rmcilroy): Emit tracing call if requested to do so.
674 if (FLAG_trace) { 675 if (FLAG_trace) {
675 UNIMPLEMENTED(); 676 UNIMPLEMENTED();
676 } 677 }
677 678
678 // Visit declarations within the function scope. 679 // Visit declarations within the function scope.
679 VisitDeclarations(scope()->declarations()); 680 VisitDeclarations(info()->scope()->declarations());
680 681
681 // Perform a stack-check before the body. 682 // Perform a stack-check before the body.
682 builder()->StackCheck(info()->literal()->start_position()); 683 builder()->StackCheck(info()->literal()->start_position());
683 684
684 // Visit statements in the function body. 685 // Visit statements in the function body.
685 VisitStatements(info()->literal()->body()); 686 VisitStatements(info()->literal()->body());
686 } 687 }
687 688
688 void BytecodeGenerator::BuildIndexedJump(Register index, size_t start_index, 689 void BytecodeGenerator::BuildIndexedJump(Register index, size_t start_index,
689 size_t size, 690 size_t size,
(...skipping 2319 matching lines...) Expand 10 before | Expand all | Expand 10 after
3009 .StoreAccumulatorInRegister(scope_info) 3010 .StoreAccumulatorInRegister(scope_info)
3010 .CallRuntime(Runtime::kNewScriptContext, closure, 2); 3011 .CallRuntime(Runtime::kNewScriptContext, closure, 2);
3011 } else { 3012 } else {
3012 builder()->CallRuntime(Runtime::kNewFunctionContext, 3013 builder()->CallRuntime(Runtime::kNewFunctionContext,
3013 Register::function_closure(), 1); 3014 Register::function_closure(), 1);
3014 } 3015 }
3015 execution_result()->SetResultInAccumulator(); 3016 execution_result()->SetResultInAccumulator();
3016 } 3017 }
3017 3018
3018 void BytecodeGenerator::VisitBuildLocalActivationContext() { 3019 void BytecodeGenerator::VisitBuildLocalActivationContext() {
3019 Scope* scope = this->scope(); 3020 DeclarationScope* scope = this->scope()->AsDeclarationScope();
Michael Starzinger 2016/08/03 13:02:19 nit: See comment above.
3020 3021
3021 if (scope->has_this_declaration() && scope->receiver()->IsContextSlot()) { 3022 if (scope->has_this_declaration() && scope->receiver()->IsContextSlot()) {
3022 Variable* variable = scope->receiver(); 3023 Variable* variable = scope->receiver();
3023 Register receiver(builder()->Parameter(0)); 3024 Register receiver(builder()->Parameter(0));
3024 // Context variable (at bottom of the context chain). 3025 // Context variable (at bottom of the context chain).
3025 DCHECK_EQ(0, scope->ContextChainLength(variable->scope())); 3026 DCHECK_EQ(0, scope->ContextChainLength(variable->scope()));
3026 builder()->LoadAccumulatorWithRegister(receiver).StoreContextSlot( 3027 builder()->LoadAccumulatorWithRegister(receiver).StoreContextSlot(
3027 execution_context()->reg(), variable->index()); 3028 execution_context()->reg(), variable->index());
3028 } 3029 }
3029 3030
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
3158 void BytecodeGenerator::VisitNewTargetVariable(Variable* variable) { 3159 void BytecodeGenerator::VisitNewTargetVariable(Variable* variable) {
3159 if (variable == nullptr) return; 3160 if (variable == nullptr) return;
3160 3161
3161 // Store the new target we were called with in the given variable. 3162 // Store the new target we were called with in the given variable.
3162 builder()->LoadAccumulatorWithRegister(Register::new_target()); 3163 builder()->LoadAccumulatorWithRegister(Register::new_target());
3163 VisitVariableAssignment(variable, Token::INIT, FeedbackVectorSlot::Invalid()); 3164 VisitVariableAssignment(variable, Token::INIT, FeedbackVectorSlot::Invalid());
3164 } 3165 }
3165 3166
3166 void BytecodeGenerator::VisitFunctionClosureForContext() { 3167 void BytecodeGenerator::VisitFunctionClosureForContext() {
3167 AccumulatorResultScope accumulator_execution_result(this); 3168 AccumulatorResultScope accumulator_execution_result(this);
3168 Scope* closure_scope = execution_context()->scope()->ClosureScope(); 3169 DeclarationScope* closure_scope =
3170 execution_context()->scope()->GetClosureScope();
3169 if (closure_scope->is_script_scope() || 3171 if (closure_scope->is_script_scope() ||
3170 closure_scope->is_module_scope()) { 3172 closure_scope->is_module_scope()) {
3171 // Contexts nested in the native context have a canonical empty function as 3173 // Contexts nested in the native context have a canonical empty function as
3172 // their closure, not the anonymous closure containing the global code. 3174 // their closure, not the anonymous closure containing the global code.
3173 Register native_context = register_allocator()->NewRegister(); 3175 Register native_context = register_allocator()->NewRegister();
3174 builder() 3176 builder()
3175 ->LoadContextSlot(execution_context()->reg(), 3177 ->LoadContextSlot(execution_context()->reg(),
3176 Context::NATIVE_CONTEXT_INDEX) 3178 Context::NATIVE_CONTEXT_INDEX)
3177 .StoreAccumulatorInRegister(native_context) 3179 .StoreAccumulatorInRegister(native_context)
3178 .LoadContextSlot(native_context, Context::CLOSURE_INDEX); 3180 .LoadContextSlot(native_context, Context::CLOSURE_INDEX);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3236 return execution_context()->scope()->language_mode(); 3238 return execution_context()->scope()->language_mode();
3237 } 3239 }
3238 3240
3239 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 3241 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
3240 return TypeFeedbackVector::GetIndex(slot); 3242 return TypeFeedbackVector::GetIndex(slot);
3241 } 3243 }
3242 3244
3243 } // namespace interpreter 3245 } // namespace interpreter
3244 } // namespace internal 3246 } // namespace internal
3245 } // namespace v8 3247 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698