nanoFORTH  v2.2
n4.h
Go to the documentation of this file.
1 
21 #ifndef __SRC_N4_H
22 #define __SRC_N4_H
23 
24 #define APP_NAME "\nnanoForth 2.2 "
25 #define N4_API_SZ 8
38 #define TRC_LEVEL 1
39 #if ARDUINO
43 #include <Arduino.h>
44 #define log(msg) Serial.print(F(msg))
45 #define logx(v) Serial.print((U16)v, HEX)
46 #else // !ARDUINO // for debugging
47 #include <cstdint> // uint_t
48 #include <cstdio> // printf
49 #include <cstdlib> // malloc
50 #include <iostream>
51 #define PROGMEM
52 #define millis() 10000
53 #define random(v) (rand()%v)
54 #define pgm_read_byte(p) (*(p))
55 #define log(msg) ::printf("%s", msg)
56 #define logx(v) ::printf("%x", (U16)v)
57 #define Stream int
58 extern int Serial;
59 #endif // ARDUINO
60 #define INLINE inline __attribute__((always_inline))
61 typedef uint8_t U8;
66 typedef uint16_t U16;
67 typedef int16_t S16;
68 typedef uint32_t U32;
69 typedef int32_t S32;
70 typedef void (*FPTR)();
71 typedef U16 IU;
76 typedef S16 DU;
77 typedef S32 DU2;
78 class NanoForth
79 {
80  static FPTR fp[N4_API_SZ];
81 
82 public:
83  void setup(
84  const char *code=0,
85  Stream &io=Serial,
86  U8 ucase=0
87  );
88  void exec();
89  //
90  // protothreading support
91  //
92  static void add_api(
93  U16 i,
94  void (*fp)()
95  );
96  static void yield();
97  static void wait(U32 ms);
98  static void call_api(U16 id);
99 };
100 
101 #endif // __SRC_N4_H
NanoForth::yield
static void yield()
nanoForth yield to user tasks
Definition: n4.cpp:42
NanoForth::call_api
static void call_api(U16 id)
call C API interface
Definition: n4.cpp:33
NanoForth
Definition: n4.h:78
NanoForth::fp
static FPTR fp[N4_API_SZ]
C API function pointer slots.
Definition: n4.h:80
DU2
S32 DU2
Definition: n4.h:77
NanoForth::setup
void setup(const char *code=0, Stream &io=Serial, U8 ucase=0)
placeholder for extra setup
Definition: n4.cpp:20
DU
S16 DU
16-bit data unit (CELL)
Definition: n4.h:76
N4_API_SZ
#define N4_API_SZ
Definition: n4.h:37
FPTR
void(* FPTR)()
function pointer
Definition: n4.h:70
S16
int16_t S16
16-bit signed integer, for general numbers
Definition: n4.h:67
U16
uint16_t U16
16-bit unsigned integer, for return stack, and pointers
Definition: n4.h:66
S32
int32_t S32
32-bit signed integer
Definition: n4.h:69
N4Core::io
Stream * io
default to Arduino Serial Monitor
Definition: n4_core.cpp:21
U32
uint32_t U32
32-bit unsigned integer, for millis()
Definition: n4.h:68
NanoForth::add_api
static void add_api(U16 i, void(*fp)())
Definition: n4.cpp:13
U8
uint8_t U8
8-bit unsigned integer, for char and short int
Definition: n4.h:65
NanoForth::exec
void exec()
nanoForth execute one line of command input
Definition: n4.cpp:27
IU
U16 IU
16-bit instruction unit (ADDR)
Definition: n4.h:75
NanoForth::wait
static void wait(U32 ms)
pause NanoForth thread for ms microseconds, yield to user tasks
Definition: n4.cpp:49