示例#1
0
void BytecodeVisitor::visitBlockNode(BlockNode *node) {

    Scope::VarIterator it_var(node->scope());
    while (it_var.hasNext()) {
        AstVar* var = it_var.next();
        context_->addVar(var);
    }

    Scope::FunctionIterator it_f(node->scope());
    while (it_f.hasNext()) {
        AstFunction* af = it_f.next();

        BytecodeFunction* bf = (BytecodeFunction*) code_->functionByName(af->name());
        if (!bf) {
            bf = new BytecodeFunction(af);
            code_->addFunction(bf);
        } else {
            throw new std::runtime_error("Uncorrect function");
        }
    }

    it_f = Scope::FunctionIterator(node->scope());
    while (it_f.hasNext()) {
        translateFunction(it_f.next());
    }

    for (uint i = 0; i < node->nodes(); ++i) {
        node->nodeAt(i)->visit(this);
    }

    setTosType(VT_VOID);
}
示例#2
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));
  }
}
示例#3
0
void BytecodeTranslatorVisitor::visitCallNode(CallNode* node) {
    onVisitNode(node);

    AstFunction* f = scope()->lookupFunction(node->name());
    if (!f) ERROR("Unknown function " + f->name());
    checkSignature(node, f);

    for (uint16_t i = 0; i < node->parametersNumber(); i++)
        visitTyped(node->parameterAt(i), f->parameterType(i));

    if (isNative(f))
        EMIT(BC_CALLNATIVE);
    else
        EMIT(BC_CALL);

    EMIT_ID(getFunctionId(f));

    pushType(f->returnType());
}