Exemple #1
0
void
outcmd(int ch, int count)
{
    struct instruction * n;

    /* I need to count 'print' commands for the java functions */
    if (ch == '"') { add_cstring(get_string()); return; }

    n = node_calloc();
    n->ch = ch;
    n->count = count;
    n->icount = ++icount;
    n->prev = last;
    if (!last) {
        pgm = n;
    } else {
        last->next = n;
    }
    last = n;

    if (n->ch == '[') {
        n->loop = jmpstack; jmpstack = n;
    } else if (n->ch == ']') {
        n->loop = jmpstack; jmpstack = jmpstack->loop; n->loop->loop = n;
    } else if (ch == '"')
        n->cstr = strdup(get_string());

    if (ch != '~') return;

    last->ch = '}';	/* Make the end an end function */

    if (icount > MAXINSTR)
	reformat();

    for(n=pgm; n; n=n->next)
	loutcmd(n->ch, n->count, n);

    loutcmd('}', 0,0);	/* End of the class */

    while(pgm) {
        n = pgm;
        pgm = pgm->next;
        if (n->cstr)
            free(n->cstr);
        memset(n, '\0', sizeof*n);
        free(n);
    }
}
Exemple #2
0
void
outcmd(int ch, int count)
{
    struct instruction * n = calloc(1, sizeof*n), *n2;
    if (!n) { perror("bf2pas"); exit(42); }

    icount ++;
    n->ch = ch;
    n->count = count;
    n->icount = icount;
    if (ch == '"')
	n->cstr=strdup(get_string());
    if (!last) {
	pgm = n;
    } else {
	last->next = n;
    }
    last = n;

    if (n->ch == '[') {
	n->ino = ++lblcount;
	n->loop = jmpstack; jmpstack = n;
    } else if (n->ch == ']') {
	n->loop = jmpstack; jmpstack = jmpstack->loop; n->loop->loop = n;
    }

    if (ch != '~') return;

    loutcmd(0, 0, 0);

    if (icount < MAXWHILE) {
	for(n=pgm; n; n=n->next)
	    loutcmd(n->ch, n->count, n);
    } else {
	for(n=pgm; n; n=n->next) {
	    if (n->ch != ']') continue;
	    if (n->icount-n->loop->icount <= MAXWHILE) continue;
	    loutcmd(1000, 1, n->loop);
	    for(n2 = n->loop->next; n != n2; n2=n2->next) {
		if (n2->ch == '[' && n2->loop->icount-n2->icount > MAXWHILE) {
		    loutcmd(n2->ch, n2->count, n);
		    prv("bf%d()", n2->ino);
		    n2 = n2->loop;
		    loutcmd(n2->ch, n2->count, n);
		} else
		    loutcmd(n2->ch, n2->count, n2);
	    }
	    loutcmd(1001, 1, n);
	}

	for(n=pgm; n; n=n->next) {
	    if (n->ch != '[' || n->loop->icount-n->icount <= MAXWHILE)
		loutcmd(n->ch, n->count, n);
	    else {
		loutcmd(n->ch, n->count, n);
		prv("bf%d()", n->ino);
		n=n->loop;
		loutcmd(n->ch, n->count, n);
	    }
	}
    }

    while(pgm) {
	n = pgm;
	pgm = pgm->next;
	if (n->cstr)
            free(n->cstr);
	memset(n, '\0', sizeof*n);
	free(n);
    }
}