Arduino-FVM
Byte Token Threaded Forth Virtual Machine (FVM) for Arduino
FVM.cpp File Reference
#include "FVM.h"
Include dependency graph for FVM.cpp:

Go to the source code of this file.

Macros

#define FVM_THREADING   1
 
#define FVM_TRACE   1
 
#define FVM_KERNEL_DICT   1
 
#define FVM_KERNEL_OPT   1
 
#define OP(n)   case OP_ ## n:
 
#define NEXT()   goto INNER
 
#define FALLTHROUGH()
 
#define CALL(fn)   tp = fn; goto FNCALL
 
#define MAP(if)   (-ir-1)
 
#define FNTAB(ix)   fntab[ix]
 
#define FNSTR(ix)   fnstr[ix]
 
#define OPSTR(ix)   opstr[ix]
 
#define fetch_byte(ip)   (*((int8_t*) (ip)))
 
#define fetch_word(ip)   (*((cell_t*) (ip)))
 

Variables

static const char EXIT_PSTR [] = "exit"
 
static const char ZERO_EXIT_PSTR [] = "?exit"
 
static const char LIT_PSTR [] = "(lit)"
 
static const char CLIT_PSTR [] = "(clit)"
 
static const char SLIT_PSTR [] = "(slit)"
 
static const char VAR_PSTR [] = "(var)"
 
static const char CONST_PSTR [] = "(const)"
 
static const char FUNC_PSTR [] = "(func)"
 
static const char DOES_PSTR [] = "(does)"
 
static const char PARAM_PSTR [] = "(param)"
 
static const char BRANCH_PSTR [] = "(branch)"
 
static const char ZERO_BRANCH_PSTR [] = "(0branch)"
 
static const char DO_PSTR [] = "(do)"
 
static const char I_PSTR [] = "i"
 
static const char J_PSTR [] = "j"
 
static const char LEAVE_PSTR [] = "leave"
 
static const char LOOP_PSTR [] = "(loop)"
 
static const char PLUS_LOOP_PSTR [] = "(+loop)"
 
static const char NOOP_PSTR [] = "noop"
 
static const char EXECUTE_PSTR [] = "execute"
 
static const char YIELD_PSTR [] = "yield"
 
static const char HALT_PSTR [] = "halt"
 
static const char SYSCALL_PSTR [] = "(syscall)"
 
static const char CALL_PSTR [] = "(call)"
 
static const char TRACE_PSTR [] = "trace"
 
static const char ROOM_PSTR [] = "room"
 
static const char C_FETCH_PSTR [] = "c@"
 
static const char C_STORE_PSTR [] = "c!"
 
static const char FETCH_PSTR [] = "@"
 
static const char STORE_PSTR [] = "!"
 
static const char PLUS_STORE_PSTR [] = "+!"
 
static const char DP_PSTR [] = "dp"
 
static const char HERE_PSTR [] = "here"
 
static const char ALLOT_PSTR [] = "allot"
 
static const char COMMA_PSTR [] = ","
 
static const char C_COMMA_PSTR [] = "c,"
 
static const char COMPILE_PSTR [] = "(compile)"
 
static const char TO_R_PSTR [] = ">r"
 
static const char R_FROM_PSTR [] = "r>"
 
static const char R_FETCH_PSTR [] = "r@"
 
static const char SP_PSTR [] = "sp"
 
static const char DEPTH_PSTR [] = "depth"
 
static const char DROP_PSTR [] = "drop"
 
static const char NIP_PSTR [] = "nip"
 
static const char EMPTY_PSTR [] = "empty"
 
static const char DUP_PSTR [] = "dup"
 
static const char QUESTION_DUP_PSTR [] = "?dup"
 
static const char OVER_PSTR [] = "over"
 
static const char TUCK_PSTR [] = "tuck"
 
static const char PICK_PSTR [] = "pick"
 
static const char SWAP_PSTR [] = "swap"
 
static const char ROT_PSTR [] = "rot"
 
static const char MINUS_ROT_PSTR [] = "-rot"
 
static const char ROLL_PSTR [] = "roll"
 
