Arduino-FVM
Byte Token Threaded Forth Virtual Machine (FVM) for Arduino
Main Page
Related Pages
Classes
Files
File List
File Members
Demo.ino
Go to the documentation of this file.
1
27
#include "
FVM.h
"
28
29
const
int
SKETCH_FN
= 0;
30
const
char
SKETCH_PSTR
[] PROGMEM =
"sketch"
;
31
const
FVM::code_t
SKETCH_CODE
[] PROGMEM = {
32
// Stack operations
33
FVM_OP
(ZERO),
// -
34
FVM_OP
(ONE),
// 0
35
FVM_OP
(TWO),
// 0 1
36
FVM_OP
(SWAP),
// 0 1 2
37
FVM_OP
(ROT),
// 0 2 1
38
FVM_OP
(QUESTION_DUP),
// 2 1 0
39
FVM_OP
(OVER),
// 2 1 0
40
FVM_OP
(TUCK),
// 2 1 0 1
41
FVM_OP
(QUESTION_DUP),
// 2 1 1 0 1
42
FVM_OP
(DROP),
// 2 1 1 0 1 1
43
FVM_OP
(NIP),
// 2 1 1 0 1
44
FVM_OP
(DEPTH),
// 2 1 1 1
45
FVM_OP
(MINUS_ROT),
// 2 1 1 1 4
46
FVM_OP
(EMPTY),
// 2 1 4 1 1
47
FVM_OP
(YIELD),
// -
48
49
// Double element operations
50
FVM_OP
(ZERO),
// -
51
FVM_OP
(ONE),
// 0
52
FVM_OP
(TWO_DUP),
// 0 1
53
FVM_OP
(SWAP),
// 0 1 0 1
54
FVM_OP
(TWO_SWAP),
// 0 1 1 0
55
FVM_OP
(TWO_OVER),
// 1 0 0 1
56
FVM_OP
(TWO_DROP),
// 1 0 0 1 1 0
57
FVM_OP
(EMPTY),
// 1 0 0 1
58
FVM_OP
(YIELD),
// -
59
60
// Return stack operations
61
FVM_OP
(ZERO),
// -
62
FVM_OP
(ONE),
// 0
63
FVM_OP
(TO_R),
// 0 1
64
FVM_OP
(TO_R),
// 0
65
FVM_OP
(TWO),
// -
66
FVM_OP
(R_FETCH),
// 2
67
FVM_OP
(R_FROM),
// 2 0
68
FVM_OP
(R_FROM),
// 2 0 0
69
FVM_OP
(EMPTY),
// 2 0 0 1
70
FVM_OP
(YIELD),
// -
71
72
// Bit-wise/boolean operations
73
FVM_OP
(ONE),
// -
74
FVM_OP
(BOOL),
// 1
75
FVM_OP
(NOT),
// -1
76
FVM_OP
(INVERT),
// 0
77
FVM_CLIT
(-13),
// -1
78
FVM_OP
(AND),
// -1 -13
79
FVM_LIT
(10),
// -13
80
FVM_OP
(OR),
// -13 10
81
FVM_CLIT
(10),
// -5
82
FVM_OP
(XOR),
// -5 10
83
FVM_OP
(EMPTY),
// -15
84
FVM_OP
(YIELD),
// -
85
86
// Arithmetic operations
87
FVM_OP
(MINUS_ONE),
// -
88
FVM_OP
(NEGATE),
// -1
89
FVM_OP
(ONE_MINUS),
// 1
90
FVM_OP
(ONE_PLUS),
// 0
91
FVM_OP
(TWO_MINUS),
// 1
92
FVM_OP
(TWO_PLUS),
// -1
93
FVM_OP
(TWO_PLUS),
// 1
94
FVM_OP
(TWO_STAR),
// 3
95
FVM_OP
(TWO_SLASH),
// 6
96
FVM_OP
(ONE),
// 3
97
FVM_OP
(PLUS),
// 3 1
98
FVM_OP
(MINUS_ONE),
// 4
99
FVM_OP
(MINUS),
// 4 -1
100
FVM_OP
(MINUS_TWO),
// 5
101
FVM_OP
(MINUS),
// 5 -2
102
FVM_OP
(MINUS_TWO),
// 7
103
FVM_OP
(STAR),
// 7 -2
104
FVM_CLIT
(5),
// -14
105
FVM_OP
(SLASH_MOD),
// -14 5
106
FVM_OP
(NEGATE),
// -2 -4
107
FVM_OP
(LSHIFT),
// -2 4
108
FVM_CLIT
(5),
// -32
109
FVM_OP
(RSHIFT),
// -32 5
110
FVM_OP
(EMPTY),
// -1
111
FVM_OP
(YIELD),
// -
112
113
// Extended arithmetic operations
114
FVM_OP
(ONE),
// -
115
FVM_OP
(ZERO),
// 1
116
FVM_OP
(TWO),
// 1 0
117
FVM_OP
(WITHIN),
// 1 0 2
118
FVM_OP
(ONE),
// -1
119
FVM_OP
(MIN),
// -1 1
120
FVM_OP
(ABS),
// -1
121
FVM_OP
(TWO),
// 1
122
FVM_OP
(MAX),
// 1 2
123
FVM_OP
(EMPTY),
// 2
124
FVM_OP
(YIELD),
// -
125
126
// Relational operations
127
FVM_OP
(ZERO),
// -
128
FVM_OP
(ZERO_NOT_EQUALS),
// 0
129
FVM_OP
(DROP),
// 0
130
FVM_OP
(ONE),
// -
131
FVM_OP
(ZERO_NOT_EQUALS),
// 1
132
FVM_OP
(DROP),
// -1
133
FVM_OP
(ZERO),
// -
134
FVM_OP
(ZERO_LESS),
// 0
135
FVM_OP
(DROP),
// 0
136
FVM_OP
(ONE),
// -
137
FVM_OP
(ZERO_LESS),
// 1
138
FVM_OP
(DROP),
// 0
139
FVM_OP
(ZERO),
// -
140
FVM_OP
(ZERO_EQUALS),
// 0
141
FVM_OP
(DROP),
// -1
142
FVM_OP
(ONE),
// -
143
FVM_OP
(ZERO_EQUALS),
// 1
144
FVM_OP
(DROP),
// 0
145
FVM_OP
(ZERO),
// -
146
FVM_OP
(ZERO_GREATER),
// 0
147
FVM_OP
(DROP),
// 0
148
FVM_OP
(ONE),
// -
149
FVM_OP
(ZERO_GREATER),
// 1
150
FVM_OP
(DROP),
// -1
151
FVM_OP
(ZERO),
// -
152
FVM_OP
(ZERO),
// 0
153
FVM_OP
(NOT_EQUALS),
// 0 0
154
FVM_OP
(DROP),
// 0
155
FVM_OP
(ZERO),
// -
156
FVM_OP
(ONE),
// 0
157
FVM_OP
(NOT_EQUALS),
// 0 1
158
FVM_OP
(DROP),
// -1
159
FVM_OP
(ZERO),
// -
160
FVM_OP
(ZERO),
// 0
161
FVM_OP
(LESS),
// 0 0
162
FVM_OP
(DROP),
// 0
163
FVM_OP
(ZERO),
// -
164
FVM_OP
(ONE),
// 0
165
FVM_OP
(LESS),
// 0 1
166
FVM_OP
(DROP),
// -1
167
FVM_OP
(ZERO),
// -
168
FVM_OP
(ZERO),
// 0
169
FVM_OP
(EQUALS),
// 0 0
170
FVM_OP
(DROP),
// -1
171
FVM_OP
(ZERO),
// -
172
FVM_OP
(ONE),
// 0
173
FVM_OP
(EQUALS),
// 0 1
174
FVM_OP
(DROP),
// 0
175
FVM_OP
(ZERO),
// -
176
FVM_OP
(ZERO),
// 0
177
FVM_OP
(GREATER),
// 0 0
178
FVM_OP
(DROP),
// 0
179
FVM_OP
(ZERO),
// -
180
FVM_OP
(ONE),
// 0
181
FVM_OP
(GREATER),
// 0 1
182
FVM_OP
(DROP),
// 0
183
FVM_OP
(YIELD),
// -
184
185
// Print operation/function name
186
FVM_OP
(FALSE),
// -
187
FVM_OP
(TRACE),
// 0
188
FVM_CLIT
(
FVM::OP_SWAP
),
// -
189
FVM_OP
(DOT_NAME),
// 32
190
FVM_OP
(DROP),
// 4
191
FVM_OP
(SPACE),
// 4
192
FVM_LIT
(128),
// -
193
FVM_OP
(DOT_NAME),
// 128
194
FVM_OP
(DROP),
// 5
195
FVM_OP
(SPACE),
// 4
196
FVM_OP
(CR),
// 4
197
FVM_OP
(YIELD),
// -
198
FVM_OP
(TRUE),
// -1
199
FVM_OP
(TRACE),
// -
200
201
// Delay
202
FVM_LIT
(100),
// -
203
FVM_OP
(DELAY),
// 100
204
FVM_OP
(HALT)
// -
205
};
206
207
const
FVM::code_P
FVM::fntab
[] PROGMEM = {
208
SKETCH_CODE
209
};
210
211
const
str_P
FVM::fnstr
[] PROGMEM = {
212
(
str_P
)
SKETCH_PSTR
,
213
0
214
};
215
216
FVM
fvm
;
217
FVM::Task<32,16>
task
(Serial,
SKETCH_CODE
);
218
219
void
setup
()
220
{
221
Serial.begin(57600);
222
while
(!Serial);
223
Serial.println(F(
"FVM/Demo: started"
));
224
225
task
.trace(
true
);
226
while
(fvm.
resume
(
task
) > 0);
227
}
228
229
void
loop
()
230
{
231
}
loop
void loop()
Definition:
Demo.ino:229
FVM::OP_SWAP
Swap two top stack elements.
Definition:
FVM.h:102
FVM.h
SKETCH_CODE
const FVM::code_t SKETCH_CODE[]
Definition:
Demo.ino:31
FVM::fntab
static const code_P fntab[]
Definition:
FVM.h:628
FVM::resume
int resume(task_t &task)
Definition:
FVM.cpp:143
FVM_CLIT
#define FVM_CLIT(n)
Definition:
FVM.h:667
FVM::Task
Definition:
FVM.h:339
str_P
const char * str_P
Definition:
FVM.h:32
FVM::code_P
const code_t * code_P
Definition:
FVM.h:249
FVM::fnstr
static const str_P fnstr[]
Definition:
FVM.h:629
SKETCH_PSTR
const char SKETCH_PSTR[]
Definition:
Demo.ino:30
task
FVM::Task< 32, 16 > task(Serial, SKETCH_CODE)
fvm
FVM fvm
Definition:
Demo.ino:216
FVM::code_t
int8_t code_t
Definition:
FVM.h:248
FVM_OP
#define FVM_OP(code)
Definition:
FVM.h:652
FVM_LIT
#define FVM_LIT(n)
Definition:
FVM.h:658
SKETCH_FN
const int SKETCH_FN
Definition:
Demo.ino:29
FVM
Definition:
FVM.h:34
setup
void setup()
Definition:
Demo.ino:219
examples
Demo
Demo.ino
Generated on Thu Aug 31 2017 17:25:52 for Arduino-FVM by
1.8.11