jitcraft/RootScopes.cpp
changeset 29 c0e27b4f0672
child 45 25b995bc75a0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/jitcraft/RootScopes.cpp	Tue Jul 03 00:21:37 2012 -0700
     1.3 @@ -0,0 +1,66 @@
     1.4 +/* vim: set ts=4 sw=4 tw=99 et:
     1.5 + *
     1.6 + * Copyright (C) 2012 David Anderson
     1.7 + *
     1.8 + * This file is part of JITCraft.
     1.9 + *
    1.10 + * JITCraft is free software: you can redistribute it and/or modify it under
    1.11 + * the terms of the GNU General Public License as published by the Free
    1.12 + * Software Foundation, either version 3 of the License, or (at your option)
    1.13 + * any later version.
    1.14 + * 
    1.15 + * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    1.16 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    1.18 + *
    1.19 + * You should have received a copy of the GNU General Public License along with
    1.20 + * JITCraft. If not, see http://www.gnu.org/licenses/.
    1.21 + */
    1.22 +#include "RootScopes.h"
    1.23 +
    1.24 +using namespace jc;
    1.25 +
    1.26 +RootScopeManager::RootScopeManager()
    1.27 +  : blocks_(&first_),
    1.28 +    first_(NULL),
    1.29 +    scope_(NULL)
    1.30 +{
    1.31 +}
    1.32 +
    1.33 +RootScopeManager::~RootScopeManager()
    1.34 +{
    1.35 +    while (blocks_ != &first_) {
    1.36 +        Block *temp = blocks_;
    1.37 +        delete blocks_;
    1.38 +        blocks_ = temp;
    1.39 +    }
    1.40 +}
    1.41 +
    1.42 +bool
    1.43 +RootScopeManager::grow()
    1.44 +{
    1.45 +    assert(blocks_->cur == blocks_->end);
    1.46 +
    1.47 +    Block *block = new Block(blocks_);
    1.48 +    if (!block)
    1.49 +        return false;
    1.50 +
    1.51 +    blocks_ = block;
    1.52 +    return true;
    1.53 +}
    1.54 +
    1.55 +void
    1.56 +RootScopeManager::unwindSlow(Object **pos)
    1.57 +{
    1.58 +    for (;;) {
    1.59 +        if (pos >= blocks_->cur && pos <= blocks_->end)
    1.60 +            break;
    1.61 +        assert(blocks_ != &first_);
    1.62 +        Block *temp = blocks_;
    1.63 +        delete blocks_;
    1.64 +        blocks_ = temp;
    1.65 +    }
    1.66 +
    1.67 +    blocks_->cur = pos;
    1.68 +}
    1.69 +