static const char TWO_SWAP_PSTR [] = "2swap"
 
static const char TWO_DUP_PSTR [] = "2dup"
 
static const char TWO_OVER_PSTR [] = "2over"
 
static const char TWO_DROP_PSTR [] = "2drop"
 
static const char MINUS_TWO_PSTR [] = "-2"
 
static const char MINUS_ONE_PSTR [] = "-1"
 
static const char ZERO_PSTR [] = "0"
 
static const char ONE_PSTR [] = "1"
 
static const char TWO_PSTR [] = "2"
 
static const char CELL_PSTR [] = "cell"
 
static const char CELLS_PSTR [] = "cells"
 
static const char BOOL_PSTR [] = "bool"
 
static const char NOT_PSTR [] = "not"
 
static const char TRUE_PSTR [] = "true"
 
static const char FALSE_PSTR [] = "false"
 
static const char INVERT_PSTR [] = "invert"
 
static const char AND_PSTR [] = "and"
 
static const char OR_PSTR [] = "or"
 
static const char XOR_PSTR [] = "xor"
 
static const char NEGATE_PSTR [] = "negate"
 
static const char ONE_PLUS_PSTR [] = "1+"
 
static const char ONE_MINUS_PSTR [] = "1-"
 
static const char TWO_PLUS_PSTR [] = "2+"
 
static const char TWO_MINUS_PSTR [] = "2-"
 
static const char TWO_STAR_PSTR [] = "2*"
 
static const char TWO_SLASH_PSTR [] = "2/"
 
static const char PLUS_PSTR [] = "+"
 
static const char MINUS_PSTR [] = "-"
 
static const char STAR_PSTR [] = "*"
 
static const char STAR_SLASH_PSTR [] = "*/"
 
static const char SLASH_PSTR [] = "/"
 
static const char MOD_PSTR [] = "mod"
 
static const char SLASH_MODE_PSTR [] = "/mod"
 
static const char LSHIFT_PSTR [] = "lshift"
 
static const char RSHIFT_PSTR [] = "rshift"
 
static const char WITHIN_PSTR [] = "within"
 
static const char ABS_PSTR [] = "abs"
 
static const char MIN_PSTR [] = "min"
 
static const char MAX_PSTR [] = "max"
 
static const char ZERO_NOT_EQUALS_PSTR [] = "0<>"
 
static const char ZERO_LESS_PSTR [] = "0<"
 
static const char ZERO_EQUALS_PSTR [] = "0="
 
static const char ZERO_GREATER_PSTR [] = "0>"
 
static const char NOT_EQUALS_PSTR [] = "<>"
 
static const char LESS_PSTR [] = "<"
 
static const char EQUALS_PSTR [] = "="
 
static const char GREATER_PSTR [] = ">"
 
static const char U_LESS_PSTR [] = "u<"
 
static const char LOOKUP_PSTR [] = "lookup"
 
static const char TO_BODY_PSTR [] = ">body"
 
static const char WORDS_PSTR [] = "words"
 
static const char BASE_PSTR [] = "base"
 
static const char HEX_PSTR [] = "hex"
 
static const char DECIMAL_PSTR [] = "decimal"
 
static const char QUESTION_KEY_PSTR [] = "?key"
 
static const char KEY_PSTR [] = "key"
 
static const char EMIT_PSTR [] = "emit"
 
static const char CR_PSTR [] = "cr"
 
static const char SPACE_PSTR [] = "space"
 
static const char SPACES_PSTR [] = "spaces"
 
static const char U_DOT_PSTR [] = "u."
 
static const char DOT_PSTR [] = "."
 
static const char DOT_S_PSTR [] = ".s"
 
static const char DOT_QUOTE_PSTR [] = "(.\")"
 
static const char TYPE_PSTR [] = "type"
 
static const char DOT_NAME_PSTR [] = ".name"
 
static const char QUESTION_PSTR [] = "?"
 
static const char MICROS_PSTR [] = "micros"
 
static const char MILLIS_PSTR [] = "millis"
 
static const char DELAY_PSTR [] = "delay"
 
