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

Unified Diff: src/full-codegen.h

Issue 7860045: Stack allocating block scoped variables. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased on tip of tree. Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler.cc ('k') | src/full-codegen.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/full-codegen.h
diff --git a/src/full-codegen.h b/src/full-codegen.h
index e8915fc8c2aca3ccc8cd4c391f3876869ac35191..c208acce125ba5d3eef835d4beac2951e5968736 100644
--- a/src/full-codegen.h
+++ b/src/full-codegen.h
@@ -115,11 +115,7 @@ class FullCodeGenerator: public AstVisitor {
class NestedStatement BASE_EMBEDDED {
public:
- explicit NestedStatement(FullCodeGenerator* codegen) : codegen_(codegen) {
- // Link into codegen's nesting stack.
- previous_ = codegen->nesting_stack_;
- codegen->nesting_stack_ = this;
- }
+ NestedStatement(FullCodeGenerator* codegen, int stack_delta);
virtual ~NestedStatement() {
// Unlink from codegen's nesting stack.
ASSERT_EQ(this, codegen_->nesting_stack_);
@@ -139,22 +135,33 @@ class FullCodeGenerator: public AstVisitor {
// number of context chain links to unwind as we traverse the nesting
// stack from an exit to its target.
virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
+ *stack_depth += stack_delta_;
return previous_;
}
+ // The depth of the stack of block local variables and handlers
+ // above the locals during the execution of this nested statement.
+ int StackDepth() const { return stack_depth_; }
+ // The depth of the stack before and after executing this nested statement.
+ int StackDepthBase() const { return stack_depth_ - stack_delta_; }
+
protected:
MacroAssembler* masm() { return codegen_->masm(); }
FullCodeGenerator* codegen_;
NestedStatement* previous_;
+ int stack_depth_;
+ int stack_delta_;
DISALLOW_COPY_AND_ASSIGN(NestedStatement);
};
// A breakable statement such as a block.
class Breakable : public NestedStatement {
public:
- Breakable(FullCodeGenerator* codegen, BreakableStatement* statement)
- : NestedStatement(codegen), statement_(statement) {
+ Breakable(FullCodeGenerator* codegen,
+ BreakableStatement* statement,
+ int stack_delta = 0)
+ : NestedStatement(codegen, stack_delta), statement_(statement) {
}
virtual ~Breakable() {}
@@ -174,8 +181,10 @@ class FullCodeGenerator: public AstVisitor {
// An iteration statement such as a while, for, or do loop.
class Iteration : public Breakable {
public:
- Iteration(FullCodeGenerator* codegen, IterationStatement* statement)
- : Breakable(codegen, statement) {
+ Iteration(FullCodeGenerator* codegen,
+ IterationStatement* statement,
+ int stack_delta = 0)
+ : Breakable(codegen, statement, stack_delta) {
}
virtual ~Iteration() {}
@@ -193,23 +202,21 @@ class FullCodeGenerator: public AstVisitor {
// A nested block statement.
class NestedBlock : public Breakable {
public:
- NestedBlock(FullCodeGenerator* codegen, Block* block)
- : Breakable(codegen, block) {
- }
+ NestedBlock(FullCodeGenerator* codegen, Block* block);
+
virtual ~NestedBlock() {}
- virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
- if (statement()->AsBlock()->block_scope() != NULL) {
- ++(*context_length);
- }
- return previous_;
- };
+ virtual NestedStatement* Exit(int* stack_depth, int* context_length);
};
// The try block of a try/catch statement.
class TryCatch : public NestedStatement {
public:
- explicit TryCatch(FullCodeGenerator* codegen) : NestedStatement(codegen) {
+ static const int kElementCount =
+ StackHandlerConstants::kSize / kPointerSize;
+
+ explicit TryCatch(FullCodeGenerator* codegen)
+ : NestedStatement(codegen, kElementCount) {
}
virtual ~TryCatch() {}
@@ -219,8 +226,11 @@ class FullCodeGenerator: public AstVisitor {
// The try block of a try/finally statement.
class TryFinally : public NestedStatement {
public:
+ static const int kElementCount = 5;
+
TryFinally(FullCodeGenerator* codegen, Label* finally_entry)
- : NestedStatement(codegen), finally_entry_(finally_entry) {
+ : NestedStatement(codegen, kElementCount),
+ finally_entry_(finally_entry) {
}
virtual ~TryFinally() {}
@@ -235,13 +245,9 @@ class FullCodeGenerator: public AstVisitor {
public:
static const int kElementCount = 2;
- explicit Finally(FullCodeGenerator* codegen) : NestedStatement(codegen) { }
+ explicit Finally(FullCodeGenerator* codegen)
+ : NestedStatement(codegen, kElementCount) { }
virtual ~Finally() {}
-
- virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
- *stack_depth += kElementCount;
- return previous_;
- }
};
// The body of a for/in loop.
@@ -250,14 +256,9 @@ class FullCodeGenerator: public AstVisitor {
static const int kElementCount = 5;
ForIn(FullCodeGenerator* codegen, ForInStatement* statement)
- : Iteration(codegen, statement) {
+ : Iteration(codegen, statement, kElementCount) {
}
virtual ~ForIn() {}
-
- virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
- *stack_depth += kElementCount;
- return previous_;
- }
};
@@ -265,7 +266,7 @@ class FullCodeGenerator: public AstVisitor {
class WithOrCatch : public NestedStatement {
public:
explicit WithOrCatch(FullCodeGenerator* codegen)
- : NestedStatement(codegen) {
+ : NestedStatement(codegen, 0) {
}
virtual ~WithOrCatch() {}
« no previous file with comments | « src/compiler.cc ('k') | src/full-codegen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698