| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "vm/ast_printer.h" | 7 #include "vm/ast_printer.h" |
| 8 #include "vm/code_descriptors.h" | 8 #include "vm/code_descriptors.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 2604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2615 if (num_context_variables > 0) { | 2615 if (num_context_variables > 0) { |
| 2616 InlineBailout("EffectGraphVisitor::VisitSequenceNode (context)"); | 2616 InlineBailout("EffectGraphVisitor::VisitSequenceNode (context)"); |
| 2617 // The loop local scope declares variables that are captured. | 2617 // The loop local scope declares variables that are captured. |
| 2618 // Allocate and chain a new context. | 2618 // Allocate and chain a new context. |
| 2619 // Allocate context computation (uses current CTX) | 2619 // Allocate context computation (uses current CTX) |
| 2620 Value* allocated_context = | 2620 Value* allocated_context = |
| 2621 Bind(new AllocateContextInstr(node->token_pos(), | 2621 Bind(new AllocateContextInstr(node->token_pos(), |
| 2622 num_context_variables)); | 2622 num_context_variables)); |
| 2623 | 2623 |
| 2624 // If this node_sequence is the body of the function being compiled, and if | 2624 // If this node_sequence is the body of the function being compiled, and if |
| 2625 // this function is not a closure, do not link the current context as the | 2625 // this function allocates context variables, but none of its enclosing |
| 2626 // parent of the newly allocated context, as it is not accessible. Instead, | 2626 // functions do, the context on entry is not linked as parent of the |
| 2627 // save it in a pre-allocated variable and restore it on exit. | 2627 // allocated context but saved on entry and restored on exit as to prevent |
| 2628 // memory leaks. |
| 2629 // In this case, the parser pre-allocates a variable to save the context. |
| 2628 if (MustSaveRestoreContext(node)) { | 2630 if (MustSaveRestoreContext(node)) { |
| 2629 Value* current_context = Bind(new CurrentContextInstr()); | 2631 Value* current_context = Bind(new CurrentContextInstr()); |
| 2630 Do(BuildStoreTemp(*owner()->parsed_function().saved_context_var(), | 2632 Do(BuildStoreTemp(*owner()->parsed_function().saved_context_var(), |
| 2631 current_context)); | 2633 current_context)); |
| 2632 Value* null_context = Bind(new ConstantInstr(Object::ZoneHandle())); | 2634 Value* null_context = Bind(new ConstantInstr(Object::ZoneHandle())); |
| 2633 AddInstruction(new StoreContextInstr(null_context)); | 2635 AddInstruction(new StoreContextInstr(null_context)); |
| 2634 } | 2636 } |
| 2635 | 2637 |
| 2636 AddInstruction(new ChainContextInstr(allocated_context)); | 2638 AddInstruction(new ChainContextInstr(allocated_context)); |
| 2637 owner()->set_context_level(scope->context_level()); | 2639 owner()->set_context_level(scope->context_level()); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3068 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 3070 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
| 3069 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 3071 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 3070 OS::SNPrint(chars, len, kFormat, function_name, reason); | 3072 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 3071 const Error& error = Error::Handle( | 3073 const Error& error = Error::Handle( |
| 3072 LanguageError::New(String::Handle(String::New(chars)))); | 3074 LanguageError::New(String::Handle(String::New(chars)))); |
| 3073 Isolate::Current()->long_jump_base()->Jump(1, error); | 3075 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 3074 } | 3076 } |
| 3075 | 3077 |
| 3076 | 3078 |
| 3077 } // namespace dart | 3079 } // namespace dart |
| OLD | NEW |