static const char PINMODE_PSTR [] = "pinmode"
 
static const char DIGITALREAD_PSTR [] = "digitalread"
 
static const char DIGITALWRITE_PSTR [] = "digitalwrite"
 
static const char DIGITALTOGGLE_PSTR [] = "digitaltoggle"
 
static const char ANALOGREAD_PSTR [] = "analogread"
 
static const char ANALOGWRITE_PSTR [] = "analogwrite"
 

Detailed Description

Version
1.1

License

Copyright (C) 2016-2017, Mikael Patel

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Definition in file FVM.cpp.

Macro Definition Documentation

#define CALL (   fn)    tp = fn; goto FNCALL

Definition at line 61 of file FVM.cpp.

#define FALLTHROUGH ( )

Definition at line 60 of file FVM.cpp.

#define fetch_byte (   ip)    (*((int8_t*) (ip)))

Definition at line 80 of file FVM.cpp.

#define fetch_word (   ip)    (*((cell_t*) (ip)))

Definition at line 81 of file FVM.cpp.

#define FNSTR (   ix)    fnstr[ix]

Definition at line 70 of file FVM.cpp.

#define FNTAB (   ix)    fntab[ix]

Definition at line 69 of file FVM.cpp.

#define FVM_KERNEL_DICT   1

Enable kernel dictionary. Remove to reduce foot-print for non-interactive application. 0: No kernel dictionary. 1: Add kernel dictionary

Definition at line 48 of file FVM.cpp.

#define FVM_KERNEL_OPT   1

Enable kernel optimization. 0: No kernel optimization. 1: Tail call optimization.

Definition at line 55 of file FVM.cpp.

#define FVM_THREADING   1

Enable threaded code in data memory. 0: Program memory only. 1: Data and program memory.

Definition at line 31 of file FVM.cpp.

#define FVM_TRACE   1

Enable symbolic trace of virtual machine instruction cycle. 0: No trace. 1: Print indented operation code and stack contents. 2: Print execute time, instruction pointer, return stack depth, operation code and stack contents.

Definition at line 40 of file FVM.cpp.

#define MAP (   if)    (-ir-1)

Definition at line 62 of file FVM.cpp.

#define NEXT ( )    goto INNER

Definition at line 59 of file FVM.cpp.

#define OP (   n)    case OP_ ## n:

Definition at line 58 of file FVM.cpp.

#define OPSTR (   ix)    opstr[ix]

Definition at line 71 of file FVM.cpp.

Variable Documentation

const char ABS_PSTR[] = "abs"
static

Definition at line 1971 of file FVM.cpp.

const char ALLOT_PSTR[] = "allot"
static

Definition at line 1907 of file FVM.cpp.

const char ANALOGREAD_PSTR[] = "analogread"
static

Definition at line 2013 of file FVM.cpp.

const char ANALOGWRITE_PSTR[] = "analogwrite"
static

Definition at line 2014 of file FVM.cpp.

const char AND_PSTR[] = "and"
static

Definition at line 1948 of file FVM.cpp.

const char BASE_PSTR[] = "base"
static

Definition at line 1989 of file FVM.cpp.

const char BOOL_PSTR[] = "bool"
static

Definition at line 1943 of file FVM.cpp.

const char BRANCH_PSTR[] = "(branch)"
static

Definition at line 1883 of file FVM.cpp.

const char C_COMMA_PSTR[] = "c,"
static

Definition at line 1909 of file FVM.cpp.

const char C_FETCH_PSTR[] = "c@"
static

Definition at line 1900 of file FVM.cpp.

const char C_STORE_PSTR[] = "c!"
static

Definition at line 1901 of file FVM.cpp.

const char CALL_PSTR[] = "(call)"
static

Definition at line 1896 of file FVM.cpp.

const char CELL_PSTR[] = "cell"
static

Definition at line 1940 of file FVM.cpp.

const char CELLS_PSTR[] = "cells"
static

Definition at line 1941 of file FVM.cpp.

const char CLIT_PSTR[] = "(clit)"
static

Definition at line 1876 of file FVM.cpp.

