예제 #1
0
void BytecodeGenerator::secondRun(Scope * scope) {
  Scope::FunctionIterator it(scope);
  while (it.hasNext()) {
    AstFunction *func = it.next();
    BytecodeFunction *bcf =
        (BytecodeFunction*) code->functionByName(func->name());
    fBC = bcf->bytecode();
    currentFun = bcf->id();
    returnType = func->returnType();
    func->node()->body()->visit(this);
    bcf->setLocalsNumber(localsCounter[currentFun]);
  }

  for (size_t i = 0; i < scope->childScopeNumber(); ++i) {
    secondRun(scope->childScopeAt(i));
  }
}
예제 #2
0
void BytecodeVisitor::translateFunction(AstFunction *f) {
    BytecodeFunction* bf = (BytecodeFunction *) code_->functionByName(f->name());
    ScopeContext* new_context = new ScopeContext(bf, f->scope(), context_);
    context_ = new_context;

    for (uint i = 0; i < f->parametersNumber(); ++i) {
        AstVar* var = f->scope()->lookupVariable(f->parameterName(i), false);
        storeVar(var);
    }

    f->node()->visit(this);

    bf->setLocalsNumber(context_->getLocalsNum());
    bf->setScopeId(context_->getId());

    context_ = new_context->getParent();
    delete new_context;

}