12 static int do_debug
= -1;
13 void debug(const char *fmt
, ...) {
16 do_debug
= !!getenv("DEBUG");
19 vfprintf(stderr
, fmt
, ap
);
27 for (int i
= 0; i
< len
; i
++)
32 int main(int argc
, char **argv
) {
33 int i
, *pc
, count
= 0;
37 if (!(stdin
= freopen(argv
[1], "r", stdin
))) {
42 while (scanf("%d%*[,\n]", &i
) == 1) {
45 printf("recompile with larger LIMIT\n");
49 printf("Read %u slots\n", len
);
63 debug("executing %d,%d(%d),%d(%d),%d\n", pc
[0], pc
[1], a
[pc
[1]],
64 pc
[2], a
[pc
[2]], pc
[3]);
65 if (pc
- a
>= len
|| pc
[1] >= len
|| pc
[2] >= len
|| pc
[3] >= len
) {
66 printf("out-of-bounds reference at instruction %d\n", (int)(pc
- a
));
72 a
[pc
[3]] = a
[pc
[1]] + a
[pc
[2]];
75 a
[pc
[3]] = a
[pc
[1]] * a
[pc
[2]];
84 printf("after %d opcodes, slot 0 holds %d\n", count
, a
[0]);