generate.c
static void code_for_statement(GenerateContext *c, ParseTreeNode *node)
{
    VMUVALUE nxt, upd, inst;
    PVAL pv;
    code_rvalue(c, node->u.forStatement.startExpr);
    code_lvalue(c, node->u.forStatement.var, &pv);
    putcbyte(c, OP_BR);
    upd = putcword(c, 0);
    nxt = codeaddr(c);
    code_statement_list(c, node->u.forStatement.bodyStatements);
    (*pv.fcn)(c, PV_LOAD, &pv);
    if (node->u.forStatement.stepExpr)
        code_rvalue(c, node->u.forStatement.stepExpr);
    else {
        putcbyte(c, OP_SLIT);
        putcbyte(c, 1);
    }
    putcbyte(c, OP_ADD);
    fixupbranch(c, upd, codeaddr(c));
    putcbyte(c, OP_DUP);
    (*pv.fcn)(c, PV_STORE, &pv);
    code_rvalue(c, node->u.forStatement.endExpr);
    putcbyte(c, OP_LE);
    inst = putcbyte(c, OP_BRT);
    putcword(c, nxt - inst - 1 - sizeof(VMVALUE));
}
/* code_for_statement - generate code for a FOR statement */
generate code for a FOR statement
generate code for a FOR statement
static void code_for_statement(GenerateContext *c, ParseTreeNode *node)
{
    VMUVALUE nxt, upd, inst;
    PVAL pv;
    code_rvalue(c, node->u.forStatement.startExpr);
    code_lvalue(c, node->u.forStatement.var, &pv);
    putcbyte(c, OP_BR);
    upd = putcword(c, 0);
    nxt = codeaddr(c);
    code_statement_list(c, node->u.forStatement.bodyStatements);
    (*pv.fcn)(c, PV_LOAD, &pv);
    if (node->u.forStatement.stepExpr)
        code_rvalue(c, node->u.forStatement.stepExpr);
    else {
        putcbyte(c, OP_SLIT);
        putcbyte(c, 1);
    }
    putcbyte(c, OP_ADD);
    fixupbranch(c, upd, codeaddr(c));
    putcbyte(c, OP_DUP);
    (*pv.fcn)(c, PV_STORE, &pv);
    code_rvalue(c, node->u.forStatement.endExpr);
    putcbyte(c, OP_LE);
    inst = putcbyte(c, OP_BRT);
    putcword(c, nxt - inst - 1 - sizeof(VMVALUE));
}
static void code_for_statement ( GenerateContext * c , ParseTreeNode * node ) { VMUVALUE nxt , upd , inst ; PVAL pv ; code_rvalue ( c , node -> u . forStatement . startExpr ) ; code_lvalue ( c , node -> u . forStatement . var , & pv ) ; putcbyte ( c , OP_BR ) ; upd = putcword ( c , 0 ) ; nxt = codeaddr ( c ) ; code_statement_list ( c , node -> u . forStatement . bodyStatements ) ; ( * pv . fcn ) ( c , PV_LOAD , & pv ) ; if ( node -> u . forStatement . stepExpr ) code_rvalue ( c , node -> u . forStatement . stepExpr ) ; else { putcbyte ( c , OP_SLIT ) ; putcbyte ( c , 1 ) ; } putcbyte ( c , OP_ADD ) ; fixupbranch ( c , upd , codeaddr ( c ) ) ; putcbyte ( c , OP_DUP ) ; ( * pv . fcn ) ( c , PV_STORE , & pv ) ; code_rvalue ( c , node -> u . forStatement . endExpr ) ; putcbyte ( c , OP_LE ) ; inst = putcbyte ( c , OP_BRT ) ; putcword ( c , nxt - inst - 1 - sizeof ( VMVALUE ) ) ; }
code_for_statement - generate code for a FOR statement
code_for_statement - generate code for a FOR statement