From 6884898cb194ce6e07a39e5cc285da89090bb571 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Wed, 5 Jul 2023 15:00:59 -0700 Subject: [PATCH] Peel off assemblers into optional module. Not sufficiently tested. --- Makefile | 59 +++++++++++++++++++++++--- common/forth_namespace_tests.fs | 3 -- esp32/{template.ino => ESP32forth.ino} | 0 esp32/README-optional.txt | 20 +++++++++ esp32/README.txt | 20 +++++++++ esp32/assemblers.h | 26 ++++++++++++ esp32/builtins.h | 10 ++++- esp32/optionals.fs | 19 +++++++++ esp32/print-builtins.cpp | 1 + 9 files changed, 148 insertions(+), 10 deletions(-) rename esp32/{template.ino => ESP32forth.ino} (100%) create mode 100644 esp32/README-optional.txt create mode 100644 esp32/README.txt create mode 100644 esp32/assemblers.h create mode 100644 esp32/optionals.fs diff --git a/Makefile b/Makefile index 723354e..f554428 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -VERSION=7.0.7.12 +VERSION=7.0.7.13 STABLE_VERSION=7.0.6.19 OLD_STABLE_VERSION=7.0.5.4 REVISION=$(shell git rev-parse HEAD | head -c 20) @@ -276,15 +276,31 @@ ESP32_BOOT = $(COMMON_PHASE1) \ esp32/allocation.fs esp32/bindings.fs \ $(COMMON_PHASE2) $(COMMON_FILETOOLS) \ esp32/platform.fs \ - common/assembler.fs esp32/xtensa-assembler.fs esp32/riscv-assembler.fs \ posix/httpd.fs posix/web_interface.fs esp32/web_interface.fs \ esp32/registers.fs esp32/timers.fs \ esp32/bterm.fs posix/telnetd.fs \ esp32/camera.fs esp32/camera_server.fs \ + esp32/optionals.fs \ esp32/autoboot.fs common/fini.fs $(GEN)/esp32_boot.h: tools/source_to_string.js $(ESP32_BOOT) | $(GEN) $< boot $(VERSION) $(REVISION) $(ESP32_BOOT) >$@ +ESP32_ASSEMBLERS = common/assembler.fs \ + esp32/xtensa-assembler.fs \ + esp32/riscv-assembler.fs +$(GEN)/esp32_assemblers.h: tools/source_to_string.js $(ESP32_ASSEMBLERS) | $(GEN) + $< assemblers_source $(VERSION) $(REVISION) $(ESP32_ASSEMBLERS) >$@ + +OPTIONAL_MODULES = $(ESP32)/ESP32forth/assemblers.h + +add-optional: $(OPTIONAL_MODULES) + +drop-optional: + rm -f $(OPTIONAL_MODULES) + +$(ESP32)/ESP32forth/assemblers.h: $(ESP32)/ESP32forth/optional/assemblers.h + cp $< $@ + $(GEN)/dump_web_opcodes: \ web/dump_web_opcodes.c \ common/tier0_opcodes.h \ @@ -492,13 +508,16 @@ $(ESP32_SIM)/Esp32forth-sim: \ # ---- ESP32 ---- esp32: esp32_target esp32_sim esp32_tests esp32_sim_tests -esp32_target: $(ESP32)/ESP32forth/ESP32forth.ino +esp32_target: $(ESP32)/ESP32forth.zip $(ESP32)/ESP32forth: mkdir -p $@ +$(ESP32)/ESP32forth/optional: + mkdir -p $@ + ESP32_PARTS = tools/replace.js \ - esp32/template.ino \ + esp32/ESP32forth.ino \ common/tier0_opcodes.h \ common/tier1_opcodes.h \ common/tier2_opcodes.h \ @@ -517,7 +536,7 @@ ESP32_PARTS = tools/replace.js \ $(GEN)/esp32_boot.h $(ESP32)/ESP32forth/ESP32forth.ino: $(ESP32_PARTS) | $(ESP32)/ESP32forth - cat esp32/template.ino | tools/replace.js \ + cat esp32/ESP32forth.ino | tools/replace.js \ VERSION=$(VERSION) \ REVISION=$(REVISION) \ tier0_opcodes=@common/tier0_opcodes.h \ @@ -538,6 +557,27 @@ $(ESP32)/ESP32forth/ESP32forth.ino: $(ESP32_PARTS) | $(ESP32)/ESP32forth boot=@$(GEN)/esp32_boot.h \ >$@ +$(ESP32)/ESP32forth/README.txt: esp32/README.txt | $(ESP32)/ESP32forth + cat esp32/README.txt | tools/replace.js \ + VERSION=$(VERSION) \ + REVISION=$(REVISION) \ + >$@ + +$(ESP32)/ESP32forth/optional/README-optional.txt: \ + esp32/README-optional.txt | $(ESP32)/ESP32forth/optional + cat esp32/README-optional.txt | tools/replace.js \ + VERSION=$(VERSION) \ + REVISION=$(REVISION) \ + >$@ + +$(ESP32)/ESP32forth/optional/assemblers.h: \ + esp32/assemblers.h $(GEN)/esp32_assemblers.h | $(ESP32)/ESP32forth/optional + cat esp32/assemblers.h | tools/replace.js \ + VERSION=$(VERSION) \ + REVISION=$(REVISION) \ + assemblers=@$(GEN)/esp32_assemblers.h \ + >$@ + # ---- ESP32 ARDUINO BUILD AND FLASH ---- ARDUINO_BUILDER="/mnt/c/Program Files (x86)/Arduino/arduino-builder.exe" @@ -623,9 +663,16 @@ CHIP_esp32cam=esp32 0xe000 ${ARDUINO_APP}/packages/esp32/hardware/esp32/2.0.5/tools/partitions/boot_app0.bin \ 0x10000 $(ESP32)/$(subst -flash,,$@)_build/ESP32forth.ino.bin +%-build: $(ESP32)/%_build/ESP32forth.ino.bin + echo "done" + # ---- PACKAGE ---- -$(ESP32)/ESP32forth.zip: $(ESP32)/ESP32forth/ESP32forth.ino +$(ESP32)/ESP32forth.zip: \ + $(ESP32)/ESP32forth/ESP32forth.ino \ + $(ESP32)/ESP32forth/README.txt \ + $(ESP32)/ESP32forth/optional/README-optional.txt \ + $(ESP32)/ESP32forth/optional/assemblers.h cd $(ESP32) && rm -f ESP32forth.zip && zip -r ESP32forth.zip ESP32forth # ---- Publish to Archive ---- diff --git a/common/forth_namespace_tests.fs b/common/forth_namespace_tests.fs index e3515a9..733b684 100644 --- a/common/forth_namespace_tests.fs +++ b/common/forth_namespace_tests.fs @@ -644,9 +644,6 @@ e: test-esp32-forth-voclist ;e e: check-esp32-platform - out: riscv-assembler - out: xtensa-assembler - out: assembler out: ok out: LED out: OUTPUT diff --git a/esp32/template.ino b/esp32/ESP32forth.ino similarity index 100% rename from esp32/template.ino rename to esp32/ESP32forth.ino diff --git a/esp32/README-optional.txt b/esp32/README-optional.txt new file mode 100644 index 0000000..8ef66e8 --- /dev/null +++ b/esp32/README-optional.txt @@ -0,0 +1,20 @@ ++----------------------------------+ +| ESP32forth - Optional Packages | ++----------------------------------+ + +ESPforth supports a number of optional packages, included in this directory. + +By default ESPforth will only include core functionality. +To include one or more of these modules, move them from this directory +into the parent directory, next to the ESPforth.ino file. + +These are the current optional modules: + * assemblers.h - Assemblers for ESP32 Xtensa and ESP32 RISC-V + +Initially ESP32forth focused on a minimal C kernel, with most functionality +built in Forth code loaded at boot. Eventually, as support for more capabilities +were added to ESPforth, this became unsustainable. + +Optional modules demonstrate good patterns for use in your own extensions +to ESP32forth. You can add you own modules by #including them from +an optional userwords.h file placed next to ESPforth.ino diff --git a/esp32/README.txt b/esp32/README.txt new file mode 100644 index 0000000..034ad25 --- /dev/null +++ b/esp32/README.txt @@ -0,0 +1,20 @@ ++--------------+ +| ESP32forth | ++--------------+ + +This is ESP32forth v{{VERSION}} (Revision {{REVISION}}). + +ESP32forth is an indirect threaded Forth for the ESP32 family of microcontrollers. +It uses a small C "kernel" that boots via inline Forth code. +The use of C allows developers to leverage C/C++ ESP32 libraries with minimal effort. + +To compile and flash with the Arduino tools, load ESP32forth.ino. + +Documentation and the latest version of ESP32forth are available at: +https://esp32forth.appspot.com/ + +Full unexpanded source code and an issue tracker are available at: +https://github.com/flagxor/ueforth + +There are several optional components that you can add into ESP32forth. +See: optional/README-optional.txt diff --git a/esp32/assemblers.h b/esp32/assemblers.h new file mode 100644 index 0000000..ae63305 --- /dev/null +++ b/esp32/assemblers.h @@ -0,0 +1,26 @@ +/* + * Copyright 2023 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. +*/ + +/* + * ESP32forth Assemblers v{{VERSION}} + * Revision: {{REVISION}} + */ + +{{assemblers}} + +#define OPTIONAL_ASSEMBLERS_SUPPORT \ + XV(internals, "assemblers-source", ASSEMBLERS_SOURCE, \ + PUSH assemblers_source; PUSH sizeof(assemblers_source)) diff --git a/esp32/builtins.h b/esp32/builtins.h index c8ebc43..8234713 100644 --- a/esp32/builtins.h +++ b/esp32/builtins.h @@ -22,19 +22,27 @@ # include # include -// Optional hook to pull in words for userwords.h +// Hook to pull in words from optional userwords.h # if __has_include("userwords.h") # include "userwords.h" # else # define USER_WORDS # endif +// Hook to pull in words from optional assemblers.h +# if __has_include("assemblers.h") +# include "assemblers.h" +# else +# define OPTIONAL_ASSEMBLERS_SUPPORT +# endif + static cell_t ResizeFile(cell_t fd, cell_t size); #endif #define PLATFORM_OPCODE_LIST \ USER_WORDS \ + OPTIONAL_ASSEMBLERS_SUPPORT \ REQUIRED_PLATFORM_SUPPORT \ REQUIRED_ESP_SUPPORT \ REQUIRED_MEMORY_SUPPORT \ diff --git a/esp32/optionals.fs b/esp32/optionals.fs new file mode 100644 index 0000000..1de43eb --- /dev/null +++ b/esp32/optionals.fs @@ -0,0 +1,19 @@ +\ Copyright 2023 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. + +internals + +DEFINED? assemblers-source [IF] assemblers-source evaluate [THEN] + +forth diff --git a/esp32/print-builtins.cpp b/esp32/print-builtins.cpp index 3415d09..b8718cf 100644 --- a/esp32/print-builtins.cpp +++ b/esp32/print-builtins.cpp @@ -23,6 +23,7 @@ #define CALLING_OPCODE_LIST #define FLOATING_POINT_LIST #define USER_WORDS +#define OPTIONAL_ASSEMBLERS_SUPPORT #include "builtins.h" #define XV(flags, name, op, code) Z(flags, name, op, code)