32 typedef const PROGMEM
char*
str_P;
229 #if defined(ARDUINO_ARCH_AVR) 269 task_t(Stream&ios, cell_t* sp0, code_P* rp0, code_P fn) :
305 return (m_sp - m_sp0 - 1);
338 template<
int PARAMETER_STACK_MAX,
int RETURN_STACK_MAX>
340 cell_t m_params[PARAMETER_STACK_MAX];
341 code_P m_returns[RETURN_STACK_MAX];
349 Task(Stream& ios, code_P fn = 0) :
350 task_t(ios, m_params, m_returns, fn)
361 } __attribute__((packed));
369 } __attribute__((packed));
377 } __attribute__((packed));
388 } __attribute__((packed));
397 FVM(uint8_t* dp0 = 0,
size_t bytes = 0, uint8_t words = 0) :
406 if (words == 0)
return;
407 dp0 +=
sizeof(code_t**) * words;
409 dp0 +=
sizeof(
char**) * words;
438 if (op < 0 || op >
TOKEN_MAX)
return (
false);
459 if (val < INT8_MIN || val > INT8_MAX) {
479 strcpy((
char*)
m_dp, name);
480 m_dp += strlen(name) + 1;
481 #if defined(ARDUINO_ARCH_AVR) 496 if (!
create(name))
return (
false);
500 #if !defined(ARDUINO_ARCH_AVR) 514 if (!
create(name))
return (
false);
518 #if !defined(ARDUINO_ARCH_AVR) 540 #if defined(ARDUINO_ARCH_AVR) 555 if (op < 0 || op >
m_next)
return (
false);
628 static const code_P
fntab[] PROGMEM;
652 #define FVM_OP(code) FVM::OP_ ## code 661 FVM::code_t((n) >> 8) 667 #define FVM_CLIT(n) \ 675 #define FVM_CALL(fn) FVM::code_t(-fn-1) 684 #define FVM_CREATE(id,var,does,data) \ 685 const int var = id; \ 686 const char var ## _PSTR[] PROGMEM = #data; \ 687 const FVM::obj_t var ## _VAR PROGMEM = { \ 690 (FVM::cell_t*) &data \ 699 #define FVM_VARIABLE(id,var,data) \ 700 const int var = id; \ 701 const char var ## _PSTR[] PROGMEM = #data; \ 702 const FVM::var_t var ## _VAR PROGMEM = { \ 704 (FVM::cell_t*) &data \ 714 #define FVM_CONSTANT(id,var,name,val) \ 715 const int var = id; \ 716 const char var ## _PSTR[] PROGMEM = name; \ 717 const FVM::const_t var ## _CONST PROGMEM = { \ 728 #define FVM_COLON(id,var,name) \ 729 const int var = id; \ 730 const char var ## _PSTR[] PROGMEM = name; \ 731 const FVM::code_t var ## _CODE[] PROGMEM = { 740 #define FVM_FUNCTION(id,var,fn,env) \ 741 const int var = id; \ 742 const char var ## _PSTR[] PROGMEM = #fn; \ 743 const FVM::func_t var ## _FUNC PROGMEM = { \ 746 (FVM::cell_t*) &env \ 755 #define FVM_SYMBOL(id,var,name) \ 756 const int var = id + FVM::KERNEL_MAX; \ 757 const char var ## _PSTR[] PROGMEM = name Allocate and assign character.
Convert top of stack to invert boolean.
Base for number conversion.
Inverse rotate three top stack elements.
Swap two top stack elements.
Duplicate double stack elements.
Bitwise XOR top two elements.
code_t op
OP_VAR/OP_CONST.
Access data area application variable.
Read character if available.
static const str_P opstr[]
Rotate given number of stack elements.
Duplicate index stack element.
static const code_P fntab[]
Handle function wrapper call.
Quotient for division of top two elements.
Substract top two elements.
Duplicate top of stack and rotate.
Set hexa-decimal number conversion base.
bool create(const char *name)
void(* fn_t)(task_t &task, void *env)
Duplicate double next top of stack.
static const uint16_t CODE_P_MAX
code_P * m_rp
Return stack pointer.
Mark loop block as completed.
Bitwise inverse top element.
bool constant(const char *name, int val)
FVM(uint8_t *dp0=0, size_t bytes=0, uint8_t words=0)
Convert cells to bytes for allot.
cell_t m_base
Number conversion base.
Allocate number of bytes.
Print top of stack as unsigned.
Multiply/Divide top three elements.
const char * name(int op)
bool variable(const char *name)
Multiply top two elements.
Lookup word in dictionary.
Load character (signed byte)
Bitwise OR top two elements.
Bitwise AND top two elements.
int execute(const char *name, task_t &task)
static const str_P fnstr[]
Threaded code return if zero/false.
Wait for character and read.
Duplicate top of stack if not zero.
int execute(int op, task_t &task)
Convert top of stack to boolean.
int execute(code_P fn, task_t &task)
cell_t * m_sp
Parameter stack pointer.
Set decimal number conversion base.
code_P * m_rp0
Return stack bottom pointer.
Duplicate next top of stack.
cell_t value
Value of constant (PROGMEM).
cell_t * m_sp0
Parameter stack bottom pointer.
void * env
Pointer to environment (SRAM).
int interpret(task_t &task)
Pop data from return stack.
int lookup(const char *name)
Duplicate inline indexed stack element.
Delay milli-seconds (yield)
Remainder for division of top two elements.
Drop double top of stack.
End loop block (n increment)
Rotate three top stack elements.
Handle variable reference.
fn_t fn
Pointer to function.
Swap two double stack elements.
task_t(Stream &ios, cell_t *sp0, code_P *rp0, code_P fn)
End loop block (one increment)
Print contents of parameter stack.
FVM::Task< 32, 16 > task(Serial, WORD3_CODE)
int scan(char *bp, task_t &task)
Push instruction pointer and branch always.
Branch always (offset -128..127)
Task(Stream &ios, code_P fn=0)
Print program memory string.
cell_t * value
Pointer to value (SRAM).
Allocate and assign from top of stack.
cell_t * value
Pointer to value (SRAM).
Branch if zero/false (offset -128..127)
Push data on return stack.
Inline literal signed character constant.
Stream & m_ios
Input/Output stream.