10. Dump Program

To dump the program to human-readable text, use seqvm_dump.

<<funcdefs>>=
void seqvm_dump(seqvm *svm, FILE *fp);
<<funcs>>=
/* some fun macro abuse... */

#define DUMP3(CMD,VAL) \
    case CMD: \
        fprintf(fp, VAL " %d %d %d", c->p[0], c->p[1], c->p[2]); \
        break;
#define DUMP2(CMD,VAL) \
    case CMD: \
        fprintf(fp, VAL " %d %d", c->p[0], c->p[1]); \
        break;
#define DUMP1(CMD, VAL) \
    case CMD: \
        fprintf(fp, VAL " %d", c->p[0]); \
        break;
#define DUMP0(CMD, VAL) \
    case CMD: \
        fprintf(fp, VAL); \
        break;

void seqvm_dump(seqvm *svm, FILE *fp)
{
    int sz;
    int pos;
    sz = svm->size;

    for (pos = 0; pos < sz; pos++) {
        seqvm_cell *c;

        c = &svm->pool[pos];

        if (c->cmd == SEQVM_NONE) break;

        fprintf(fp, "%d ", pos);

        switch (c->cmd) {
<<dump>>
        }

        fprintf(fp, "\n");
    }
}



prev | home | next