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" |
11 #include "src/objects.h" | 11 #include "src/objects.h" |
12 #include "src/parsing/parser.h" | 12 #include "src/parsing/parser.h" |
13 #include "src/parsing/token.h" | 13 #include "src/parsing/token.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 namespace interpreter { | 17 namespace interpreter { |
18 | 18 |
19 | 19 |
20 // Scoped class tracking context objects created by the visitor. Represents | 20 // Scoped class tracking context objects created by the visitor. Represents |
21 // mutations of the context chain within the function body, allowing pushing and | 21 // mutations of the context chain within the function body, allowing pushing and |
22 // popping of the current {context_register} during visitation. | 22 // popping of the current {context_register} during visitation. |
23 class BytecodeGenerator::ContextScope BASE_EMBEDDED { | 23 class BytecodeGenerator::ContextScope BASE_EMBEDDED { |
24 public: | 24 public: |
25 ContextScope(BytecodeGenerator* generator, Scope* scope, | 25 ContextScope(BytecodeGenerator* generator, Scope* scope, |
26 bool should_pop_context = true) | 26 bool should_pop_context = true) |
rmcilroy
2016/03/08 07:34:37
Now that we are popping more explicitly on return,
mythria
2016/03/08 11:04:23
Done.
| |
27 : generator_(generator), | 27 : generator_(generator), |
28 scope_(scope), | 28 scope_(scope), |
29 outer_(generator_->execution_context()), | 29 outer_(generator_->execution_context()), |
30 register_(Register::current_context()), | 30 register_(Register::current_context()), |
31 depth_(0), | 31 depth_(0), |
32 should_pop_context_(should_pop_context) { | 32 should_pop_context_(should_pop_context) { |
33 if (outer_) { | 33 if (outer_) { |
34 depth_ = outer_->depth_ + 1; | 34 depth_ = outer_->depth_ + 1; |
35 | 35 |
36 // Push the outer context into a new context register. | 36 // Push the outer context into a new context register. |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 | 355 |
356 private: | 356 private: |
357 TryFinallyBuilder* try_finally_builder_; | 357 TryFinallyBuilder* try_finally_builder_; |
358 DeferredCommands* commands_; | 358 DeferredCommands* commands_; |
359 }; | 359 }; |
360 | 360 |
361 | 361 |
362 void BytecodeGenerator::ControlScope::PerformCommand(Command command, | 362 void BytecodeGenerator::ControlScope::PerformCommand(Command command, |
363 Statement* statement) { | 363 Statement* statement) { |
364 ControlScope* current = this; | 364 ControlScope* current = this; |
365 ContextScope* context = this->context(); | 365 ContextScope* context = generator()->execution_context(); |
366 do { | 366 do { |
367 if (current->Execute(command, statement)) { return; } | |
368 current = current->outer(); | |
369 if (current->context() != context) { | 367 if (current->context() != context) { |
370 // Pop context to the expected depth. | 368 // Pop context to the expected depth. |
371 // TODO(rmcilroy): Only emit a single context pop. | 369 // TODO(rmcilroy): Only emit a single context pop. |
372 generator()->builder()->PopContext(current->context()->reg()); | 370 generator()->builder()->PopContext(current->context()->reg()); |
373 context = current->context(); | 371 context = current->context(); |
374 } | 372 } |
373 if (current->Execute(command, statement)) { | |
374 return; | |
375 } | |
376 current = current->outer(); | |
375 } while (current != nullptr); | 377 } while (current != nullptr); |
376 UNREACHABLE(); | 378 UNREACHABLE(); |
377 } | 379 } |
378 | 380 |
379 | 381 |
380 class BytecodeGenerator::RegisterAllocationScope { | 382 class BytecodeGenerator::RegisterAllocationScope { |
381 public: | 383 public: |
382 explicit RegisterAllocationScope(BytecodeGenerator* generator) | 384 explicit RegisterAllocationScope(BytecodeGenerator* generator) |
383 : generator_(generator), | 385 : generator_(generator), |
384 outer_(generator->register_allocator()), | 386 outer_(generator->register_allocator()), |
(...skipping 2757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3142 } | 3144 } |
3143 | 3145 |
3144 | 3146 |
3145 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3147 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
3146 return info()->feedback_vector()->GetIndex(slot); | 3148 return info()->feedback_vector()->GetIndex(slot); |
3147 } | 3149 } |
3148 | 3150 |
3149 } // namespace interpreter | 3151 } // namespace interpreter |
3150 } // namespace internal | 3152 } // namespace internal |
3151 } // namespace v8 | 3153 } // namespace v8 |
OLD | NEW |