-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterp_raw.c
More file actions
57 lines (56 loc) · 948 Bytes
/
interp_raw.c
File metadata and controls
57 lines (56 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include "main.h"
void interpretRaw(Node* n, CELL_T* m, size_t* i) {
if (n == NULL) {
return;
}
switch (n->type) {
case LOOP:
while (m[*i]) {
interpretRaw(n->n[0].n, m, i);
}
break;
case STMTS:
interpretRaw(n->n[0].n, m, i);
interpretRaw(n->n[1].n, m, i);
break;
case SUM:
m[*i + n->n[1].i] += n->n[0].i;
break;
case SHIFT:
*i += n->n[0].i;
break;
case OUT: {
int off = n->n[0].i;
putchar(m[*i + off]);
fflush(stdout);
}
break;
case IN: {
int off = n->n[0].i;
m[*i + off] = readChar(m[*i + off]);
}
break;
case SET: {
int off = n->n[0].i;
for (int k = 1; k < n->sz; k++) {
Point *p = n->n[k].p;
int x = p->x;
int y = p->y;
int scale = p->z;
m[*i+x+off] += (y*m[*i+off])/scale;
}
m[*i+off] = 0;
}
break;
}
}
void interpRaw() {
CELL_T m[numCells];
for (int z = 0; z < numCells; z++) {
m[z] = 0;
}
size_t i[1] = {0};
I = i;
interpretRaw(root, m, i);
}