Exemple #1
0
void Assignment::codeGen(CodeGenContext& context)
{
    if (debug)
        std::cout << "Creating assignment for " << lhs->m_name << endl;
    if (context.locals().find(lhs->m_name) == context.locals().end()) {
        std::cerr << "undeclared variable " << lhs->m_name << endl;
        return;
    }

    rhs->codeGen(context);
    context.vpop(context.locals()[lhs->m_name]->addr);
}
Exemple #2
0
void VariableDeclaration::codeGen(CodeGenContext& context)
{
    if (debug)
        std::cout << "Creating variable declaration " << m_type->m_name << " " << m_name->m_name << endl;

    context.locals()[m_name->m_name] = value();
    if (m_assignment_expr != NULL) {
        Assignment assn(m_name, m_assignment_expr);
        assn.codeGen(context);
    }
}
Exemple #3
0
void ForeachStatement::codeGen(CodeGenContext &context)
{
    m_var_decl->codeGen(context);
    m_expr->codeGen(context);
    context.vmake_iter();
    int pos = context.getCurrent();
    context.viter_value();
    context.vpop(context.locals()[m_var_decl->m_name->m_name]->addr);
    m_block->codeGen(context, false);
    context.vloop_iter(pos);
    context.vpop(444);
    context.vpop(444);
}