Add terser Y syntax
This commit is contained in:
@ -43,12 +43,12 @@
|
|||||||
|
|
||||||
#define PLATFORM_OPCODE_LIST \
|
#define PLATFORM_OPCODE_LIST \
|
||||||
/* Memory Allocation */ \
|
/* Memory Allocation */ \
|
||||||
X("MALLOC", MALLOC, tos = (cell_t) malloc(tos)) \
|
Y(MALLOC, tos = (cell_t) malloc(tos)) \
|
||||||
X("SYSFREE", FREE, free((void *) tos); DROP) \
|
Y(SYSFREE, free((void *) tos); DROP) \
|
||||||
X("REALLOC", REALLOC, tos = (cell_t) realloc((void *) *sp, tos); --sp) \
|
Y(REALLOC, tos = (cell_t) realloc((void *) *sp, tos); --sp) \
|
||||||
X("heap_caps_malloc", HEAP_CAPS_MALLOC, tos = (cell_t) heap_caps_malloc(*sp, tos); --sp) \
|
Y(heap_caps_malloc, tos = (cell_t) heap_caps_malloc(*sp, tos); --sp) \
|
||||||
X("heap_caps_free", HEAP_CAPS_FREE, heap_caps_free((void *) tos); DROP) \
|
Y(heap_caps_free, heap_caps_free((void *) tos); DROP) \
|
||||||
X("heap_caps_realloc", HEAP_CAPS_REALLOC, \
|
Y(heap_caps_realloc, \
|
||||||
tos = (cell_t) heap_caps_realloc((void *) sp[-1], *sp, tos); sp -= 2) \
|
tos = (cell_t) heap_caps_realloc((void *) sp[-1], *sp, tos); sp -= 2) \
|
||||||
/* Serial */ \
|
/* Serial */ \
|
||||||
X("Serial.begin", SERIAL_BEGIN, Serial.begin(tos); DROP) \
|
X("Serial.begin", SERIAL_BEGIN, Serial.begin(tos); DROP) \
|
||||||
@ -58,29 +58,29 @@
|
|||||||
X("Serial.write", SERIAL_WRITE, tos = Serial.write((const uint8_t *) *sp, tos); --sp) \
|
X("Serial.write", SERIAL_WRITE, tos = Serial.write((const uint8_t *) *sp, tos); --sp) \
|
||||||
X("Serial.flush", SERIAL_FLUSH, Serial.flush()) \
|
X("Serial.flush", SERIAL_FLUSH, Serial.flush()) \
|
||||||
/* Pins and PWM */ \
|
/* Pins and PWM */ \
|
||||||
X("pinMode", PIN_MODE, pinMode(*sp, tos); --sp; DROP) \
|
Y(pinMode, pinMode(*sp, tos); --sp; DROP) \
|
||||||
X("digitalWrite", DIGITAL_WRITE, digitalWrite(*sp, tos); --sp; DROP) \
|
Y(digitalWrite, digitalWrite(*sp, tos); --sp; DROP) \
|
||||||
X("digitalRead", DIGITAL_READ, tos = (cell_t) digitalRead(tos)) \
|
Y(digitalRead, tos = (cell_t) digitalRead(tos)) \
|
||||||
X("analogRead", ANALOG_READ, tos = (cell_t) analogRead(tos)) \
|
Y(analogRead, tos = (cell_t) analogRead(tos)) \
|
||||||
X("ledcSetup", LEDC_SETUP, \
|
Y(ledcSetup, \
|
||||||
tos = (cell_t) (1000000 * ledcSetup(sp[-1], *sp / 1000.0, tos)); sp -= 2) \
|
tos = (cell_t) (1000000 * ledcSetup(sp[-1], *sp / 1000.0, tos)); sp -= 2) \
|
||||||
X("ledcAttachPin", ATTACH_PIN, ledcAttachPin(*sp, tos); --sp; DROP) \
|
Y(ledcAttachPin, ledcAttachPin(*sp, tos); --sp; DROP) \
|
||||||
X("ledcDetachPin", DETACH_PIN, ledcDetachPin(tos); DROP) \
|
Y(ledcDetachPin, ledcDetachPin(tos); DROP) \
|
||||||
X("ledcRead", LEDC_READ, tos = (cell_t) ledcRead(tos)) \
|
Y(ledcRead, tos = (cell_t) ledcRead(tos)) \
|
||||||
X("ledcReadFreq", LEDC_READ_FREQ, tos = (cell_t) (1000000 * ledcReadFreq(tos))) \
|
Y(ledcReadFreq, tos = (cell_t) (1000000 * ledcReadFreq(tos))) \
|
||||||
X("ledcWrite", LEDC_WRITE, ledcWrite(*sp, tos); --sp; DROP) \
|
Y(ledcWrite, ledcWrite(*sp, tos); --sp; DROP) \
|
||||||
X("ledcWriteTone", LEDC_WRITE_TONE, \
|
Y(ledcWriteTone, \
|
||||||
tos = (cell_t) (1000000 * ledcWriteTone(*sp, tos / 1000.0)); --sp) \
|
tos = (cell_t) (1000000 * ledcWriteTone(*sp, tos / 1000.0)); --sp) \
|
||||||
X("ledcWriteNote", LEDC_WRITE_NOTE, \
|
Y(ledcWriteNote, \
|
||||||
tos = (cell_t) (1000000 * ledcWriteNote(sp[-1], (note_t) *sp, tos)); sp -=2) \
|
tos = (cell_t) (1000000 * ledcWriteNote(sp[-1], (note_t) *sp, tos)); sp -=2) \
|
||||||
/* General System */ \
|
/* General System */ \
|
||||||
X("MS", MS, delay(tos); DROP) \
|
Y(MS, delay(tos); DROP) \
|
||||||
X("TERMINATE", TERMINATE, exit(tos)) \
|
Y(TERMINATE, exit(tos)) \
|
||||||
/* File words */ \
|
/* File words */ \
|
||||||
X("R/O", R_O, PUSH(O_RDONLY)) \
|
X("R/O", R_O, PUSH(O_RDONLY)) \
|
||||||
X("R/W", R_W, PUSH(O_RDWR)) \
|
X("R/W", R_W, PUSH(O_RDWR)) \
|
||||||
X("W/O", W_O, PUSH(O_WRONLY)) \
|
X("W/O", W_O, PUSH(O_WRONLY)) \
|
||||||
X("BIN", BIN, ) \
|
Y(BIN, ) \
|
||||||
X("CLOSE-FILE", CLOSE_FILE, tos = close(tos); tos = tos ? errno : 0) \
|
X("CLOSE-FILE", CLOSE_FILE, tos = close(tos); tos = tos ? errno : 0) \
|
||||||
X("FLUSH-FILE", FLUSH_FILE, fsync(tos); /* fsync has no impl and returns ENOSYS :-( */ tos = 0) \
|
X("FLUSH-FILE", FLUSH_FILE, fsync(tos); /* fsync has no impl and returns ENOSYS :-( */ tos = 0) \
|
||||||
X("OPEN-FILE", OPEN_FILE, cell_t mode = tos; DROP; cell_t len = tos; DROP; \
|
X("OPEN-FILE", OPEN_FILE, cell_t mode = tos; DROP; cell_t len = tos; DROP; \
|
||||||
@ -134,15 +134,15 @@
|
|||||||
# include "esp_camera.h"
|
# include "esp_camera.h"
|
||||||
# define OPTIONAL_CAMERA_SUPPORT \
|
# define OPTIONAL_CAMERA_SUPPORT \
|
||||||
/* Camera */ \
|
/* Camera */ \
|
||||||
X("esp_camera_init", ESP_CAMERA_INIT, \
|
Y(esp_camera_init, \
|
||||||
tos = esp_camera_init((const camera_config_t *) tos)) \
|
tos = esp_camera_init((const camera_config_t *) tos)) \
|
||||||
X("esp_camera_deinit", ESP_CAMERA_DEINIT, \
|
Y(esp_camera_deinit, \
|
||||||
DUP; tos = esp_camera_deinit()) \
|
DUP; tos = esp_camera_deinit()) \
|
||||||
X("esp_camera_fb_get", ESP_CAMERA_FB_GET, \
|
Y(esp_camera_fb_get, \
|
||||||
DUP; tos = (cell_t) esp_camera_fb_get()) \
|
DUP; tos = (cell_t) esp_camera_fb_get()) \
|
||||||
X("esp_camera_db_return", ESP_CAMERA_FB_RETURN, \
|
Y(esp_camera_db_return, \
|
||||||
esp_camera_fb_return((camera_fb_t *) tos); DROP) \
|
esp_camera_fb_return((camera_fb_t *) tos); DROP) \
|
||||||
X("esp_camera_sensor_get", ESP_CAMERA_SENSOR_GET, \
|
Y(esp_camera_sensor_get, \
|
||||||
DUP; tos = (cell_t) esp_camera_sensor_get())
|
DUP; tos = (cell_t) esp_camera_sensor_get())
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -218,7 +218,7 @@
|
|||||||
X("SerialBT.connected", SERIALBT_CONNECTED, tos = ((BluetoothSerial *) tos)->connected(*sp); --sp) \
|
X("SerialBT.connected", SERIALBT_CONNECTED, tos = ((BluetoothSerial *) tos)->connected(*sp); --sp) \
|
||||||
X("SerialBT.isReady", SERIALBT_IS_READY, tos = ((BluetoothSerial *) tos)->isReady(sp[-1], *sp); sp -= 2) \
|
X("SerialBT.isReady", SERIALBT_IS_READY, tos = ((BluetoothSerial *) tos)->isReady(sp[-1], *sp); sp -= 2) \
|
||||||
/* Bluetooth */ \
|
/* Bluetooth */ \
|
||||||
X("esp_bt_dev_get_address", ESP_BT_DEV_GET_ADDRESS, DUP; tos = (cell_t) esp_bt_dev_get_address())
|
Y(esp_bt_dev_get_address, DUP; tos = (cell_t) esp_bt_dev_get_address())
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ENABLE_WIFI_SUPPORT
|
#ifndef ENABLE_WIFI_SUPPORT
|
||||||
|
|||||||
@ -4,15 +4,15 @@
|
|||||||
typedef cell_t (CALLTYPE *call_t)();
|
typedef cell_t (CALLTYPE *call_t)();
|
||||||
|
|
||||||
#define CALLING_OPCODE_LIST \
|
#define CALLING_OPCODE_LIST \
|
||||||
X("CALL0", OP_CALL0, tos = ((call_t) tos)()) \
|
Y(CALL0, tos = ((call_t) tos)()) \
|
||||||
X("CALL1", OP_CALL1, tos = ((call_t) tos)(*sp); --sp) \
|
Y(CALL1, tos = ((call_t) tos)(*sp); --sp) \
|
||||||
X("CALL2", OP_CALL2, tos = ((call_t) tos)(sp[-1], *sp); sp -= 2) \
|
Y(CALL2, tos = ((call_t) tos)(sp[-1], *sp); sp -= 2) \
|
||||||
X("CALL3", OP_CALL3, tos = ((call_t) tos)(sp[-2], sp[-1], *sp); sp -= 3) \
|
Y(CALL3, tos = ((call_t) tos)(sp[-2], sp[-1], *sp); sp -= 3) \
|
||||||
X("CALL4", OP_CALL4, tos = ((call_t) tos)(sp[-3], sp[-2], sp[-1], *sp); sp -= 4) \
|
Y(CALL4, tos = ((call_t) tos)(sp[-3], sp[-2], sp[-1], *sp); sp -= 4) \
|
||||||
X("CALL5", OP_CALL5, tos = ((call_t) tos)(sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 5) \
|
Y(CALL5, tos = ((call_t) tos)(sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 5) \
|
||||||
X("CALL6", OP_CALL6, tos = ((call_t) tos)(sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 6) \
|
Y(CALL6, tos = ((call_t) tos)(sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 6) \
|
||||||
X("CALL7", OP_CALL7, tos = ((call_t) tos)(sp[-6], sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 7) \
|
Y(CALL7, tos = ((call_t) tos)(sp[-6], sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 7) \
|
||||||
X("CALL8", OP_CALL8, tos = ((call_t) tos)(sp[-7], sp[-6], sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 8) \
|
Y(CALL8, tos = ((call_t) tos)(sp[-7], sp[-6], sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 8) \
|
||||||
X("CALL9", OP_CALL9, tos = ((call_t) tos)(sp[-8], sp[-7], sp[-6], sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 9) \
|
Y(CALL9, tos = ((call_t) tos)(sp[-8], sp[-7], sp[-6], sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 9) \
|
||||||
X("CALL10", OP_CALL10, tos = ((call_t) tos)(sp[-9], sp[-8], sp[-7], sp[-6], sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 10) \
|
Y(CALL10, tos = ((call_t) tos)(sp[-9], sp[-8], sp[-7], sp[-6], sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 10) \
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
typedef intptr_t cell_t;
|
typedef intptr_t cell_t;
|
||||||
typedef uintptr_t ucell_t;
|
typedef uintptr_t ucell_t;
|
||||||
|
|
||||||
|
#define Y(op, code) X(#op, id ## op, code)
|
||||||
#define DUP *++sp = tos
|
#define DUP *++sp = tos
|
||||||
#define DROP tos = *sp--
|
#define DROP tos = *sp--
|
||||||
#define COMMA(n) *g_sys.heap++ = (n)
|
#define COMMA(n) *g_sys.heap++ = (n)
|
||||||
@ -34,13 +35,13 @@ typedef int64_t dcell_t;
|
|||||||
X("U/MOD", USMOD, w = *sp; *sp = (ucell_t) w % (ucell_t) tos; \
|
X("U/MOD", USMOD, w = *sp; *sp = (ucell_t) w % (ucell_t) tos; \
|
||||||
tos = (ucell_t) w / (ucell_t) tos) \
|
tos = (ucell_t) w / (ucell_t) tos) \
|
||||||
X("*/MOD", SSMOD, SSMOD_FUNC) \
|
X("*/MOD", SSMOD, SSMOD_FUNC) \
|
||||||
X("AND", AND, tos &= *sp--) \
|
Y(AND, tos &= *sp--) \
|
||||||
X("OR", OR, tos |= *sp--) \
|
Y(OR, tos |= *sp--) \
|
||||||
X("XOR", XOR, tos ^= *sp--) \
|
Y(XOR, tos ^= *sp--) \
|
||||||
X("DUP", DUP, DUP) \
|
Y(DUP, DUP) \
|
||||||
X("SWAP", SWAP, w = tos; tos = *sp; *sp = w) \
|
Y(SWAP, w = tos; tos = *sp; *sp = w) \
|
||||||
X("OVER", OVER, DUP; tos = sp[-1]) \
|
Y(OVER, DUP; tos = sp[-1]) \
|
||||||
X("DROP", DROP, DROP) \
|
Y(DROP, DROP) \
|
||||||
X("@", AT, tos = *(cell_t *) tos) \
|
X("@", AT, tos = *(cell_t *) tos) \
|
||||||
X("L@", LAT, tos = *(int32_t *) tos) \
|
X("L@", LAT, tos = *(int32_t *) tos) \
|
||||||
X("C@", CAT, tos = *(uint8_t *) tos) \
|
X("C@", CAT, tos = *(uint8_t *) tos) \
|
||||||
@ -54,30 +55,28 @@ typedef int64_t dcell_t;
|
|||||||
X(">R", TOR, *++rp = tos; DROP) \
|
X(">R", TOR, *++rp = tos; DROP) \
|
||||||
X("R>", FROMR, DUP; tos = *rp; --rp) \
|
X("R>", FROMR, DUP; tos = *rp; --rp) \
|
||||||
X("R@", RAT, DUP; tos = *rp) \
|
X("R@", RAT, DUP; tos = *rp) \
|
||||||
X("EXECUTE", EXECUTE, w = tos; DROP; JMPW) \
|
Y(EXECUTE, w = tos; DROP; JMPW) \
|
||||||
X("BRANCH", BRANCH, ip = (cell_t *) *ip) \
|
Y(BRANCH, ip = (cell_t *) *ip) \
|
||||||
X("0BRANCH", ZBRANCH, if (!tos) ip = (cell_t *) *ip; else ++ip; DROP) \
|
Y(0BRANCH, if (!tos) ip = (cell_t *) *ip; else ++ip; DROP) \
|
||||||
X("DONEXT", DONEXT, *rp = *rp - 1; \
|
Y(DONEXT, *rp = *rp - 1; if (~*rp) ip = (cell_t *) *ip; else (--rp, ++ip)) \
|
||||||
if (~*rp) ip = (cell_t *) *ip; else (--rp, ++ip)) \
|
Y(DOLIT, DUP; tos = *ip++) \
|
||||||
X("DOLIT", DOLIT, DUP; tos = *ip++) \
|
Y(ALITERAL, COMMA(g_sys.DOLIT_XT); COMMA(tos); DROP) \
|
||||||
X("ALITERAL", ALITERAL, COMMA(g_sys.DOLIT_XT); COMMA(tos); DROP) \
|
Y(CELL, DUP; tos = sizeof(cell_t)) \
|
||||||
X("CELL", CELL, DUP; tos = sizeof(cell_t)) \
|
Y(FIND, tos = find((const char *) *sp, tos); --sp) \
|
||||||
X("FIND", FIND, tos = find((const char *) *sp, tos); --sp) \
|
Y(PARSE, DUP; tos = parse(tos, sp)) \
|
||||||
X("PARSE", PARSE, DUP; tos = parse(tos, sp)) \
|
|
||||||
X("S>NUMBER?", CONVERT, tos = convert((const char *) *sp, tos, sp); \
|
X("S>NUMBER?", CONVERT, tos = convert((const char *) *sp, tos, sp); \
|
||||||
if (!tos) --sp) \
|
if (!tos) --sp) \
|
||||||
X("CREATE", CREATE, DUP; DUP; tos = parse(32, sp); \
|
Y(CREATE, DUP; DUP; tos = parse(32, sp); \
|
||||||
create((const char *) *sp, tos, 0, ADDR_DOCREATE); \
|
create((const char *) *sp, tos, 0, ADDR_DOCREATE); \
|
||||||
COMMA(0); --sp; DROP) \
|
COMMA(0); --sp; DROP) \
|
||||||
X("DOES>", DOES, DOES(ip); ip = (cell_t *) *rp; --rp) \
|
X("DOES>", DOES, DOES(ip); ip = (cell_t *) *rp; --rp) \
|
||||||
X("IMMEDIATE", IMMEDIATE, DOIMMEDIATE()) \
|
Y(IMMEDIATE, DOIMMEDIATE()) \
|
||||||
X("'SYS", SYS, DUP; tos = (cell_t) &g_sys) \
|
X("'SYS", SYS, DUP; tos = (cell_t) &g_sys) \
|
||||||
X("YIELD", YIELD, PARK; return rp) \
|
Y(YIELD, PARK; return rp) \
|
||||||
X(":", COLON, DUP; DUP; tos = parse(32, sp); \
|
X(":", COLON, DUP; DUP; tos = parse(32, sp); \
|
||||||
create((const char *) *sp, tos, SMUDGE, ADDR_DOCOLON); \
|
create((const char *) *sp, tos, SMUDGE, ADDR_DOCOLON); \
|
||||||
g_sys.state = -1; --sp; DROP) \
|
g_sys.state = -1; --sp; DROP) \
|
||||||
X("EVALUATE1", EVALUATE1, DUP; sp = evaluate1(sp); w = *sp--; DROP; \
|
Y(EVALUATE1, DUP; sp = evaluate1(sp); w = *sp--; DROP; if (w) JMPW) \
|
||||||
if (w) JMPW) \
|
Y(EXIT, ip = (cell_t *) *rp--) \
|
||||||
X("EXIT", EXIT, ip = (cell_t *) *rp--) \
|
|
||||||
X(";", SEMICOLON, UNSMUDGE(); COMMA(g_sys.DOEXIT_XT); g_sys.state = 0) \
|
X(";", SEMICOLON, UNSMUDGE(); COMMA(g_sys.DOEXIT_XT); g_sys.state = 0) \
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
#define STACK_SIZE (16 * 1024)
|
#define STACK_SIZE (16 * 1024)
|
||||||
|
|
||||||
#define PLATFORM_OPCODE_LIST \
|
#define PLATFORM_OPCODE_LIST \
|
||||||
X("DLSYM", DLSYM, tos = (cell_t) dlsym((void *) *sp, (void *) tos); --sp) \
|
Y(DLSYM, tos = (cell_t) dlsym((void *) *sp, (void *) tos); --sp) \
|
||||||
CALLING_OPCODE_LIST \
|
CALLING_OPCODE_LIST \
|
||||||
|
|
||||||
#include "common/core.h"
|
#include "common/core.h"
|
||||||
|
|||||||
@ -20,9 +20,9 @@
|
|||||||
#define STACK_SIZE (64 * 1024)
|
#define STACK_SIZE (64 * 1024)
|
||||||
|
|
||||||
#define PLATFORM_OPCODE_LIST \
|
#define PLATFORM_OPCODE_LIST \
|
||||||
X("GETPROCADDRESS", GETPROCADDRESS, \
|
Y(GETPROCADDRESS, \
|
||||||
tos = (cell_t) GetProcAddress((HMODULE) *sp, (LPCSTR) tos); --sp) \
|
tos = (cell_t) GetProcAddress((HMODULE) *sp, (LPCSTR) tos); --sp) \
|
||||||
X("LOADLIBRARYA", LOADLIBRARYA, \
|
Y(LOADLIBRARYA, \
|
||||||
tos = (cell_t) LoadLibraryA((LPCSTR) tos)) \
|
tos = (cell_t) LoadLibraryA((LPCSTR) tos)) \
|
||||||
CALLING_OPCODE_LIST \
|
CALLING_OPCODE_LIST \
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user