6. Stack

<<funcdefs>>=
int bitlang_pop(bitlang *vm, int *x);
<<funcs>>=
int bitlang_pop(bitlang *vm, int *x)
{
    if (vm->stkpos < 0) {
        vm->err = 1;
        return 1;
    }

    *x = vm->stk[vm->stkpos];
    vm->stkpos--;
    return 0;
}
<<funcdefs>>=
int bitlang_push(bitlang *vm, int x);
<<funcs>>=
int bitlang_push(bitlang *vm, int x)
{
    if (vm->stkpos >= 8) return 1;

    vm->stkpos++;
    vm->stk[vm->stkpos] = x;

    return 0;
}



prev | home | next