4 #include "mTaskSymbols.h"
7 #define PROGRAMSIZE 1024
11 #define debug(s, ...) printf(s, ##__VA_ARGS__);
13 #define debug(s, ...) ;
16 #define die(s, ...) {fprintf(stderr, s, ##__VA_ARGS__); return 1;}
18 char program
[PROGRAMSIZE
+1] = {0};
19 int stack
[STACKSIZE
+1] = {0};
21 bool input_available(){
28 select(1, &fds
, NULL
, NULL
, &tv
);
29 return FD_ISSET(0, &fds
);
40 while ((c
= getchar()) != EOF
&& pc
< PROGRAMSIZE
)
42 if (pc
>= PROGRAMSIZE
)
43 die("Max program size: %d\n", PROGRAMSIZE
);
45 debug("Done reading, program length: %d\n", pl
);
48 //Reset program counter and stack counter
52 switch(program
[pc
++]){
56 stack
[sp
++] = program
[pc
++];
62 stack
[sp
] = stack
[sp
] > 0 ? 0 : 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 stack
[sp
-1] = stack
[sp
] > stack
[sp
-1];
105 stack
[sp
-1] = stack
[sp
] <= stack
[sp
-1];
109 stack
[sp
-1] = stack
[sp
] >= stack
[sp
-1];
113 pc
= pc
+ program
[pc
];
116 pc
+= stack
[sp
] ? program
[pc
] : 1;
119 pc
+= stack
[sp
] ? 1 : program
[pc
];
122 printf("SerialAvailable()\n");
125 printf("SerialPrint()\n");
127 case BCSERIALPRINTLN
:
128 printf("SerialPrintln()\n");
131 printf("SerialRead()\n");
133 case BCSERIALPARSEINT
:
134 printf("SerialParseInt()\n");
137 printf("AnalogRead()\n");
140 printf("AnalogWrite()\n");
142 die("Unrecognized command: %X\n", program
[--pc
]);