diff -r 8f1e74d35718 -r 4d6265f95ff1 jitcraft/Scopes.cpp --- a/jitcraft/Scopes.cpp Sat Jul 07 21:01:39 2012 -0700 +++ b/jitcraft/Scopes.cpp Sat Jul 07 21:08:47 2012 -0700 @@ -38,8 +38,8 @@ bool Scope::initialize() { - if (enclosing_) - enclosing_->children_.push_back(this); + if (enclosing_ && !enclosing_->children_.append(this)) + return false; return true; } @@ -48,11 +48,13 @@ { assert(empty()); - assert(enclosing_->children_[enclosing_->children_.size() - 1] == this); - enclosing_->children_.pop_back(); + assert(enclosing_->children_[enclosing_->children_.length() - 1] == this); + enclosing_->children_.pop(); - for (size_t i = 0; i < children_.size(); i++) - enclosing_->children_.push_back(children_[i]); + // OOM here is swallowed and checked after compilation. + // :TODO: make the above true. + for (size_t i = 0; i < children_.length(); i++) + enclosing_->children_.append(children_[i]); } Scope * @@ -68,7 +70,7 @@ BoundName * Scope::localLookup(Handle name) { - for (size_t i = 0; i < names_.size(); i++) { + for (size_t i = 0; i < names_.length(); i++) { if (names_[i]->name() == name) return names_[i]; } @@ -91,7 +93,8 @@ assert(!localLookup(name)); Variable *var = new (pool_) Variable(this, name, pos); - names_.push_back(var); + if (!names_.append(var)) + return NULL; return var; } @@ -100,8 +103,10 @@ { assert(kind() == FUNCTION); Variable *var = declareVariable(name, pos); - names_.push_back(var); - parameters_.push_back(var); + if (!names_.append(var)) + return NULL; + if (!parameters_.append(var)) + return NULL; return var; } @@ -112,7 +117,8 @@ assert(kind() == GLOBAL); NamedFunction *fun = new (pool_) NamedFunction(this, name, pos); - names_.push_back(fun); + if (!names_.append(fun)) + return NULL; return fun; } @@ -120,7 +126,8 @@ Scope::declareEnum(Handle name, const SourcePosition &pos) { NamedEnum *e = new (pool_) NamedEnum(this, name, pos); - names_.push_back(e); + if (!names_.append(e)) + return NULL; return e; } @@ -128,7 +135,8 @@ Scope::declareConstant(Handle name, const SourcePosition &pos) { NamedConstant *constant = new (pool_) NamedConstant(this, name, pos); - names_.push_back(constant); + if (!names_.append(constant)) + return NULL; return constant; } @@ -137,12 +145,12 @@ { assert(kind() == GLOBAL); - for (size_t i = 0; i < children_.size(); i++) { + for (size_t i = 0; i < children_.length(); i++) { assert(children_[i]->kind() == FUNCTION); children_[i]->allocate(); } - for (size_t i = 0; i < names_.size(); i++) { + for (size_t i = 0; i < names_.length(); i++) { BoundName *name = names_[i]; if (name->kind() == BoundName::FUNCTION) { @@ -166,19 +174,19 @@ Scope::allocate() { maxContainedLocals_ = 0; - for (size_t i = 0; i < children_.size(); i++) { + for (size_t i = 0; i < children_.length(); i++) { Scope *scope = children_[i]; scope->allocate(); if (scope->maxContainedLocals() > maxContainedLocals_) maxContainedLocals_ = scope->maxContainedLocals(); } - for (size_t i = 0; i < parameters_.size(); i++) + for (size_t i = 0; i < parameters_.length(); i++) parameters_[i]->allocate(Variable::PARAMETER, i); if (lifoSlot_) allocate(lifoSlot_); - for (size_t i = 0; i < names_.size(); i++) { + for (size_t i = 0; i < names_.length(); i++) { if (names_[i]->kind() != BoundName::VARIABLE) continue;