3 #include "mTaskSymbols.h"
6 #define PROGRAMSIZE 1024
10 #define debug(s, ...) printf(s, ##__VA_ARGS__);
12 #define debug(s, ...) ;
15 #define die(s, ...) {fprintf(stderr, s, ##__VA_ARGS__); return 1;}
17 char program
[PROGRAMSIZE
+1] = {0};
18 int stack
[STACKSIZE
+1] = {0};
28 while ((c
= getchar()) != EOF
&& pc
< PROGRAMSIZE
)
30 if (pc
>= PROGRAMSIZE
)
31 die("Max program size: %d\n", PROGRAMSIZE
);
33 debug("Done reading, program length: %d\n", pl
);
36 //Reset program counter and stack counter
40 switch(program
[pc
++]){
44 stack
[sp
++] = program
[pc
++];
50 stack
[sp
] = stack
[sp
] > 0 ? 0 : 1;
53 stack
[sp
-1] = stack
[sp
] + stack
[sp
-1];
57 stack
[sp
-1] = stack
[sp
] - stack
[sp
-1];
61 stack
[sp
-1] = stack
[sp
] * stack
[sp
-1];
65 stack
[sp
-1] = stack
[sp
] / stack
[sp
-1];
69 stack
[sp
-1] = stack
[sp
] && stack
[sp
-1];
73 stack
[sp
-1] = stack
[sp
] || stack
[sp
-1];
77 stack
[sp
-1] = stack
[sp
] == stack
[sp
-1];
81 stack
[sp
-1] = stack
[sp
] != stack
[sp
-1];
85 stack
[sp
-1] = stack
[sp
] < stack
[sp
-1];
89 stack
[sp
-1] = stack
[sp
] > stack
[sp
-1];
93 stack
[sp
-1] = stack
[sp
] <= stack
[sp
-1];
97 stack
[sp
-1] = stack
[sp
] >= stack
[sp
-1];
101 pc
= pc
+ program
[pc
];
105 pc
= pc
+ program
[pc
];
113 pc
= pc
+ program
[pc
];
116 die("Unrecognized command: %X\n", program
[--pc
]);