Initial import of prototype.
2 * Copyright (C) 2012 David Anderson
4 * This file is part of JITCraft.
6 * JITCraft is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * JITCraft. If not, see http://www.gnu.org/licenses/.
18 #ifndef _include_jitcraft_scopes_h_
19 #define _include_jitcraft_scopes_h_
22 #include "PoolAllocator.h"
24 #include "NameBinding.h"
28 class Scope : public PoolObject
31 std::vector<BoundName *> names_;
32 std::vector<Scope *> children_;
33 std::vector<Variable *> parameters_;
35 unsigned maxContainedLocals_;
36 unsigned numFunctions_;
39 return names_.size() == 0;
51 Scope(PoolAllocator &pool, Kind kind, Scope *enclosing);
57 Scope *enclosing() const {
60 unsigned locals() const {
63 unsigned maxContainedLocals() const {
64 return maxContainedLocals_;
66 unsigned numFunctions() const {
69 unsigned numArguments() const {
70 return parameters_.size();
72 Variable *getArgument(size_t index) {
73 return parameters_[index];
76 Scope *unlinkIfEmpty();
77 BoundName *localLookup(Name *name);
78 BoundName *lookup(Name *name);
79 NamedFunction *declareFunction(Name *name);
80 Variable *declareVariable(Name *name);
81 Variable *declareArgument(Name *name);
83 void allocateGlobals();
86 static bool BindAndAllocate(ParseTree *tree);
95 #endif // _include_jitcraft_scopes_h_