jitcraft/RootScopes.cpp
author David Anderson <dvander@alliedmods.net>
Sun Jul 08 01:54:08 2012 -0700 (2012-07-08)
changeset 60 581a9c793062
parent 59 b7d61ddb3c8d
child 64 11c81eb30246
permissions -rw-r--r--
Initial import of some kind of API.
     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 ke;
    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_->objects && 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 
    67 void
    68 RootScopeManager::accept(VirtualObjectVisitor *visitor)
    69 {
    70     Block *block = blocks_;
    71     while (block) {
    72         for (Object **ptr = block->objects; ptr < block->cur; ptr++)
    73             visitor->visit(ptr);
    74         block = block->prev;
    75     }
    76 }