108 FVM_COLON(3, BACKWARD_RESOLVE, "<resolve")
124 #define THEN_CODE FORWARD_RESOLVE_CODE 137 #define BEGIN_CODE BACKWARD_MARK_CODE 155 #define WHILE_CODE IF_CODE 197 FVM_SYMBOL(24, COMPILED_WORDS, "compiled-words");
198 FVM_SYMBOL(25, GENERATE_CODE, "generate-code");
200 const
FVM::code_P
FVM::fntab[] PROGMEM = {
201 (code_P) &FORWARD_MARK_CODE,
202 (code_P) &FORWARD_RESOLVE_CODE,
203 (code_P) &BACKWARD_MARK_CODE,
204 (code_P) &BACKWARD_RESOLVE_CODE,
209 (code_P) &AGAIN_CODE,
210 (code_P) &UNTIL_CODE,
212 (code_P) &REPEAT_CODE,
215 (code_P) &PLUS_LOOP_CODE
219 (
str_P) FORWARD_MARK_PSTR,
220 (
str_P) FORWARD_RESOLVE_PSTR,
221 (
str_P) BACKWARD_MARK_PSTR,
222 (
str_P) BACKWARD_RESOLVE_PSTR,
234 (
str_P) LEFT_BRACKET_PSTR,
235 (
str_P) COMMENT_PSTR,
237 (
str_P) LITERAL_PSTR,
238 (
str_P) SEMICOLON_PSTR,
239 (
str_P) RIGHT_BRACKET_PSTR,
241 (
str_P) VARIABLE_PSTR,
242 (
str_P) CONSTANT_PSTR,
243 (
str_P) COMPILED_WORDS_PSTR,
244 (
str_P) GENERATE_CODE_PSTR,
249 #if defined(ARDUINO_ARCH_AVR) 253 const int DATA_MAX = 32 * 1024;
254 const int WORD_MAX = 128;
259 FVM fvm(data, DATA_MAX, WORD_MAX);
267 Serial.println(F(
"FVM/Compiler V1.1.0: started [Newline]"));
283 int val = strtol(buffer, &endptr,
task.m_base);
284 if (*endptr != 0)
goto error;
301 else if (op == COMMENT) {
302 while (Serial.read() !=
')');
306 else if (!compiling) {
345 while (!Serial.available());
347 if (c ==
'\"')
break;
367 if (c ==
'\n' && !compiling) Serial.println(F(
" ok"));
371 Serial.print(buffer);
372 Serial.println(F(
" ??"));
380 while ((s =
fvm.
name(nr)) != 0) {
381 int len = ios.print(s);
385 for (;len < 16; len++) ios.print(
' ');
398 for (
int nr = 0; ((name =
fvm.
name(nr)) != 0); nr++) {
399 ios.print(F(
"const char " PREFIX));
401 ios.print(F(
"_PSTR[] PROGMEM = \""));
403 ios.println(F(
"\";"));
407 ios.print(F(
"FVM::cell_t " PREFIX));
410 ios.print(F(
"const FVM::var_t " PREFIX));
412 ios.println(F(
"_VAR[] PROGMEM = {"));
413 ios.print(F(
" FVM::OP_CONST, &" PREFIX));
415 ios.println(F(
"};"));
418 val = dp[2] << 8 | dp[1];
419 ios.print(F(
"const FVM::const_t " PREFIX));
421 ios.println(F(
"_CONST[] PROGMEM = {"));
422 ios.print(F(
" FVM::OP_CONST, "));
424 ios.println(F(
"};"));
427 ios.print(F(
"const FVM::code_t " PREFIX));
429 ios.print(F(
"_CODE[] PROGMEM = {\n "));
430 uint8_t* next = (uint8_t*)
fvm.
name(nr + 1);
431 if (next == 0) next =
fvm.
dp();
432 int length = next - dp;
434 int8_t code = (int8_t) *dp++;
436 if (--length) ios.print(F(
", "));
439 ios.println(F(
"};"));
444 ios.println(F(
"const FVM::code_P FVM::fntab[] PROGMEM = {"));
445 for (
int nr = 0; (dp = (uint8_t*)
fvm.
body(nr)) != 0; nr++) {
446 ios.print(F(
" (code_P) &" PREFIX));
450 ios.print(F(
"_VAR"));
453 ios.print(F(
"_CONST"));
456 ios.print(F(
"_CODE"));
460 ios.println(F(
" 0"));
461 ios.println(F(
"};"));
464 ios.println(F(
"const str_P FVM::fnstr[] PROGMEM = {"));
465 for (
int nr = 0;
fvm.
body(nr) != 0; nr++) {
466 ios.print(F(
" (str_P) " PREFIX));
468 ios.println(F(
"_PSTR,"));
470 ios.println(F(
" 0"));
471 ios.println(F(
"};"));
static const char DOT_QUOTE_PSTR[]
bool create(const char *name)
static const char LOOP_PSTR[]
FVM_SYMBOL(15, LEFT_BRACKET,"[")
bool constant(const char *name, int val)
const char * name(int op)
bool variable(const char *name)
void generate_code(Stream &ios)
FVM fvm(data, DATA_MAX, WORD_MAX)
static const char PLUS_LOOP_PSTR[]
static const str_P fnstr[]
int execute(int op, task_t &task)
void compiled_words(Stream &ios)
FVM::Task< 64, 32 > task(Serial)
int lookup(const char *name)
Handle variable reference.
static const char DO_PSTR[]
#define FVM_COLON(id, var, name)
int scan(char *bp, task_t &task)
Print program memory string.