Arduino-FVM
Byte Token Threaded Forth Virtual Machine (FVM) for Arduino
Test.ino
Go to the documentation of this file.
1 
28 #include "FVM.h"
29 
30 /*
31 : test0 ." hello world" cr halt ;
32 : test1 0 begin dup 1+ dup 9 = if halt then again ;
33 : test2 0 begin dup 1+ dup 9 = until halt ;
34 : test3 0 begin dup 9 < while dup 1+ repeat halt ;
35 : test4 10 0 do i loop halt ;
36 : test5 10 0 do i 3 +loop halt ;
37 : test6 10 0 do i i 5 = if leave then loop halt ;
38 : test7 2 0 do 2 0 do i j loop loop halt ;
39 : test8 0 analogread ;
40 generate-code
41 */
42 
43 const char WORD0_PSTR[] PROGMEM = "test0";
44 const FVM::code_t WORD0_CODE[] PROGMEM = {
45  117, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 111, 20, 0
46 };
47 const char WORD1_PSTR[] PROGMEM = "test1";
48 const FVM::code_t WORD1_CODE[] PROGMEM = {
49  60, 45, 74, 45, 3, 9, 99, 11, 2, 20, 10, -10, 0
50 };
51 const char WORD2_PSTR[] PROGMEM = "test2";
52 const FVM::code_t WORD2_CODE[] PROGMEM = {
53  60, 45, 74, 45, 3, 9, 99, 11, -7, 20, 0
54 };
55 const char WORD3_PSTR[] PROGMEM = "test3";
56 const FVM::code_t WORD3_CODE[] PROGMEM = {
57  60, 45, 3, 9, 98, 11, 5, 45, 74, 10, -9, 20, 0
58 };
59 const char WORD4_PSTR[] PROGMEM = "test4";
60 const FVM::code_t WORD4_CODE[] PROGMEM = {
61  3, 10, 60, 12, 4, 13, 16, -2, 20, 0
62 };
63 const char WORD5_PSTR[] PROGMEM = "test5";
64 const FVM::code_t WORD5_CODE[] PROGMEM = {
65  3, 10, 60, 12, 6, 13, 3, 3, 17, -4, 20, 0
66 };
67 const char WORD6_PSTR[] PROGMEM = "test6";
68 const FVM::code_t WORD6_CODE[] PROGMEM = {
69  3, 10, 60, 12, 11, 13, 13, 3, 5, 99, 11, 2, 15, 16, -9, 20, 0
70 };
71 const char WORD7_PSTR[] PROGMEM = "test7";
72 const FVM::code_t WORD7_CODE[] PROGMEM = {
73  62, 60, 12, 11, 62, 60, 12, 5, 13, 14, 16, -3, 16, -9, 20, 0
74 };
75 const char WORD8_PSTR[] PROGMEM = "test8";
76 const FVM::code_t WORD8_CODE[] PROGMEM = {
77  60, 22, -128, 0
78 };
79 const FVM::code_P FVM::fntab[] PROGMEM = {
80  (code_P) &WORD0_CODE,
81  (code_P) &WORD1_CODE,
82  (code_P) &WORD2_CODE,
83  (code_P) &WORD3_CODE,
84  (code_P) &WORD4_CODE,
85  (code_P) &WORD5_CODE,
86  (code_P) &WORD6_CODE,
87  (code_P) &WORD7_CODE,
88  (code_P) &WORD8_CODE
89 };
90 const str_P FVM::fnstr[] PROGMEM = {
91  (str_P) WORD0_PSTR,
92  (str_P) WORD1_PSTR,
93  (str_P) WORD2_PSTR,
94  (str_P) WORD3_PSTR,
95  (str_P) WORD4_PSTR,
96  (str_P) WORD5_PSTR,
97  (str_P) WORD6_PSTR,
98  (str_P) WORD7_PSTR,
99  (str_P) WORD8_PSTR,
100  0
101 };
102 
103 FVM::Task<32,16> task(Serial);
105 
106 void setup()
107 {
108  Serial.begin(57600);
109  while (!Serial);
110  Serial.println(F("FVM/Test: started"));
111 }
112 
113 void loop()
114 {
115  fvm.interpret(task);
116 }
const FVM::code_t WORD4_CODE[]
Definition: Test.ino:60
const char WORD0_PSTR[]
Definition: Test.ino:43
const FVM::code_t WORD2_CODE[]
Definition: Test.ino:52
const char WORD3_PSTR[]
Definition: Test.ino:55
static const code_P fntab[]
Definition: FVM.h:628
FVM fvm
Definition: Test.ino:104
const char WORD4_PSTR[]
Definition: Test.ino:59
Definition: FVM.h:339
const char * str_P
Definition: FVM.h:32
const char WORD2_PSTR[]
Definition: Test.ino:51
const FVM::code_t WORD0_CODE[]
Definition: Test.ino:44
const code_t * code_P
Definition: FVM.h:249
const FVM::code_t WORD8_CODE[]
Definition: Test.ino:76
static const str_P fnstr[]
Definition: FVM.h:629
const char WORD1_PSTR[]
Definition: Test.ino:47
const FVM::code_t WORD6_CODE[]
Definition: Test.ino:68
void setup()
Definition: Test.ino:106
const FVM::code_t WORD7_CODE[]
Definition: Test.ino:72
const char WORD7_PSTR[]
Definition: Test.ino:71
const char WORD5_PSTR[]
Definition: Test.ino:63
int interpret(task_t &task)
Definition: FVM.cpp:1848
const char WORD8_PSTR[]
Definition: Test.ino:75
void loop()
Definition: Test.ino:113
int8_t code_t
Definition: FVM.h:248
const char WORD6_PSTR[]
Definition: Test.ino:67
const FVM::code_t WORD5_CODE[]
Definition: Test.ino:64
const FVM::code_t WORD3_CODE[]
Definition: Test.ino:56
Definition: FVM.h:34
FVM::Task< 32, 16 > task(Serial)
const FVM::code_t WORD1_CODE[]
Definition: Test.ino:48