jitcraft/Scopes.cpp
changeset 85 06a0015b6a5c
parent 84 eaa43f765cbd
     1.1 --- a/jitcraft/Scopes.cpp	Fri Jul 20 00:03:10 2012 -0700
     1.2 +++ b/jitcraft/Scopes.cpp	Mon Jul 23 01:19:44 2012 -0700
     1.3 @@ -22,6 +22,7 @@
     1.4  #include "TypeManager.h"
     1.5  #include "Strings.h"
     1.6  #include "CompileContext.h"
     1.7 +#include "Environments.h"
     1.8  
     1.9  using namespace ke;
    1.10  
    1.11 @@ -152,6 +153,7 @@
    1.12          children_[i]->allocate();
    1.13      }
    1.14  
    1.15 +    Local<Type> type(ZONE());
    1.16      for (size_t i = 0; i < names_.length(); i++) {
    1.17          BoundName *name = names_[i];
    1.18          
    1.19 @@ -161,6 +163,8 @@
    1.20                  fun->allocate(numNatives_++);
    1.21              else
    1.22                  fun->allocate(numFunctions_++);
    1.23 +        } else if (name->kind() == BoundName::VARIABLE) {
    1.24 +            allocate(name->toVariable());
    1.25          }
    1.26      }
    1.27  }
    1.28 @@ -171,8 +175,13 @@
    1.29      if (!var->unallocated())
    1.30          return;
    1.31  
    1.32 -    var->allocate(Variable::STACK, maxContainedLocals_ + locals_);
    1.33 -    locals_++;
    1.34 +    if (kind() == GLOBAL) {
    1.35 +        var->allocate(Variable::ENVIRONMENT, envVars_.length());
    1.36 +        envVars_.append(var);
    1.37 +    } else {
    1.38 +        var->allocate(Variable::STACK, maxContainedLocals_ + locals_);
    1.39 +        locals_++;
    1.40 +    }
    1.41  }
    1.42  
    1.43  void
    1.44 @@ -256,3 +265,9 @@
    1.45      lifoSlot_ = new (pool_) Variable(this, name, SourcePosition());
    1.46      lifoSlot_->setType(type);
    1.47  }
    1.48 +
    1.49 +EnvironmentMap *
    1.50 +Scope::createEnvironmentMap(Zone *zone)
    1.51 +{
    1.52 +    return EnvironmentMap::New(zone, envVars_.length(), envVars_.buffer());
    1.53 +}