jitcraft/RootScopes.cpp
author David Anderson <dvander@alliedmods.net>
Tue Jul 03 00:36:48 2012 -0700 (2012-07-03)
changeset 33 95baf120f7d4
parent 29 c0e27b4f0672
child 45 25b995bc75a0
permissions -rw-r--r--
Handle-ize BytecodeEmitter.
     1 /* vim: set ts=4 sw=4 tw=99 et:
     2  *
     3  * Copyright (C) 2012 David Anderson
     4  *
     5  * This file is part of JITCraft.
     6  *
     7  * JITCraft is free software: you can redistribute it and/or modify it under
     8  * the terms of the GNU General Public License as published by the Free
     9  * Software Foundation, either version 3 of the License, or (at your option)
    10  * any later version.
    11  * 
    12  * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License along with
    17  * JITCraft. If not, see http://www.gnu.org/licenses/.
    18  */
    19 #include "RootScopes.h"
    20 
    21 using namespace jc;
    22 
    23 RootScopeManager::RootScopeManager()
    24   : blocks_(&first_),
    25     first_(NULL),
    26     scope_(NULL)
    27 {
    28 }
    29 
    30 RootScopeManager::~RootScopeManager()
    31 {
    32     while (blocks_ != &first_) {
    33         Block *temp = blocks_;
    34         delete blocks_;
    35         blocks_ = temp;
    36     }
    37 }
    38 
    39 bool
    40 RootScopeManager::grow()
    41 {
    42     assert(blocks_->cur == blocks_->end);
    43 
    44     Block *block = new Block(blocks_);
    45     if (!block)
    46         return false;
    47 
    48     blocks_ = block;
    49     return true;
    50 }
    51 
    52 void
    53 RootScopeManager::unwindSlow(Object **pos)
    54 {
    55     for (;;) {
    56         if (pos >= blocks_->cur && pos <= blocks_->end)
    57             break;
    58         assert(blocks_ != &first_);
    59         Block *temp = blocks_;
    60         delete blocks_;
    61         blocks_ = temp;
    62     }
    63 
    64     blocks_->cur = pos;
    65 }
    66