nanoFORTH v2.2
Loading...
Searching...
No Matches
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 "
37#define N4_API_SZ 8
38#define TRC_LEVEL 1
42#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
58extern int Serial;
59#endif // ARDUINO
60#define INLINE inline __attribute__((always_inline))
65typedef uint8_t U8;
66typedef uint16_t U16;
67typedef int16_t S16;
68typedef uint32_t U32;
69typedef int32_t S32;
70typedef void (*FPTR)();
75typedef U16 IU;
76typedef S16 DU;
77typedef S32 DU2;
79{
80 static FPTR api[N4_API_SZ];
81
82public:
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
Definition n4.h:79
void exec()
nanoForth execute one line of command input
Definition n4.cpp:27
static void wait(U32 ms)
pause NanoForth thread for ms microseconds, yield to user tasks
Definition n4.cpp:49
void setup(const char *code=0, Stream &io=Serial, U8 ucase=0)
placeholder for extra setup
Definition n4.cpp:20
static void yield()
nanoForth yield to user tasks
Definition n4.cpp:42
static void call_api(U16 id)
call C API interface
Definition n4.cpp:33
static FPTR api[N4_API_SZ]
C API function pointer slots.
Definition n4.h:9
static void add_api(U16 i, void(*fp)())
Definition n4.cpp:13
uint16_t U16
16-bit unsigned integer, for return stack, and pointers
Definition n4.h:66
S16 DU
16-bit data unit (CELL)
Definition n4.h:76
int32_t S32
32-bit signed integer
Definition n4.h:69
U16 IU
16-bit instruction unit (ADDR)
Definition n4.h:75
uint32_t U32
32-bit unsigned integer, for millis()
Definition n4.h:68
int16_t S16
16-bit signed integer, for general numbers
Definition n4.h:67
#define N4_API_SZ
Definition n4.h:37
uint8_t U8
8-bit unsigned integer, for char and short int
Definition n4.h:65
S32 DU2
Definition n4.h:77
void(* FPTR)()
function pointer
Definition n4.h:70