diff --git a/ueforth/Makefile b/ueforth/Makefile index fb985f2..cc654fa 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -74,7 +74,8 @@ WIN_LFLAGS64 = /LIBPATH:"c:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Lib TARGETS = $(WEB)/terminal.html \ $(WEB)/ueforth.js \ $(POSIX)/ueforth \ - $(ESP32)/ESP32forth/ESP32forth.ino + $(ESP32)/ESP32forth/ESP32forth.ino \ + $(ESP32_SIM)/Esp32forth-sim LSQ = ls 2>/dev/null @@ -260,6 +261,7 @@ $(POSIX)/ueforth: \ posix/main.c \ common/opcodes.h \ common/calls.h \ + common/calling.h \ common/floats.h \ common/interp.h \ common/core.h \ @@ -276,6 +278,7 @@ $(WINDOWS)/uEf32.obj: \ windows/main.c \ common/opcodes.h \ common/calls.h \ + common/calling.h \ common/floats.h \ common/core.h \ windows/interp.h \ @@ -291,6 +294,7 @@ $(WINDOWS)/uEf64.obj: \ windows/main.c \ common/opcodes.h \ common/calls.h \ + common/calling.h \ common/floats.h \ common/core.h \ windows/interp.h \ @@ -307,12 +311,26 @@ $(WINDOWS)/uEf64.exe: \ $(ESP32_SIM): mkdir -p $@ -$(ESP32_SIM)/print-builtins: \ - esp32/print-builtins.c esp32/builtins.h | $(ESP32_SIM) +$(GEN)/print-esp32-builtins: \ + esp32/print-builtins.c esp32/builtins.h | $(GEN) $(CC) $< -o $@ -print: $(ESP32_SIM)/print-builtins - $< +$(GEN)/esp32_sim_opcodes.h: $(GEN)/print-esp32-builtins | $(GEN) + $< >$@ + +$(ESP32_SIM)/Esp32forth-sim: \ + esp32/sim_main.cpp \ + esp32/main.cpp \ + common/opcodes.h \ + common/floats.h \ + common/calling.h \ + common/floats.h \ + common/core.h \ + common/interp.h \ + $(GEN)/esp32_boot.h \ + $(GEN)/esp32_sim_opcodes.h | $(ESP32_SIM) + $(CXX) $(CFLAGS) -g $< -o $@ + strip $(STRIP_ARGS) $@ # ---- ESP32 ---- @@ -329,12 +347,14 @@ ESP32_PARTS = common/replace.js \ esp32/options.h \ esp32/builtins.h \ esp32/builtins.cpp \ + esp32/main.cpp \ $(GEN)/esp32_boot.h $(ESP32)/ESP32forth/ESP32forth.ino: $(ESP32_PARTS) | $(ESP32)/ESP32forth cat esp32/template.ino | common/replace.js \ VERSION=$(VERSION) \ REVISION=$(REVISION) \ + config=@esp32/config.h \ opcodes=@common/opcodes.h \ calling=@common/calling.h \ floats=@common/floats.h \ @@ -343,6 +363,7 @@ $(ESP32)/ESP32forth/ESP32forth.ino: $(ESP32_PARTS) | $(ESP32)/ESP32forth options=@esp32/options.h \ builtins.h=@esp32/builtins.h \ builtins.cpp=@esp32/builtins.cpp \ + main.cpp=@esp32/main.cpp \ boot=@$(GEN)/esp32_boot.h \ >$@ diff --git a/ueforth/esp32/builtins.cpp b/ueforth/esp32/builtins.cpp index 5bff541..3b023c1 100644 --- a/ueforth/esp32/builtins.cpp +++ b/ueforth/esp32/builtins.cpp @@ -117,12 +117,3 @@ static cell_t TimerIsrRegister(cell_t group, cell_t timer, cell_t xt, cell_t arg return timer_isr_register((timer_group_t) group, (timer_idx_t) timer, HandleInterrupt, args, flags, (timer_isr_handle_t *) ret); } #endif - -void setup() { - cell_t *heap = (cell_t *) malloc(HEAP_SIZE); - forth_init(0, 0, heap, boot, sizeof(boot)); -} - -void loop() { - g_sys.rp = forth_run(g_sys.rp); -} diff --git a/ueforth/esp32/builtins.h b/ueforth/esp32/builtins.h index 93a576e..a59bf2c 100644 --- a/ueforth/esp32/builtins.h +++ b/ueforth/esp32/builtins.h @@ -14,27 +14,23 @@ #ifndef SIM_PRINT_ONLY -#ifdef ENABLE_WEBSERVER_SUPPORT -# include "WebServer.h" -#endif +# ifdef ENABLE_WEBSERVER_SUPPORT +# include "WebServer.h" +# endif -#include -#include -#include -#include -#include -#include - -#define HEAP_SIZE (100 * 1024) -#define STACK_CELLS 512 -#define INTERRUPT_STACK_CELLS 64 +# include +# include +# include +# include +# include +# include // Optional hook to pull in words for userwords.h -#if __has_include("userwords.h") -# include "userwords.h" -#else -# define USER_WORDS -#endif +# if __has_include("userwords.h") +# include "userwords.h" +# else +# define USER_WORDS +# endif static cell_t ResizeFile(cell_t fd, cell_t size); diff --git a/ueforth/esp32/config.h b/ueforth/esp32/config.h new file mode 100644 index 0000000..4ea139b --- /dev/null +++ b/ueforth/esp32/config.h @@ -0,0 +1,17 @@ +// Copyright 2022 Bradley D. Nelson +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#define HEAP_SIZE (100 * 1024) +#define STACK_CELLS 512 +#define INTERRUPT_STACK_CELLS 64 diff --git a/ueforth/esp32/main.cpp b/ueforth/esp32/main.cpp new file mode 100644 index 0000000..c981c25 --- /dev/null +++ b/ueforth/esp32/main.cpp @@ -0,0 +1,22 @@ +// Copyright 2022 Bradley D. Nelson +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +void setup() { + cell_t *heap = (cell_t *) malloc(HEAP_SIZE); + forth_init(0, 0, heap, boot, sizeof(boot)); +} + +void loop() { + g_sys.rp = forth_run(g_sys.rp); +} diff --git a/ueforth/esp32/print-builtins.c b/ueforth/esp32/print-builtins.c index 2e46477..79aeae4 100644 --- a/ueforth/esp32/print-builtins.c +++ b/ueforth/esp32/print-builtins.c @@ -43,8 +43,10 @@ #define Y(name, code) X(#name, name, code) int main() { -#define X(str, name, code) printf("%s\n", str); + printf("#define PLATFORM_OPCODE_LIST \\\n"); +#define X(str, name, code) printf(" X(\"%s\", %s, ) \\\n", str, #name); PLATFORM_OPCODE_LIST #undef X + printf("\n"); return 0; } diff --git a/ueforth/esp32/sim_main.cpp b/ueforth/esp32/sim_main.cpp new file mode 100644 index 0000000..e21a7b9 --- /dev/null +++ b/ueforth/esp32/sim_main.cpp @@ -0,0 +1,31 @@ +// Copyright 2022 Bradley D. Nelson +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "esp32/config.h" +#include "esp32/options.h" +#include "common/opcodes.h" +#include "common/floats.h" +#include "common/calling.h" +#include "gen/esp32_sim_opcodes.h" +#include "common/core.h" +#include "common/interp.h" +#include "gen/esp32_boot.h" +#include "esp32/main.cpp" + +int main(int argc, char *argv[]) { + setup(); + for (;;) { + loop(); + } +} diff --git a/ueforth/esp32/template.ino b/ueforth/esp32/template.ino index 87c2879..f9e3a7d 100644 --- a/ueforth/esp32/template.ino +++ b/ueforth/esp32/template.ino @@ -19,9 +19,11 @@ * Revision: {{REVISION}} */ +{{config}} +{{options}} {{opcodes}} {{floats}} {{calling}} -{{options}} {{builtins.h}} {{builtins.cpp}} +{{main.cpp}}