6. Step

<<funcdefs>>=
void trig_vm_step(trig_vm *vm);

When a VM step happens, it will run through the program until it reaches a pattern cell or an empty cell. Some protection is done to ensure that an infinite loop doesn't happen.

This now wraps around trig_vm_step_state using the internal state file. See that function for more detail.s

<<funcs>>=
void trig_vm_step(trig_vm *vm)
{
    trig_vm_step_state(vm, &vm->istate);
}

This trig_vm_step_state steps with an external state. This can be used to allow multiple readers to happen concurrently.

<<funcdefs>>=
void trig_vm_step_state(trig_vm *vm, trig_state *ts);
<<funcs>>=
void trig_vm_step_state(trig_vm *vm, trig_state *ts)
{
    int count;
    vm->running = 1;

    count = 0;
    vm->state = ts;
    while (vm->running) {
        trig_cell *c;

        count++;

        if (count >= 64) {
            fprintf(stderr,
            "trig: max count of 64 reached. "
            "breaking.\n");
            vm->running = 0;
            break;
        }

        if (ts->pos < 0 || ts->pos >= 32) {
            fprintf(stderr,
                    "trig: invalid position %d\n",
                    ts->pos);
            vm->running = 0;
            break;
        }
        c = &vm->cell[ts->pos];
        ts->pos = trig_vm_ex(vm, ts->pos, c->cmd, c->data);
    }

    vm->state = &vm->istate;
}



prev | home | next