const char COMMA_PSTR[] = ","
static

Definition at line 1908 of file FVM.cpp.

const char COMPILE_PSTR[] = "(compile)"
static

Definition at line 1910 of file FVM.cpp.

const char CONST_PSTR[] = "(const)"
static

Definition at line 1879 of file FVM.cpp.

const char CR_PSTR[] = "cr"
static

Definition at line 1995 of file FVM.cpp.

const char DECIMAL_PSTR[] = "decimal"
static

Definition at line 1991 of file FVM.cpp.

const char DELAY_PSTR[] = "delay"
static

Definition at line 2008 of file FVM.cpp.

const char DEPTH_PSTR[] = "depth"
static

Definition at line 1917 of file FVM.cpp.

const char DIGITALREAD_PSTR[] = "digitalread"
static

Definition at line 2010 of file FVM.cpp.

const char DIGITALTOGGLE_PSTR[] = "digitaltoggle"
static

Definition at line 2012 of file FVM.cpp.

const char DIGITALWRITE_PSTR[] = "digitalwrite"
static

Definition at line 2011 of file FVM.cpp.

const char DO_PSTR[] = "(do)"
static

Definition at line 1885 of file FVM.cpp.

const char DOES_PSTR[] = "(does)"
static

Definition at line 1881 of file FVM.cpp.

const char DOT_NAME_PSTR[] = ".name"
static

Definition at line 2003 of file FVM.cpp.

const char DOT_PSTR[] = "."
static

Definition at line 1999 of file FVM.cpp.

const char DOT_QUOTE_PSTR[] = "(.\")"
static

Definition at line 2001 of file FVM.cpp.

const char DOT_S_PSTR[] = ".s"
static

Definition at line 2000 of file FVM.cpp.

const char DP_PSTR[] = "dp"
static

Definition at line 1905 of file FVM.cpp.

const char DROP_PSTR[] = "drop"
static

Definition at line 1918 of file FVM.cpp.

const char DUP_PSTR[] = "dup"
static

Definition at line 1921 of file FVM.cpp.

const char EMIT_PSTR[] = "emit"
static

Definition at line 1994 of file FVM.cpp.

const char EMPTY_PSTR[] = "empty"
static

Definition at line 1920 of file FVM.cpp.

const char EQUALS_PSTR[] = "="
static

Definition at line 1981 of file FVM.cpp.

const char EXECUTE_PSTR[] = "execute"
static

Definition at line 1892 of file FVM.cpp.

const char EXIT_PSTR[] = "exit"
static

Definition at line 1873 of file FVM.cpp.

const char FALSE_PSTR[] = "false"
static

Definition at line 1946 of file FVM.cpp.

const char FETCH_PSTR[] = "@"
static

Definition at line 1902 of file FVM.cpp.

const char FUNC_PSTR[] = "(func)"
static

Definition at line 1880 of file FVM.cpp.

const char GREATER_PSTR[] = ">"
static

Definition at line 1982 of file FVM.cpp.

const char HALT_PSTR[] = "halt"
static

Definition at line 1894 of file FVM.cpp.

const char HERE_PSTR[] = "here"
static

Definition at line 1906 of file FVM.cpp.

const char HEX_PSTR[] = "hex"
static

Definition at line 1990 of file FVM.cpp.

const char I_PSTR[] = "i"
static

Definition at line 1886 of file FVM.cpp.

const char INVERT_PSTR[] = "invert"
static

Definition at line 1947 of file FVM.cpp.

const char J_PSTR[] = "j"
static

Definition at line 1887 of file FVM.cpp.

const char KEY_PSTR[] = "key"
static

Definition at line 1993 of file FVM.cpp.

const char LEAVE_PSTR[] = "leave"
static

Definition at line 1888 of file FVM.cpp.

const char LESS_PSTR[] = "<"
static

Definition at line 1980 of file FVM.cpp.

const char LIT_PSTR[] = "(lit)"
static

Definition at line 1875 of file FVM.cpp.

const char LOOKUP_PSTR[] = "lookup"
static

Definition at line 1985 of file FVM.cpp.

