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};
27 while ((c
= getchar()) != EOF
&& pc
< PROGRAMSIZE
)
29 if (pc
>= PROGRAMSIZE
)
30 die("Max program size: %d\n", PROGRAMSIZE
);
32 debug("Done reading, program length: %d\n", pl
);
35 //Reset program counter and stack counter
39 switch(program
[pc
++]){
43 stack
[sp
++] = program
[pc
++];
49 stack
[sp
] = stack
[sp
] > 0 ? 0 : 1;
52 stack
[sp
-1] = stack
[sp
] + stack
[sp
-1];
56 stack
[sp
-1] = stack
[sp
] - stack
[sp
-1];
60 stack
[sp
-1] = stack
[sp
] * stack
[sp
-1];
64 stack
[sp
-1] = stack
[sp
] / stack
[sp
-1];
68 stack
[sp
-1] = stack
[sp
] && stack
[sp
-1];
72 stack
[sp
-1] = stack
[sp
] || stack
[sp
-1];
76 stack
[sp
-1] = stack
[sp
] == stack
[sp
-1];
80 stack
[sp
-1] = stack
[sp
] != stack
[sp
-1];
84 stack
[sp
-1] = stack
[sp
] < stack
[sp
-1];
88 stack
[sp
-1] = stack
[sp
] > stack
[sp
-1];
92 stack
[sp
-1] = stack
[sp
] <= stack
[sp
-1];
96 stack
[sp
-1] = stack
[sp
] >= stack
[sp
-1];
100 pc
= pc
+ program
[pc
];
103 pc
+= stack
[sp
] ? program
[pc
] : 1;
106 pc
+= stack
[sp
] ? 1 : program
[pc
];
109 printf("SerialAvailable()\n");
112 printf("SerialPrint()\n");
114 case BCSERIALPRINTLN
:
115 printf("SerialPrintln()\n");
118 printf("SerialRead()\n");
120 case BCSERIALPARSEINT
:
121 printf("SerialParseInt()\n");
124 printf("AnalogRead()\n");
127 printf("AnalogWrite()\n");
129 die("Unrecognized command: %X\n", program
[--pc
]);