diff --git a/ueforth/esp32/builtins.h b/ueforth/esp32/builtins.h index a59bf2c..b4b07aa 100644 --- a/ueforth/esp32/builtins.h +++ b/ueforth/esp32/builtins.h @@ -62,6 +62,8 @@ static cell_t ResizeFile(cell_t fd, cell_t size); OPTIONAL_SPI_FLASH_SUPPORT \ USER_WORDS +#ifndef SIM_PRINT_ONLY + #define REQUIRED_MEMORY_SUPPORT \ Y(MALLOC, SET malloc(n0)) \ Y(SYSFREE, free(a0); DROP) \ @@ -84,6 +86,8 @@ static cell_t ResizeFile(cell_t fd, cell_t size); X("Serial.write", SERIAL_WRITE, n0 = Serial.write(b1, n0); NIP) \ X("Serial.flush", SERIAL_FLUSH, Serial.flush()) +#endif + #define REQUIRED_ARDUINO_GPIO_SUPPORT \ Y(pinMode, pinMode(n1, n0); DROPn(2)) \ Y(digitalWrite, digitalWrite(n1, n0); DROPn(2)) \ diff --git a/ueforth/esp32/print-builtins.cpp b/ueforth/esp32/print-builtins.cpp index 9f868cd..71d4bbf 100644 --- a/ueforth/esp32/print-builtins.cpp +++ b/ueforth/esp32/print-builtins.cpp @@ -20,12 +20,15 @@ #include "esp32/options.h" #define FLOATING_POINT_LIST #define USER_WORDS +#define REQUIRED_MEMORY_SUPPORT +#define REQUIRED_SYSTEM_SUPPORT +#define REQUIRED_SERIAL_SUPPORT #include "builtins.h" #define Y(name, code) X(#name, name, code) int main() { - printf("#define PLATFORM_OPCODE_LIST \\\n"); + printf("#define PLATFORM_MOCK_OPCODE_LIST \\\n"); #define X(str, name, code) printf(" X(\"%s\", %s, ) \\\n", str, #name); PLATFORM_OPCODE_LIST #undef X diff --git a/ueforth/esp32/sim_main.cpp b/ueforth/esp32/sim_main.cpp index e21a7b9..6a5e10a 100644 --- a/ueforth/esp32/sim_main.cpp +++ b/ueforth/esp32/sim_main.cpp @@ -17,6 +17,38 @@ #include "common/opcodes.h" #include "common/floats.h" #include "common/calling.h" +#include +#include + +#define PLATFORM_OPCODE_LIST \ + FLOATING_POINT_LIST \ + REQUIRED_MEMORY_SUPPORT \ + REQUIRED_SYSTEM_SUPPORT \ + REQUIRED_SERIAL_SUPPORT \ + PLATFORM_MOCK_OPCODE_LIST + +#define REQUIRED_MEMORY_SUPPORT \ + Y(MALLOC, SET malloc(n0)) \ + Y(SYSFREE, free(a0); DROP) \ + Y(REALLOC, SET realloc(a1, n0); NIP) \ + Y(heap_caps_malloc, SET malloc(n1); NIP) \ + Y(heap_caps_free, free(a0); DROP) \ + Y(heap_caps_realloc, \ + tos = (cell_t) realloc(a2, n1); NIPn(2)) + +#define REQUIRED_SYSTEM_SUPPORT \ + X("MS-TICKS", MS_TICKS, PUSH time(0) * 1000) \ + X("RAW-YIELD", RAW_YIELD, ) \ + Y(TERMINATE, exit(n0)) + +#define REQUIRED_SERIAL_SUPPORT \ + X("Serial.begin", SERIAL_BEGIN, DROP) \ + X("Serial.end", SERIAL_END, ) \ + X("Serial.available", SERIAL_AVAILABLE, PUSH -1) \ + X("Serial.readBytes", SERIAL_READ_BYTES, n0 = read(0, b1, n0); NIP) \ + X("Serial.write", SERIAL_WRITE, n0 = write(1, b1, n0); NIP) \ + X("Serial.flush", SERIAL_FLUSH, ) + #include "gen/esp32_sim_opcodes.h" #include "common/core.h" #include "common/interp.h"