src/Stack.h
changeset 230 fb3cd08bc7fb
parent 86 32ad0523b309
child 263 ba85a47ee414
     1.1 --- a/src/Stack.h	Sat Dec 22 16:42:20 2012 -0800
     1.2 +++ b/src/Stack.h	Sat Dec 22 18:22:14 2012 -0800
     1.3 @@ -66,7 +66,14 @@
     1.4          Object *callee_;
     1.5      };
     1.6      Code *code_;
     1.7 +
     1.8 +    // Position of the LIFO stack at function entry.
     1.9      Address lifoPosition_;
    1.10 +    
    1.11 +    // Loop nesting level, for LIFO stack balancing. LIFO stack balancing
    1.12 +    // is not strictly required, but it helps to avoid unnecessary waste,
    1.13 +    // since once the LIFO stack is depleted, we must use the heap instead.
    1.14 +    unsigned loopDepth_;
    1.15  
    1.16    public:
    1.17      Frame(Frame *prev, bytecode *prevpc, Function *fun, Code *code, Address lifoPosition)
    1.18 @@ -74,7 +81,8 @@
    1.19          prevpc_(prevpc),
    1.20          fun_(fun),
    1.21          code_(code),
    1.22 -        lifoPosition_(lifoPosition)
    1.23 +        lifoPosition_(lifoPosition),
    1.24 +        loopDepth_(0)
    1.25      {
    1.26      }
    1.27  
    1.28 @@ -87,8 +95,11 @@
    1.29      {
    1.30      }
    1.31  
    1.32 +    Address *loopStack() {
    1.33 +        return reinterpret_cast<Address *>(this + 1);
    1.34 +    }
    1.35      LocalSlot *locals() {
    1.36 -        return reinterpret_cast<LocalSlot *>(this + 1);
    1.37 +        return reinterpret_cast<LocalSlot *>(loopStack() + code_->maxLoopDepth());
    1.38      }
    1.39      LocalSlot *stackBase() {
    1.40          return locals() + code_->nlocals();
    1.41 @@ -124,6 +135,8 @@
    1.42          assert(slot < fun()->nargs());
    1.43          return *(reinterpret_cast<LocalSlot *>(this) - slot - 1);
    1.44      }
    1.45 +    void enterLoop(Zone *zone);
    1.46 +    void leaveLoop(Zone *zone);
    1.47      void accept(VirtualObjectVisitor *visitor);
    1.48  };
    1.49