From b7485d8ea9301af1800e351ffdd336fda5376991 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sun, 30 Jan 2022 20:02:53 -0800 Subject: [PATCH] Unify replacement. --- ueforth/Makefile | 17 ++++++++++--- ueforth/common/replace.js | 12 ++++----- ueforth/esp32/fuse_ino.js | 52 --------------------------------------- 3 files changed, 18 insertions(+), 63 deletions(-) delete mode 100755 ueforth/esp32/fuse_ino.js diff --git a/ueforth/Makefile b/ueforth/Makefile index 23378a5..8c03f34 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -306,7 +306,8 @@ $(WINDOWS)/uEf64.exe: \ $(ESP32)/ESP32forth: mkdir -p $@ -ESP32_PARTS = esp32/template.ino \ +ESP32_PARTS = common/replace.js \ + esp32/template.ino \ common/opcodes.h \ common/calling.h \ common/floats.h \ @@ -314,9 +315,17 @@ ESP32_PARTS = esp32/template.ino \ common/interp.h \ $(GEN)/esp32_boot.h -$(ESP32)/ESP32forth/ESP32forth.ino: \ - esp32/fuse_ino.js $(ESP32_PARTS) | $(ESP32)/ESP32forth - $< $(VERSION) $(REVISION) $(ESP32_PARTS) >$@ +$(ESP32)/ESP32forth/ESP32forth.ino: $(ESP32_PARTS) | $(ESP32)/ESP32forth + cat esp32/template.ino | common/replace.js \ + VERSION=$(VERSION) \ + REVISION=$(REVISION) \ + opcodes=@common/opcodes.h \ + calling=@common/calling.h \ + floats=@common/floats.h \ + core=@common/core.h \ + interp=@common/interp.h \ + boot=@$(GEN)/esp32_boot.h \ + >$@ # ---- PACKAGE ---- diff --git a/ueforth/common/replace.js b/ueforth/common/replace.js index 61c9cbe..51c0d44 100644 --- a/ueforth/common/replace.js +++ b/ueforth/common/replace.js @@ -43,25 +43,23 @@ for (var i = 2; i < process.argv.length; ++i) { var m = item.match(/^([^=]+)=@(.+)$/); if (m) { var content = DropCopyright(fs.readFileSync(m[2]).toString()); - replacements.push([m[1], content]); + replacements.push(['{{' + m[1] + '}}', content]); continue; } var m = item.match(/^([^=]+)=(.+)$/); if (m) { - replacements.push([m[1], m[2]]); + replacements.push(['{{' + m[1] + '}}', m[2]]); continue; } throw 'Bad replacement ' + item; } - -var version = process.argv[3]; -var revision = process.argv[4]; for (;;) { var old_source = source; for (var i = 0; i < replacements.length; ++i) { - source = source.replace('{{' + replacements[i][0] + '}}', - replacements[i][1]); + source = source.replace( + replacements[i][0], + function() { return replacements[i][1]}); } if (old_source == source) { break; diff --git a/ueforth/esp32/fuse_ino.js b/ueforth/esp32/fuse_ino.js deleted file mode 100755 index 776d693..0000000 --- a/ueforth/esp32/fuse_ino.js +++ /dev/null @@ -1,52 +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 version = process.argv[2]; -var revision = process.argv[3]; -var code = fs.readFileSync(process.argv[4]).toString(); -var opcodes = DropCopyright(fs.readFileSync(process.argv[5]).toString()); -var calling = DropCopyright(fs.readFileSync(process.argv[6]).toString()); -var floats = DropCopyright(fs.readFileSync(process.argv[7]).toString()); -var core = DropCopyright(fs.readFileSync(process.argv[8]).toString()); -var interp = DropCopyright(fs.readFileSync(process.argv[9]).toString()); -var boot = DropCopyright(fs.readFileSync(process.argv[10]).toString()); - -code = code.replace('{{VERSION}}', function() { return version; }); -code = code.replace('{{REVISION}}', function() { return revision; }); -code = code.replace('{{opcodes}}', function() { return opcodes; }); -code = code.replace('{{floats}}', function() { return floats; }); -code = code.replace('{{calling}}', function() { return calling; }); -code = code.replace('{{boot}}', function() { return boot; }); -code = code.replace('{{core}}', function() { return core; }); -code = code.replace('{{interp}}', function() { return interp; }); - -process.stdout.write(code);