diff --git a/Makefile b/Makefile index 5f92fce..6354096 100644 --- a/Makefile +++ b/Makefile @@ -239,107 +239,96 @@ sanity_test_web: $(WEB)/ueforth.js $(GEN): mkdir -p $@ -$(GEN)/posix_boot_merged.fs: posix/posix_boot.fs | $(GEN) +$(GEN)/posix_boot.h: posix/posix_boot.fs | $(GEN) ./tools/importation.py $< $@ \ - -I . -I $(GEN) --depsout $@.dd \ + -I . -I $(GEN) --name boot --header cpp --depsout $@.dd \ --set-version $(VERSION) \ --set-revision $(REVISION) --include $(GEN)/posix_boot_merged.fs.dd +-include $(GEN)/posix_boot.h.dd -$(GEN)/posix_boot.h: tools/source_to_string.js $(GEN)/posix_boot_merged.fs | $(GEN) - $< boot $(VERSION) $(REVISION) $(GEN)/posix_boot_merged.fs >$@ - -$(GEN)/windows_boot_extra_merged.fs: windows/windows_boot_extra.fs | $(GEN) +$(GEN)/windows_boot_extra.h: windows/windows_boot_extra.fs | $(GEN) ./tools/importation.py $< $@ \ - -I . -I $(GEN) --depsout $@.dd \ + -I . -I $(GEN) --name boot_extra --header win --depsout $@.dd \ --set-version $(VERSION) \ --set-revision $(REVISION) --include $(GEN)/windows_boot_extra_merged.fs.dd +-include $(GEN)/windows_boot_extra.h.dd -$(GEN)/windows_boot_extra.h: tools/source_to_string.js $(GEN)/windows_boot_extra_merged.fs | $(GEN) - $< -win boot_extra $(VERSION) $(REVISION) $(GEN)/windows_boot_extra_merged.fs >$@ - -$(GEN)/windows_boot_merged.fs: windows/windows_boot.fs | $(GEN) - ./tools/importation.py $^ $@ \ - -I . -I $(GEN) --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) --include $(GEN)/windows_boot_merged.fs.dd - -$(GEN)/windows_boot.h: tools/source_to_string.js $(GEN)/windows_boot_merged.fs | $(GEN) - $< -win boot $(VERSION) $(REVISION) $(GEN)/windows_boot_merged.fs >$@ - -$(GEN)/pico_ice_boot_merged.fs: pico-ice/pico_ice_boot.fs | $(GEN) - ./tools/importation.py $^ $@ \ - -I . -I $(GEN) --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) --include $(GEN)/pico_ice_boot_merged.fs.dd - -$(GEN)/pico_ice_boot.h: tools/source_to_string.js $(GEN)/pico_ice_boot_merged.fs | $(GEN) - $< boot $(VERSION) $(REVISION) $(GEN)/pico_ice_boot_merged.fs >$@ - -$(GEN)/esp32_boot_merged.fs: esp32/esp32_boot.fs | $(GEN) +$(GEN)/windows_boot.h: windows/windows_boot.fs | $(GEN) ./tools/importation.py $< $@ \ - -I . -I $(GEN) --depsout $@.dd \ + -I . -I $(GEN) --name boot --header win --depsout $@.dd \ --set-version $(VERSION) \ --set-revision $(REVISION) --include $(GEN)/esp32_boot_merged.fs.dd +-include $(GEN)/windows_boot.h.dd -$(GEN)/esp32_boot.h: tools/source_to_string.js $(GEN)/esp32_boot_merged.fs | $(GEN) - $< boot $(VERSION) $(REVISION) $(GEN)/esp32_boot_merged.fs >$@ +$(GEN)/pico_ice_boot.h: pico-ice/pico_ice_boot.fs | $(GEN) + ./tools/importation.py $< $@ \ + -I . -I $(GEN) --name boot --header cpp --depsout $@.dd \ + --set-version $(VERSION) \ + --set-revision $(REVISION) +-include $(GEN)/pico_ice_boot.h.dd -$(GEN)/esp32_assembler.h: \ - tools/source_to_string.js \ - common/assembler.fs | $(GEN) - $< assembler_source $(VERSION) $(REVISION) \ - common/assembler.fs >$@ +$(GEN)/esp32_boot.h: esp32/esp32_boot.fs | $(GEN) + ./tools/importation.py $< $@ \ + -I . -I $(GEN) --name boot --header cpp --depsout $@.dd \ + --set-version $(VERSION) \ + --set-revision $(REVISION) +-include $(GEN)/esp32_boot.h.dd -$(GEN)/esp32_xtensa-assembler.h: \ - tools/source_to_string.js \ - esp32/optional/assemblers/xtensa-assembler.fs | $(GEN) - $< xtensa_assembler_source $(VERSION) $(REVISION) \ - esp32/optional/assemblers/xtensa-assembler.fs >$@ +$(GEN)/esp32_assembler.h: common/assembler.fs | $(GEN) + ./tools/importation.py $< $@ \ + -I . -I $(GEN) --name assembler_source --header cpp --depsout $@.dd \ + --set-version $(VERSION) \ + --set-revision $(REVISION) +-include $(GEN)/esp32_assembler.h.dd -$(GEN)/esp32_riscv-assembler.h: \ - tools/source_to_string.js \ - esp32/optional/assemblers/riscv-assembler.fs | $(GEN) - $< riscv_assembler_source $(VERSION) $(REVISION) \ - esp32/optional/assemblers/riscv-assembler.fs >$@ +$(GEN)/esp32_xtensa-assembler.h: esp32/optional/assemblers/xtensa-assembler.fs | $(GEN) + ./tools/importation.py $< $@ \ + -I . -I $(GEN) --name xtensa_assembler_source --header cpp --depsout $@.dd \ + --set-version $(VERSION) \ + --set-revision $(REVISION) +-include $(GEN)/esp32_xtensa-assembler.h.dd -$(GEN)/esp32_camera.h: \ - tools/source_to_string.js \ - esp32/optional/camera/camera_server.fs \ - esp32/optional/camera/camera.fs | $(GEN) - $< camera_source $(VERSION) $(REVISION) \ - esp32/optional/camera/camera.fs \ - esp32/optional/camera/camera_server.fs >$@ +$(GEN)/esp32_riscv-assembler.h: esp32/optional/assemblers/riscv-assembler.fs | $(GEN) + ./tools/importation.py $< $@ \ + -I . -I $(GEN) --name riscv_assembler_source --header cpp --depsout $@.dd \ + --set-version $(VERSION) \ + --set-revision $(REVISION) +-include $(GEN)/esp32_riscv-assembler.h.dd -$(GEN)/esp32_interrupts.h: \ - tools/source_to_string.js \ - esp32/optional/interrupts/interrupts.fs \ - esp32/optional/interrupts/timers.fs | $(GEN) - $< interrupts_source $(VERSION) $(REVISION) \ - esp32/optional/interrupts/interrupts.fs \ - esp32/optional/interrupts/timers.fs >$@ +$(GEN)/esp32_camera.h: esp32/optional/camera/camera_server.fs | $(GEN) + ./tools/importation.py $< $@ \ + -I . -I $(GEN) --name camera_source --header cpp --depsout $@.dd \ + --set-version $(VERSION) \ + --set-revision $(REVISION) +-include $(GEN)/esp32_camera.h.dd -$(GEN)/esp32_oled.h: \ - tools/source_to_string.js esp32/optional/oled/oled.fs | $(GEN) - $< oled_source $(VERSION) $(REVISION) \ - esp32/optional/oled/oled.fs >$@ +$(GEN)/esp32_interrupts.h: esp32/optional/interrupts/timers.fs | $(GEN) + ./tools/importation.py $< $@ \ + -I . -I $(GEN) --name interrupts_source --header cpp --depsout $@.dd \ + --set-version $(VERSION) \ + --set-revision $(REVISION) +-include $(GEN)/esp32_interrupts.h.dd -$(GEN)/esp32_spi-flash.h: \ - tools/source_to_string.js esp32/optional/spi-flash/spi-flash.fs | $(GEN) - $< spi_flash_source $(VERSION) $(REVISION) \ - esp32/optional/spi-flash/spi-flash.fs >$@ +$(GEN)/esp32_oled.h: esp32/optional/oled/oled.fs | $(GEN) + ./tools/importation.py $< $@ \ + -I . -I $(GEN) --name oled_source --header cpp --depsout $@.dd \ + --set-version $(VERSION) \ + --set-revision $(REVISION) +-include $(GEN)/esp32_oled.h.dd -$(GEN)/esp32_serial-bluetooth.h: \ - tools/source_to_string.js \ - esp32/optional/serial-bluetooth/bterm.fs \ - esp32/optional/serial-bluetooth/serial-bluetooth.fs | $(GEN) - $< serial_bluetooth_source $(VERSION) $(REVISION) \ - esp32/optional/serial-bluetooth/serial-bluetooth.fs \ - esp32/optional/serial-bluetooth/bterm.fs >$@ +$(GEN)/esp32_spi-flash.h: esp32/optional/spi-flash/spi-flash.fs | $(GEN) + ./tools/importation.py $< $@ \ + -I . -I $(GEN) --name spi_flash_source --header cpp --depsout $@.dd \ + --set-version $(VERSION) \ + --set-revision $(REVISION) +-include $(GEN)/esp32_spi-flash.h.dd + +$(GEN)/esp32_serial-bluetooth.h: esp32/optional/serial-bluetooth/serial-bluetooth.fs | $(GEN) + ./tools/importation.py $< $@ \ + -I . -I $(GEN) --name serial_blueooth_source --header cpp --depsout $@.dd \ + --set-version $(VERSION) \ + --set-revision $(REVISION) +-include $(GEN)/esp32_serial-bluetooth.h.dd OPTIONAL_MODULES = \ $(ESP32)/ESP32forth/assemblers.h \ @@ -371,15 +360,12 @@ $(GEN)/web_dict.js: $(GEN)/dump_web_opcodes | $(GEN) $(GEN)/web_sys.js: $(GEN)/dump_web_opcodes | $(GEN) $< sys >$@ -$(GEN)/web_boot_merged.fs: web/web_boot.fs | $(GEN) - ./tools/importation.py $^ $@ \ - -I . -I $(GEN) --depsout $@.dd \ +$(GEN)/web_boot.js: web/web_boot.fs | $(GEN) + ./tools/importation.py $< $@ \ + -I . -I $(GEN) --name boot --header web --depsout $@.dd \ --set-version $(VERSION) \ --set-revision $(REVISION) --include $(GEN)/web_boot_merged.fs.dd - -$(GEN)/web_boot.js: tools/source_to_string.js $(GEN)/web_boot_merged.fs | $(GEN) - $< -web boot $(VERSION) $(REVISION) $(GEN)/web_boot_merged.fs >$@ +-include $(GEN)/web_boot.js.dd # ---- RESOURCES ---- diff --git a/esp32/optional/camera/camera_server.fs b/esp32/optional/camera/camera_server.fs index 54f9f4b..6504d61 100644 --- a/esp32/optional/camera/camera_server.fs +++ b/esp32/optional/camera/camera_server.fs @@ -12,6 +12,8 @@ \ See the License for the specific language governing permissions and \ limitations under the License. +needs camera.fs + ( Lazy loaded Camera Server ) : camera-server r~ diff --git a/esp32/optional/interrupts/timers.fs b/esp32/optional/interrupts/timers.fs index d442d48..ec2b9ad 100644 --- a/esp32/optional/interrupts/timers.fs +++ b/esp32/optional/interrupts/timers.fs @@ -12,6 +12,8 @@ \ See the License for the specific language governing permissions and \ limitations under the License. +needs interrupts.fs + internals definitions transfer timers-builtins forth definitions diff --git a/esp32/optional/serial-bluetooth/serial-bluetooth.fs b/esp32/optional/serial-bluetooth/serial-bluetooth.fs index c032367..1a684bd 100644 --- a/esp32/optional/serial-bluetooth/serial-bluetooth.fs +++ b/esp32/optional/serial-bluetooth/serial-bluetooth.fs @@ -12,6 +12,8 @@ \ See the License for the specific language governing permissions and \ limitations under the License. +needs bterm.fs + DEFINED? SerialBT.new [IF] vocabulary bluetooth bluetooth definitions transfer bluetooth-builtins diff --git a/tools/configure.py b/tools/configure.py index 9572125..d7e63ef 100755 --- a/tools/configure.py +++ b/tools/configure.py @@ -94,14 +94,10 @@ rule mkdir description = mkdir command = mkdir -p $out -rule source_to_string - description = source_to_string - command = ../tools/source_to_string.js $name $version $revision $in >$out - rule importation - description = import + description = importation depfile = $out.dd - command = ../tools/importation.py $in $out -I . -I .. --depsout $out.dd --set-version $version --set-revision $revision + command = ../tools/importation.py $in $out -I . -I .. --name $name --header $header_mode --depsout $out.dd --set-version $version --set-revision $revision build gen: mkdir @@ -113,23 +109,20 @@ build gen: mkdir 'libs': ' '.join(LIBS), } -def ForthHeader(target, name, source): +def ForthHeader(target, name, source, header_mode='cpp'): + source = '../' + source global output - output += """ -build %(target)s: source_to_string %(target)s.merged | gen - name = %(name)s - -build %(target)s.merged: importation %(source)s | gen -""" % { - 'target': target, - 'source': os.path.join('..', source), - 'name': name, - } + output += f""" +build {target}: importation {source} | gen + name = {name} + header_mode = {header_mode} +""" ForthHeader('gen/posix_boot.h', 'boot', 'posix/posix_boot.fs') -ForthHeader('gen/window_boot.h', 'boot', 'windows/windows_boot.fs') -ForthHeader('gen/window_boot_extra.h', 'boot_extra', 'windows/windows_boot_extra.fs') +ForthHeader('gen/window_boot.h', 'boot', 'windows/windows_boot.fs', header_mode='win') +ForthHeader('gen/window_boot_extra.h', 'boot_extra', 'windows/windows_boot_extra.fs', header_mode='win') ForthHeader('gen/pico_ice_boot.h', 'boot', 'pico-ice/pico_ice_boot.fs') ForthHeader('gen/esp32_boot.h', 'boot', 'esp32/esp32_boot.fs') +ForthHeader('gen/web_boot.js', 'boot', 'esp32/esp32_boot.fs', header_mode='web') print(output) diff --git a/tools/importation.py b/tools/importation.py index 03ad8de..0f9a2e5 100755 --- a/tools/importation.py +++ b/tools/importation.py @@ -15,6 +15,8 @@ parser.add_argument('--set-revision') parser.add_argument('--depsout') parser.add_argument('--no-out', action='store_true') parser.add_argument('--keep-first-comment', action='store_true') +parser.add_argument('--name') +parser.add_argument('--header') args = parser.parse_args() bases = args.I or [] @@ -88,6 +90,25 @@ def Process(): # Emit expanded file. if not args.no_out: with open(args.output, 'w') as fh: - fh.write('\n'.join(output) + '\n') + if args.header == 'web': + fh.write('const ' + args.name + ' = `\n' + + '\n'.join(output) + '\n`;\n') + elif args.header == 'cpp': + fh.write('const char ' + args.name + '[] = R"""(\n' + + '\n'.join(output) + '\n)""";\n') + elif args.header == 'win': + fixed = [] + for line in output: + line = line.replace('\\', '\\\\') + line = line.replace('"', '\\"') + line = '"' + line + '\\n"' + if line.startswith('"(') and line.endswith(')\\n"'): + line = '// ' + line + if line: + fixed.append(line) + fh.write('const char ' + args.name + '[] =\n' + + '\n'.join(fixed) + '\n;\n') + else: + fh.write('\n'.join(output) + '\n') Process() diff --git a/tools/source_to_string.js b/tools/source_to_string.js deleted file mode 100755 index e10415e..0000000 --- a/tools/source_to_string.js +++ /dev/null @@ -1,69 +0,0 @@ -#! /usr/bin/env nodejs -// Copyright 2021 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. - -var fs = require('fs'); - -function DropCopyright(source) { - var lines = source.split('\n'); - var cleaned = []; - for (var i = 0; i < lines.length; ++i) { - if (lines[i].search('Copyright') >= 0) { - while (lines[i] != '') { - ++i; - } - } else { - cleaned.push(lines[i]); - } - } - return cleaned.join('\n'); -} - -var is_windows = false; -var is_web = false; - -var args = process.argv.slice(2); -if (args.length > 0 && args[0] == '-win') { - is_windows = true; - args.shift(); -} -if (args.length > 0 && args[0] == '-web') { - is_web = true; - args.shift(); -} -var name = args.shift(); -var version = args.shift(); -var revision = args.shift(); -var source = ''; -while (args.length > 0) { - source += DropCopyright(fs.readFileSync(args.shift()).toString()); -} - -source = source.replace('{{VERSION}}', version); -source = source.replace('{{REVISION}}', revision); - -if (is_windows) { - source = source.replace(/\\/g, '\\\\'); - source = source.replace(/["]/g, '\\"'); - source = '"' + source.split('\n').join('\\n"\n"') + '\\n"'; - source = source.replace(/["] ["]/g, ''); - source = source.replace(/["] [(] ([^)]*)[)] ["]/g, '// $1'); - source = 'const char ' + name + '[] =\n' + source + ';\n'; -} else if (is_web) { - source = 'const ' + name + ' = `\n' + source + '`;\n'; -} else { - source = 'const char ' + name + '[] = R"""(\n' + source + ')""";\n'; -} - -process.stdout.write(source);