1.1 --- a/jitcraft/Scopes.cpp Sat Jul 07 21:01:39 2012 -0700
1.2 +++ b/jitcraft/Scopes.cpp Sat Jul 07 21:08:47 2012 -0700
1.3 @@ -38,8 +38,8 @@
1.4 bool
1.5 Scope::initialize()
1.6 {
1.7 - if (enclosing_)
1.8 - enclosing_->children_.push_back(this);
1.9 + if (enclosing_ && !enclosing_->children_.append(this))
1.10 + return false;
1.11 return true;
1.12 }
1.13
1.14 @@ -48,11 +48,13 @@
1.15 {
1.16 assert(empty());
1.17
1.18 - assert(enclosing_->children_[enclosing_->children_.size() - 1] == this);
1.19 - enclosing_->children_.pop_back();
1.20 + assert(enclosing_->children_[enclosing_->children_.length() - 1] == this);
1.21 + enclosing_->children_.pop();
1.22
1.23 - for (size_t i = 0; i < children_.size(); i++)
1.24 - enclosing_->children_.push_back(children_[i]);
1.25 + // OOM here is swallowed and checked after compilation.
1.26 + // :TODO: make the above true.
1.27 + for (size_t i = 0; i < children_.length(); i++)
1.28 + enclosing_->children_.append(children_[i]);
1.29 }
1.30
1.31 Scope *
1.32 @@ -68,7 +70,7 @@
1.33 BoundName *
1.34 Scope::localLookup(Handle<String> name)
1.35 {
1.36 - for (size_t i = 0; i < names_.size(); i++) {
1.37 + for (size_t i = 0; i < names_.length(); i++) {
1.38 if (names_[i]->name() == name)
1.39 return names_[i];
1.40 }
1.41 @@ -91,7 +93,8 @@
1.42 assert(!localLookup(name));
1.43
1.44 Variable *var = new (pool_) Variable(this, name, pos);
1.45 - names_.push_back(var);
1.46 + if (!names_.append(var))
1.47 + return NULL;
1.48 return var;
1.49 }
1.50
1.51 @@ -100,8 +103,10 @@
1.52 {
1.53 assert(kind() == FUNCTION);
1.54 Variable *var = declareVariable(name, pos);
1.55 - names_.push_back(var);
1.56 - parameters_.push_back(var);
1.57 + if (!names_.append(var))
1.58 + return NULL;
1.59 + if (!parameters_.append(var))
1.60 + return NULL;
1.61 return var;
1.62 }
1.63
1.64 @@ -112,7 +117,8 @@
1.65 assert(kind() == GLOBAL);
1.66
1.67 NamedFunction *fun = new (pool_) NamedFunction(this, name, pos);
1.68 - names_.push_back(fun);
1.69 + if (!names_.append(fun))
1.70 + return NULL;
1.71 return fun;
1.72 }
1.73
1.74 @@ -120,7 +126,8 @@
1.75 Scope::declareEnum(Handle<String> name, const SourcePosition &pos)
1.76 {
1.77 NamedEnum *e = new (pool_) NamedEnum(this, name, pos);
1.78 - names_.push_back(e);
1.79 + if (!names_.append(e))
1.80 + return NULL;
1.81 return e;
1.82 }
1.83
1.84 @@ -128,7 +135,8 @@
1.85 Scope::declareConstant(Handle<String> name, const SourcePosition &pos)
1.86 {
1.87 NamedConstant *constant = new (pool_) NamedConstant(this, name, pos);
1.88 - names_.push_back(constant);
1.89 + if (!names_.append(constant))
1.90 + return NULL;
1.91 return constant;
1.92 }
1.93
1.94 @@ -137,12 +145,12 @@
1.95 {
1.96 assert(kind() == GLOBAL);
1.97
1.98 - for (size_t i = 0; i < children_.size(); i++) {
1.99 + for (size_t i = 0; i < children_.length(); i++) {
1.100 assert(children_[i]->kind() == FUNCTION);
1.101 children_[i]->allocate();
1.102 }
1.103
1.104 - for (size_t i = 0; i < names_.size(); i++) {
1.105 + for (size_t i = 0; i < names_.length(); i++) {
1.106 BoundName *name = names_[i];
1.107
1.108 if (name->kind() == BoundName::FUNCTION) {
1.109 @@ -166,19 +174,19 @@
1.110 Scope::allocate()
1.111 {
1.112 maxContainedLocals_ = 0;
1.113 - for (size_t i = 0; i < children_.size(); i++) {
1.114 + for (size_t i = 0; i < children_.length(); i++) {
1.115 Scope *scope = children_[i];
1.116 scope->allocate();
1.117 if (scope->maxContainedLocals() > maxContainedLocals_)
1.118 maxContainedLocals_ = scope->maxContainedLocals();
1.119 }
1.120
1.121 - for (size_t i = 0; i < parameters_.size(); i++)
1.122 + for (size_t i = 0; i < parameters_.length(); i++)
1.123 parameters_[i]->allocate(Variable::PARAMETER, i);
1.124
1.125 if (lifoSlot_)
1.126 allocate(lifoSlot_);
1.127 - for (size_t i = 0; i < names_.size(); i++) {
1.128 + for (size_t i = 0; i < names_.length(); i++) {
1.129 if (names_[i]->kind() != BoundName::VARIABLE)
1.130 continue;
1.131