Stop using ccache on OS X.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
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)
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.
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/.
22 #include "TypeManager.h"
24 #include "CompileContext.h"
25 #include "Environments.h"
26 #include "Spaces-inl.h"
31 Scope::Scope(PoolAllocator &pool, Kind kind, Scope *enclosing)
34 maxContainedLocals_(0),
46 if (enclosing_ && !enclosing_->children_.append(this))
56 assert(enclosing_->children_[enclosing_->children_.length() - 1] == this);
57 enclosing_->children_.pop();
59 // OOM here is swallowed and checked after compilation.
60 // :TODO: make the above true.
61 for (size_t i = 0; i < children_.length(); i++)
62 enclosing_->children_.append(children_[i]);
66 Scope::unlinkIfEmpty()
76 Scope::localLookup(Handle<String> name)
78 for (size_t i = 0; i < names_.length(); i++) {
79 if (names_[i]->name() == name)
86 Scope::lookup(Handle<String> name)
88 for (Scope *scope = this; scope; scope = scope->enclosing()) {
89 if (BoundName *bound = scope->localLookup(name))
96 Scope::declareVariable(Handle<String> name, const SourcePosition &pos)
98 assert(!localLookup(name));
100 Variable *var = new (pool_) Variable(this, name, pos);
101 if (!names_.append(var))
107 Scope::declareArgument(Handle<String> name, const SourcePosition &pos)
109 assert(kind() == FUNCTION);
110 Variable *var = declareVariable(name, pos);
111 if (!names_.append(var))
113 if (!parameters_.append(var))
119 Scope::declareFunction(Handle<String> name, const SourcePosition &pos, TokenKind token)
121 assert(!localLookup(name));
122 assert(kind() == GLOBAL);
124 NamedFunction *fun = new (pool_) NamedFunction(this, name, pos, token);
125 if (!names_.append(fun))
131 Scope::declareEnum(Handle<String> name, const SourcePosition &pos)
133 NamedEnum *e = new (pool_) NamedEnum(this, name, pos);
134 if (!names_.append(e))
140 Scope::declareConstant(Handle<String> name, const SourcePosition &pos)
142 NamedConstant *constant = new (pool_) NamedConstant(this, name, pos);
143 if (!names_.append(constant))
149 Scope::allocateGlobals()
151 assert(kind() == GLOBAL);
153 for (size_t i = 0; i < children_.length(); i++) {
154 assert(children_[i]->kind() == FUNCTION);
155 children_[i]->allocate();
158 Local<Type> type(ZONE());
159 for (size_t i = 0; i < names_.length(); i++) {
160 BoundName *name = names_[i];
162 if (name->kind() == BoundName::FUNCTION) {
163 NamedFunction *fun = name->toNamedFunction();
165 fun->allocate(numNatives_++);
167 fun->allocate(numFunctions_++);
168 } else if (name->kind() == BoundName::VARIABLE) {
169 allocate(name->toVariable());
175 Scope::allocate(Variable *var)
177 if (!var->unallocated())
180 if (kind() == GLOBAL) {
181 var->allocate(Variable::ENVIRONMENT, envVars_.length());
182 envVars_.append(var);
184 var->allocate(Variable::STACK, maxContainedLocals_ + locals_);
192 maxContainedLocals_ = 0;
193 for (size_t i = 0; i < children_.length(); i++) {
194 Scope *scope = children_[i];
196 if (scope->maxContainedLocals() > maxContainedLocals_)
197 maxContainedLocals_ = scope->maxContainedLocals();
200 for (size_t i = 0; i < parameters_.length(); i++)
201 parameters_[i]->allocate(Variable::PARAMETER, i);
205 for (size_t i = 0; i < names_.length(); i++) {
206 if (names_[i]->kind() != BoundName::VARIABLE)
209 allocate(names_[i]->toVariable());
212 maxContainedLocals_ += locals_;
216 Scope::Bind(CompileContext &cc, ParseTree *tree)
218 Local<String> name(ZONE());
219 for (size_t i = 0; i < tree->unbound()->length(); i++) {
220 NameProxy *proxy = tree->unbound()->at(i);
221 name = proxy->name();
222 BoundName *binding = tree->scope()->lookup(name);
225 cc.reportError(proxy->pos(), Message_IdentifierNotFound, name->chars());
229 // We only allow global functions to be late-bound.
230 if (binding->kind() != BoundName::FUNCTION ||
231 binding->scope()->kind() != Scope::GLOBAL)
233 cc.reportError(proxy->pos(), Message_IdentifierNotFound, name->chars());
237 proxy->bind(binding);
243 Scope::Allocate(ParseTree *tree)
245 tree->scope()->allocateGlobals();
249 Scope::setUsesLifoHeap()
251 // Only one lifo slot is needed per scope.
255 // If the parent of this scope is the function scope, then this is the
256 // function's block scope, and the lifo slot is part of the Frame instead.
257 // Note we can get a function scope here if we're making a temporary in a
258 // function with no local variables.
259 if (kind() == FUNCTION || enclosing()->kind() == FUNCTION)
262 Local<Type> type(ZONE(), ZONE()->types()->getPrimitive(PrimitiveType_Native));
266 Local<String> name(ZONE());
267 lifoSlot_ = new (pool_) Variable(this, name, SourcePosition());
268 lifoSlot_->setType(type);
272 Scope::createEnvironmentMap(Zone *zone)
274 return EnvironmentMap::New(zone, envVars_.length(), envVars_.buffer());