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

Side by Side Diff: src/scopes.cc

Issue 7826009: Support declarations of context allocated locals in Crankshaft. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 for (Scope* scope = this; 369 for (Scope* scope = this;
370 scope != NULL; 370 scope != NULL;
371 scope = scope->outer_scope()) { 371 scope = scope->outer_scope()) {
372 Variable* var = scope->LocalLookup(name); 372 Variable* var = scope->LocalLookup(name);
373 if (var != NULL) return var; 373 if (var != NULL) return var;
374 } 374 }
375 return NULL; 375 return NULL;
376 } 376 }
377 377
378 378
379 Variable* Scope::DeclareFunctionVar(Handle<String> name) { 379 VariableProxy* Scope::DeclareFunctionVar(Handle<String> name) {
380 ASSERT(is_function_scope() && function_ == NULL); 380 ASSERT(is_function_scope() && function_ == NULL);
381 function_ = new Variable(this, name, Variable::CONST, true, Variable::NORMAL); 381 Variable* function_var =
382 new Variable(this, name, Variable::CONST, true, Variable::NORMAL);
383 function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var);
382 return function_; 384 return function_;
383 } 385 }
384 386
385 387
386 void Scope::DeclareParameter(Handle<String> name, Variable::Mode mode) { 388 void Scope::DeclareParameter(Handle<String> name, Variable::Mode mode) {
387 ASSERT(!already_resolved()); 389 ASSERT(!already_resolved());
388 ASSERT(is_function_scope()); 390 ASSERT(is_function_scope());
389 Variable* var = 391 Variable* var =
390 variables_.Declare(this, name, mode, true, Variable::NORMAL); 392 variables_.Declare(this, name, mode, true, Variable::NORMAL);
391 params_.Add(var); 393 params_.Add(var);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 } 710 }
709 if (num_stack_slots_ > 0) { Indent(n1, "// "); 711 if (num_stack_slots_ > 0) { Indent(n1, "// ");
710 PrintF("%d stack slots\n", num_stack_slots_); } 712 PrintF("%d stack slots\n", num_stack_slots_); }
711 if (num_heap_slots_ > 0) { Indent(n1, "// "); 713 if (num_heap_slots_ > 0) { Indent(n1, "// ");
712 PrintF("%d heap slots\n", num_heap_slots_); } 714 PrintF("%d heap slots\n", num_heap_slots_); }
713 715
714 // Print locals. 716 // Print locals.
715 PrettyPrinter printer; 717 PrettyPrinter printer;
716 Indent(n1, "// function var\n"); 718 Indent(n1, "// function var\n");
717 if (function_ != NULL) { 719 if (function_ != NULL) {
718 PrintVar(&printer, n1, function_); 720 PrintVar(&printer, n1, function_->var());
719 } 721 }
720 722
721 Indent(n1, "// temporary vars\n"); 723 Indent(n1, "// temporary vars\n");
722 for (int i = 0; i < temps_.length(); i++) { 724 for (int i = 0; i < temps_.length(); i++) {
723 PrintVar(&printer, n1, temps_[i]); 725 PrintVar(&printer, n1, temps_[i]);
724 } 726 }
725 727
726 Indent(n1, "// local vars\n"); 728 Indent(n1, "// local vars\n");
727 PrintMap(&printer, n1, &variables_); 729 PrintMap(&printer, n1, &variables_);
728 730
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 790
789 } else { 791 } else {
790 // We did not find a variable locally. Check against the function variable, 792 // We did not find a variable locally. Check against the function variable,
791 // if any. We can do this for all scopes, since the function variable is 793 // if any. We can do this for all scopes, since the function variable is
792 // only present - if at all - for function scopes. 794 // only present - if at all - for function scopes.
793 // 795 //
794 // This lookup corresponds to a lookup in the "intermediate" scope sitting 796 // This lookup corresponds to a lookup in the "intermediate" scope sitting
795 // between this scope and the outer scope. (ECMA-262, 3rd., requires that 797 // between this scope and the outer scope. (ECMA-262, 3rd., requires that
796 // the name of named function literal is kept in an intermediate scope 798 // the name of named function literal is kept in an intermediate scope
797 // in between this scope and the next outer scope.) 799 // in between this scope and the next outer scope.)
798 if (function_ != NULL && function_->name().is_identical_to(name)) { 800 if (function_ != NULL && function_->var()->name().is_identical_to(name)) {
Kevin Millikin (Chromium) 2011/09/01 15:40:58 function_->name() because the VariableProxy and Va
fschneider 2011/09/01 16:28:21 Done.
799 var = function_; 801 var = function_->var();
800 802
801 } else if (outer_scope_ != NULL) { 803 } else if (outer_scope_ != NULL) {
802 var = outer_scope_->LookupRecursive( 804 var = outer_scope_->LookupRecursive(
803 name, 805 name,
804 is_function_scope() || from_inner_function, 806 is_function_scope() || from_inner_function,
805 invalidated_local); 807 invalidated_local);
806 // We may have found a variable in an outer scope. However, if 808 // We may have found a variable in an outer scope. However, if
807 // the current scope is inside a 'with', the actual variable may 809 // the current scope is inside a 'with', the actual variable may
808 // be a property introduced via the 'with' statement. Then, the 810 // be a property introduced via the 'with' statement. Then, the
809 // variable we may have found is just a guess. 811 // variable we may have found is just a guess.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 p = variables_.Next(p)) { 1109 p = variables_.Next(p)) {
1108 Variable* var = reinterpret_cast<Variable*>(p->value); 1110 Variable* var = reinterpret_cast<Variable*>(p->value);
1109 AllocateNonParameterLocal(var); 1111 AllocateNonParameterLocal(var);
1110 } 1112 }
1111 1113
1112 // For now, function_ must be allocated at the very end. If it gets 1114 // For now, function_ must be allocated at the very end. If it gets
1113 // allocated in the context, it must be the last slot in the context, 1115 // allocated in the context, it must be the last slot in the context,
1114 // because of the current ScopeInfo implementation (see 1116 // because of the current ScopeInfo implementation (see
1115 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). 1117 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor).
1116 if (function_ != NULL) { 1118 if (function_ != NULL) {
1117 AllocateNonParameterLocal(function_); 1119 AllocateNonParameterLocal(function_->var());
1118 } 1120 }
1119 } 1121 }
1120 1122
1121 1123
1122 void Scope::AllocateVariablesRecursively() { 1124 void Scope::AllocateVariablesRecursively() {
1123 // Allocate variables for inner scopes. 1125 // Allocate variables for inner scopes.
1124 for (int i = 0; i < inner_scopes_.length(); i++) { 1126 for (int i = 0; i < inner_scopes_.length(); i++) {
1125 inner_scopes_[i]->AllocateVariablesRecursively(); 1127 inner_scopes_[i]->AllocateVariablesRecursively();
1126 } 1128 }
1127 1129
(...skipping 25 matching lines...) Expand all
1153 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && 1155 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS &&
1154 !must_have_local_context) { 1156 !must_have_local_context) {
1155 num_heap_slots_ = 0; 1157 num_heap_slots_ = 0;
1156 } 1158 }
1157 1159
1158 // Allocation done. 1160 // Allocation done.
1159 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 1161 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
1160 } 1162 }
1161 1163
1162 } } // namespace v8::internal 1164 } } // namespace v8::internal
OLDNEW
« src/scopeinfo.cc ('K') | « src/scopes.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698