const char LOOP_PSTR[] = "(loop)"
static

Definition at line 1889 of file FVM.cpp.

const char LSHIFT_PSTR[] = "lshift"
static

Definition at line 1966 of file FVM.cpp.

const char MAX_PSTR[] = "max"
static

Definition at line 1973 of file FVM.cpp.

const char MICROS_PSTR[] = "micros"
static

Definition at line 2006 of file FVM.cpp.

const char MILLIS_PSTR[] = "millis"
static

Definition at line 2007 of file FVM.cpp.

const char MIN_PSTR[] = "min"
static

Definition at line 1972 of file FVM.cpp.

const char MINUS_ONE_PSTR[] = "-1"
static

Definition at line 1936 of file FVM.cpp.

const char MINUS_PSTR[] = "-"
static

Definition at line 1960 of file FVM.cpp.

const char MINUS_ROT_PSTR[] = "-rot"
static

Definition at line 1928 of file FVM.cpp.

const char MINUS_TWO_PSTR[] = "-2"
static

Definition at line 1935 of file FVM.cpp.

const char MOD_PSTR[] = "mod"
static

Definition at line 1964 of file FVM.cpp.

const char NEGATE_PSTR[] = "negate"
static

Definition at line 1952 of file FVM.cpp.

const char NIP_PSTR[] = "nip"
static

Definition at line 1919 of file FVM.cpp.

const char NOOP_PSTR[] = "noop"
static

Definition at line 1891 of file FVM.cpp.

const char NOT_EQUALS_PSTR[] = "<>"
static

Definition at line 1979 of file FVM.cpp.

const char NOT_PSTR[] = "not"
static

Definition at line 1944 of file FVM.cpp.

const char ONE_MINUS_PSTR[] = "1-"
static

Definition at line 1954 of file FVM.cpp.

const char ONE_PLUS_PSTR[] = "1+"
static

Definition at line 1953 of file FVM.cpp.

const char ONE_PSTR[] = "1"
static

Definition at line 1938 of file FVM.cpp.

const char OR_PSTR[] = "or"
static

Definition at line 1949 of file FVM.cpp.

const char OVER_PSTR[] = "over"
static

Definition at line 1923 of file FVM.cpp.

const char PARAM_PSTR[] = "(param)"
static

Definition at line 1882 of file FVM.cpp.

const char PICK_PSTR[] = "pick"
static

Definition at line 1925 of file FVM.cpp.

const char PINMODE_PSTR[] = "pinmode"
static

Definition at line 2009 of file FVM.cpp.

const char PLUS_LOOP_PSTR[] = "(+loop)"
static

Definition at line 1890 of file FVM.cpp.

const char PLUS_PSTR[] = "+"
static

Definition at line 1959 of file FVM.cpp.

const char PLUS_STORE_PSTR[] = "+!"
static

Definition at line 1904 of file FVM.cpp.

const char QUESTION_DUP_PSTR[] = "?dup"
static

Definition at line 1922 of file FVM.cpp.

const char QUESTION_KEY_PSTR[] = "?key"
static

Definition at line 1992 of file FVM.cpp.

const char QUESTION_PSTR[] = "?"
static

Definition at line 2004 of file FVM.cpp.

const char R_FETCH_PSTR[] = "r@"
static

Definition at line 1914 of file FVM.cpp.

const char R_FROM_PSTR[] = "r>"
static

Definition at line 1913 of file FVM.cpp.

const char ROLL_PSTR[] = "roll"
static

Definition at line 1929 of file FVM.cpp.

const char ROOM_PSTR[] = "room"
static

Definition at line 1898 of file FVM.cpp.

const char ROT_PSTR[] = "rot"
static

Definition at line 1927 of file FVM.cpp.

const char RSHIFT_PSTR[] = "rshift"
static

Definition at line 1967 of file FVM.cpp.

const char SLASH_MODE_PSTR[] = "/mod"
static

Definition at line 1965 of file FVM.cpp.

const char SLASH_PSTR[] = "/"
static

Definition at line 1963 of file FVM.cpp.

