From acdb20167781b865d43258ce5564e8be06bf8cc6 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Thu, 7 Jan 2021 19:34:09 -0800 Subject: [PATCH] Adding Webserver on. --- ueforth/arduino/arduino.template.ino | 24 ++++++++++++++++++++++++ ueforth/common/core.h | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ueforth/arduino/arduino.template.ino b/ueforth/arduino/arduino.template.ino index 19add04..b735f34 100644 --- a/ueforth/arduino/arduino.template.ino +++ b/ueforth/arduino/arduino.template.ino @@ -100,6 +100,10 @@ WebServer *ws = (WebServer *) tos; DROP; ws->begin(tos); DROP) \ X("WebServer.stop", WEBSERVER_STOP, \ WebServer *ws = (WebServer *) tos; DROP; ws->stop()) \ + X("WebServer.on", WEBSERVER_ON, \ + WebServer *ws = (WebServer *) tos; DROP; \ + const char *url = (const char *) tos; DROP; \ + InvokeWebServerOn(ws, url, tos); DROP) \ // TODO: Why doesn't ftruncate exist? // X("RESIZE-FILE", RESIZE_FILE, cell_t fd = tos; DROP; \ @@ -123,6 +127,26 @@ static cell_t FromIP(IPAddress ip) { return ret; } +static void InvokeWebServerOn(WebServer *ws, const char *url, cell_t xt) { + ws->on(url, [xt]() { + cell_t *old_ip = g_sys.ip; + cell_t *old_rp = g_sys.rp; + cell_t *old_sp = g_sys.sp; + cell_t stack[16]; + cell_t rstack[16]; + g_sys.sp = stack + 1; + g_sys.rp = rstack; + cell_t code[2]; + code[0] = xt; + code[1] = g_sys.YIELD_XT; + g_sys.ip = code; + ueforth_run(); + g_sys.ip = old_ip; + g_sys.rp = old_rp; + g_sys.sp = old_sp; + }); +} + void setup() { cell_t *heap = (cell_t *) malloc(HEAP_SIZE); ueforth(0, 0, heap, boot, sizeof(boot)); diff --git a/ueforth/common/core.h b/ueforth/common/core.h index 2cda19f..9683cff 100644 --- a/ueforth/common/core.h +++ b/ueforth/common/core.h @@ -15,7 +15,7 @@ static struct { cell_t *heap, *last, notfound; int argc; char **argv; - cell_t DOLIT_XT, DOEXIT_XT; + cell_t DOLIT_XT, DOEXIT_XT, YIELD_XT; cell_t *ip, *sp, *rp; // Parked alternates } g_sys; @@ -148,6 +148,7 @@ static void ueforth(int argc, char *argv[], void *heap, g_sys.last[-1] = 1; // Make ; IMMEDIATE g_sys.DOLIT_XT = FIND("DOLIT"); g_sys.DOEXIT_XT = FIND("EXIT"); + g_sys.YIELD_XT = FIND("YIELD"); g_sys.notfound = FIND("DROP"); g_sys.ip = g_sys.heap; *g_sys.heap++ = FIND("EVALUATE1");