ESP32forth
February
Update
π
February 13, 2021
ESP32forth
v7
New Website:
π
esp32forth.appspot.com
Topics
π
β’ Vocabularies
β’ Block Editor
β’ Adding Words
π£οΈ
Vocabularies
Hybrid Vocabularies
π
β’ Forth-79 Style Chaining
β’ Forth-83+ Style Vocabulary Stack
VOCABULARY ( "name" ) Create a vocabulary
FORTH ( -- ) The FORTH vocabulary
DEFINITIONS ( -- ) Make the context, current
VLIST ( -- ) List the vocabulary
WORDS ( -- ) List the reachable words
TRANSFER ( "name" ) Move a word
ALSO ( -- ) Add vocabulary
ONLY ( -- ) Reset back to Forth only
( Non-standard )
ORDER ( -- ) Print search order
SEALED ( -- ) Make it Forth-83+
π§± Block
Editor
SCR ( -- a ) Pointer to last listed block
USE ( "name" -- ) e.g. USE /spiffs/foo
FLUSH ( -- ) Save and empty all buffers
LIST ( n -- ) List a block
LOAD ( n -- ) Evaluate a block
EDITOR ( -- ) Enter editor vocabulary
WIPE ( -- ) Blank out current block
L ( -- ) List the current block
D ( n -- ) Delete a line
E ( n -- ) Erase a line
R ( n "text" -- ) Replace a line
A ( n "text" -- ) Add (insert) a line
P ( -- ) Move to the previous block
N ( -- ) Move to the next block
Live π₯
Demo...
Adding
π¬Words
#define OPCODE_LIST \
X("0=", ZEQUAL, tos = !tos ? -1 : 0) \
X("0<", ZLESS, tos = (tos|0) < 0 ? -1 : 0) \
X("+", PLUS, tos += *sp--) \
Y(MY_WORD123, c_function_to_call()) \
X("myword!", MY_WORD_BANG, c_function_to_call()) \
Y(MY_WORD, PUSH calculate_magic_value()) \
n10 n9 n8 n7 n6 n5 n4 n3 n2 n1 n0 - Access stack as cell_t integer values
c4 c3 c2 c1 c0 - Access stack as char* values
b4 b3 b2 b1 b0 - Access stack as uint8_t* byte values
a4 a3 a2 a1 a0 - Access stack as void* values
void send_message(const char *message, int code);
π
X("send-message", SEND_MESSAGE, send_message(c1, n0)) \
Y(DECODE, SET decode_func(n0)) \
Y(MY_WORD, cell_t foo = n0; DROP; char *x = c0; DROP; \
PUSH my_func(foo, x)) \
# define ws0 ((WebServer *) a0)
# define OPTIONAL_WEBSERVER_SUPPORT \
/* WebServer */ \
X("WebServer.new", WEBSERVER_NEW, PUSH new WebServer(tos)) \
X("WebServer.delete", WEBSERVER_DELETE, delete ws0; DROP) \
X("WebServer.begin", WEBSERVER_BEGIN, ws0->begin(n1); DROPn(2)) \
X("WebServer.stop", WEBSERVER_STOP, ws0->stop(); DROP) \
X("WebServer.on", WEBSERVER_ON, InvokeWebServerOn(ws0, c2, n1); DROPn(3)) \
X("WebServer.hasArg", WEBSERVER_HAS_ARG, n0 = ws0->hasArg(c1); DROP) \
static void InvokeWebServerOn(WebServer *ws, const char *url, cell_t xt) {
ws->on(url, [xt]() {
cell_t code[2];
code[0] = xt;
code[1] = g_sys.YIELD_XT;
cell_t stack[16];
cell_t rstack[16];
cell_t *rp = rstack;
*++rp = (cell_t) (stack + 1);
*++rp = (cell_t) code;
forth_run(rp);
});
QUESTIONS?
β
Thank you!