const char SLIT_PSTR[] = "(slit)"
static

Definition at line 1877 of file FVM.cpp.

const char SP_PSTR[] = "sp"
static

Definition at line 1916 of file FVM.cpp.

const char SPACE_PSTR[] = "space"
static

Definition at line 1996 of file FVM.cpp.

const char SPACES_PSTR[] = "spaces"
static

Definition at line 1997 of file FVM.cpp.

const char STAR_PSTR[] = "*"
static

Definition at line 1961 of file FVM.cpp.

const char STAR_SLASH_PSTR[] = "*/"
static

Definition at line 1962 of file FVM.cpp.

const char STORE_PSTR[] = "!"
static

Definition at line 1903 of file FVM.cpp.

const char SWAP_PSTR[] = "swap"
static

Definition at line 1926 of file FVM.cpp.

const char SYSCALL_PSTR[] = "(syscall)"
static

Definition at line 1895 of file FVM.cpp.

const char TO_BODY_PSTR[] = ">body"
static

Definition at line 1986 of file FVM.cpp.

const char TO_R_PSTR[] = ">r"
static

Definition at line 1912 of file FVM.cpp.

const char TRACE_PSTR[] = "trace"
static

Definition at line 1897 of file FVM.cpp.

const char TRUE_PSTR[] = "true"
static

Definition at line 1945 of file FVM.cpp.

const char TUCK_PSTR[] = "tuck"
static

Definition at line 1924 of file FVM.cpp.

const char TWO_DROP_PSTR[] = "2drop"
static

Definition at line 1933 of file FVM.cpp.

const char TWO_DUP_PSTR[] = "2dup"
static

Definition at line 1931 of file FVM.cpp.

const char TWO_MINUS_PSTR[] = "2-"
static

Definition at line 1956 of file FVM.cpp.

const char TWO_OVER_PSTR[] = "2over"
static

Definition at line 1932 of file FVM.cpp.

const char TWO_PLUS_PSTR[] = "2+"
static

Definition at line 1955 of file FVM.cpp.

const char TWO_PSTR[] = "2"
static

Definition at line 1939 of file FVM.cpp.

const char TWO_SLASH_PSTR[] = "2/"
static

Definition at line 1958 of file FVM.cpp.

const char TWO_STAR_PSTR[] = "2*"
static

Definition at line 1957 of file FVM.cpp.

const char TWO_SWAP_PSTR[] = "2swap"
static

Definition at line 1930 of file FVM.cpp.

const char TYPE_PSTR[] = "type"
static

Definition at line 2002 of file FVM.cpp.

const char U_DOT_PSTR[] = "u."
static

Definition at line 1998 of file FVM.cpp.

const char U_LESS_PSTR[] = "u<"
static

Definition at line 1983 of file FVM.cpp.

const char VAR_PSTR[] = "(var)"
static

Definition at line 1878 of file FVM.cpp.

const char WITHIN_PSTR[] = "within"
static

Definition at line 1970 of file FVM.cpp.

const char WORDS_PSTR[] = "words"
static

Definition at line 1987 of file FVM.cpp.

const char XOR_PSTR[] = "xor"
static

Definition at line 1950 of file FVM.cpp.

const char YIELD_PSTR[] = "yield"
static

Definition at line 1893 of file FVM.cpp.

const char ZERO_BRANCH_PSTR[] = "(0branch)"
static

Definition at line 1884 of file FVM.cpp.

const char ZERO_EQUALS_PSTR[] = "0="
static

Definition at line 1977 of file FVM.cpp.

const char ZERO_EXIT_PSTR[] = "?exit"
static

Definition at line 1874 of file FVM.cpp.

const char ZERO_GREATER_PSTR[] = "0>"
static

Definition at line 1978 of file FVM.cpp.

const char ZERO_LESS_PSTR[] = "0<"
static

Definition at line 1976 of file FVM.cpp.

const char ZERO_NOT_EQUALS_PSTR[] = "0<>"
static

Definition at line 1975 of file FVM.cpp.

const char ZERO_PSTR[] = "0"
static

Definition at line 1937 of file FVM.cpp.