5. Compute/Tick
A single instruction is read through a command called
compute
. A tick
will compute until a halt is
reached.
<<funcdefs>>=
int seqvm_compute(seqvm *svm, seqvm_cell *c);
int seqvm_tick(seqvm *svm, int blkpos);
int seqvm_retick(seqvm *svm, int *start);
<<funcs>>=
int seqvm_compute(seqvm *svm, seqvm_cell *c)
{
int pos;
pos = svm->pos;
switch (c->cmd) {
<<compute>>
default:
pos++;
break;
}
return pos;
}
<<funcs>>=
int seqvm_tick(seqvm *svm, int blkpos)
{
int i;
svm->blkpos = blkpos;
svm->halt = 0;
for (i = 0; i < 128; i++) {
seqvm_cell *c;
if (svm->halt) {
return 0;
}
c = &svm->pool[svm->pos];
svm->pos = seqvm_compute(svm, c);
}
return -1;
}
<<funcs>>=
int seqvm_retick(seqvm *svm, int *start)
{
int i;
int save;
svm->halt = 0;
save = svm->pos;
svm->pos = *start;
for (i = 0; i < 128; i++) {
seqvm_cell *c;
if (svm->halt) {
*start = svm->pos;
svm->pos = save;
return 0;
}
c = &svm->pool[svm->pos];
svm->pos = seqvm_compute(svm, c);
}
*start = svm->pos;
svm->pos = save;
return -1;
}
prev | home | next