From 0490253fa93f5f50ed029235ba09fdadee9fe571 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sat, 2 Jan 2021 00:37:18 -0800 Subject: [PATCH] Builds again for posix. --- ueforth/Makefile | 26 ++++++++++++++++--------- ueforth/arduino/arduino.template.ino | 3 +-- ueforth/arduino/fuse_ino.js | 19 +++--------------- ueforth/{ => common}/boot.fs | 0 ueforth/{ => common}/core.h | 0 ueforth/{ => common}/opcodes.h | 0 ueforth/common/source_to_string.js | 15 ++++++++++++++ ueforth/posix/{posix.c => posix_main.c} | 8 +++++--- ueforth/web/dump_web_opcodes.c | 2 +- 9 files changed, 42 insertions(+), 31 deletions(-) rename ueforth/{ => common}/boot.fs (100%) rename ueforth/{ => common}/core.h (100%) rename ueforth/{ => common}/opcodes.h (100%) create mode 100755 ueforth/common/source_to_string.js rename ueforth/posix/{posix.c => posix_main.c} (90%) diff --git a/ueforth/Makefile b/ueforth/Makefile index 1593db9..b6f0922 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -1,4 +1,4 @@ -CFLAGS=-O2 -Wall -Werror -I./ +CFLAGS=-O2 -Wall -Werror -I./ -I./out LIBS=-ldl TARGETS = out/web/terminal.html \ @@ -11,7 +11,10 @@ all: $(TARGETS) out/gen: mkdir -p out/gen -out/gen/dump_web_opcodes: web/dump_web_opcodes.c opcodes.h | out/gen +out/gen/boot.h: common/source_to_string.js common/boot.fs | out/gen + $^ boot >$@ + +out/gen/dump_web_opcodes: web/dump_web_opcodes.c common/opcodes.h | out/gen $(CC) $(CFLAGS) $< -o $@ out/gen/web_cases.js: out/gen/dump_web_opcodes | out/gen @@ -26,24 +29,29 @@ out/web: out/web/terminal.html: web/terminal.html | out/web cp $< $@ -out/web/ueforth.js: web/fuse_web.js web/web.template.js boot.fs \ - out/gen/web_dict.js out/gen/web_cases.js | out/web +out/web/ueforth.js: \ + web/fuse_web.js \ + web/web.template.js \ + out/gen/boot.h \ + out/gen/web_dict.js \ + out/gen/web_cases.js | out/web $^ >$@ out/posix: mkdir -p out/posix -out/posix/ueforth: posix/posix.c opcodes.h | out/posix +out/posix/ueforth: posix/posix_main.c common/opcodes.h | out/posix $(CC) $(CFLAGS) $< -o $@ $(LIBS) out/arduino: mkdir -p out/arduino -out/arduino/ueforth.ino: arduino/fuse_ino.js \ +out/arduino/ueforth.ino: \ + arduino/fuse_ino.js \ arduino/arduino.template.ino \ - opcodes.h \ - core.h \ - boot.fs | out/arduino + common/opcodes.h \ + common/core.h \ + out/gen/boot.h | out/arduino $^ >$@ clean: diff --git a/ueforth/arduino/arduino.template.ino b/ueforth/arduino/arduino.template.ino index 032381a..c2d60a5 100644 --- a/ueforth/arduino/arduino.template.ino +++ b/ueforth/arduino/arduino.template.ino @@ -1,7 +1,6 @@ {{opcodes}} {{core}} -const char boot[] = -{{boot}}; +{{boot}} void setup() { ueforth(boot, sizeof(boot)); diff --git a/ueforth/arduino/fuse_ino.js b/ueforth/arduino/fuse_ino.js index 14ab72d..cf4833a 100755 --- a/ueforth/arduino/fuse_ino.js +++ b/ueforth/arduino/fuse_ino.js @@ -1,27 +1,14 @@ #! /usr/bin/env nodejs var fs = require('fs'); + var code = fs.readFileSync(process.argv[2]).toString(); var opcodes = fs.readFileSync(process.argv[3]).toString(); var core = fs.readFileSync(process.argv[4]).toString(); var boot = fs.readFileSync(process.argv[5]).toString(); -function ReplaceAll(haystack, needle, replacement) { - for (;;) { - var old = haystack; - haystack = haystack.replace(needle, replacement); - if (old === haystack) { - return haystack; - } - } -} - -boot = boot.replace(/["]/g, '\\"'); -boot = '" ' + boot.split('\n').join(' "\n" ') + ' "'; -boot = boot.replace(/["] ["]/g, ''); -boot = boot.replace(/["] [(] ([^)]*)[)] ["]/g, '// $1'); -code = code.replace('{{boot}}', boot); code = code.replace('{{opcodes}}', opcodes); +code = code.replace('{{boot}}', boot); code = code.replace('{{core}}', core); -console.log(code); +process.stdout.write(code); diff --git a/ueforth/boot.fs b/ueforth/common/boot.fs similarity index 100% rename from ueforth/boot.fs rename to ueforth/common/boot.fs diff --git a/ueforth/core.h b/ueforth/common/core.h similarity index 100% rename from ueforth/core.h rename to ueforth/common/core.h diff --git a/ueforth/opcodes.h b/ueforth/common/opcodes.h similarity index 100% rename from ueforth/opcodes.h rename to ueforth/common/opcodes.h diff --git a/ueforth/common/source_to_string.js b/ueforth/common/source_to_string.js new file mode 100755 index 0000000..27db95a --- /dev/null +++ b/ueforth/common/source_to_string.js @@ -0,0 +1,15 @@ +#! /usr/bin/env nodejs + +var fs = require('fs'); + +var source = fs.readFileSync(process.argv[2]).toString(); +var name = process.argv[3]; + +source = source.replace(/["]/g, '\\"'); +source = '" ' + source.split('\n').join(' "\n" ') + ' "'; +source = source.replace(/["] ["]/g, ''); +source = source.replace(/["] [(] ([^)]*)[)] ["]/g, '// $1'); + +source = 'const char ' + name + '[] =\n' + source + ';\n'; + +process.stdout.write(source); diff --git a/ueforth/posix/posix.c b/ueforth/posix/posix_main.c similarity index 90% rename from ueforth/posix/posix.c rename to ueforth/posix/posix_main.c index 2dd1772..2734670 100644 --- a/ueforth/posix/posix.c +++ b/ueforth/posix/posix_main.c @@ -1,7 +1,7 @@ #include #include -#include "opcodes.h" +#include "common/opcodes.h" #define HEAP_SIZE (10 * 1024 * 1024) #define STACK_SIZE (16 * 1024) @@ -19,8 +19,10 @@ X("KEY", OP_KEY, DUP; tos = fgetc(stdin)) \ X("SYSEXIT", OP_SYSEXIT, DUP; exit(tos)) \ -#include "core.h" +#include "common/core.h" + +#include "gen/boot.h" int main(int argc, char *argv[]) { - ueforth(0, 0); + ueforth(boot, sizeof(boot)); } diff --git a/ueforth/web/dump_web_opcodes.c b/ueforth/web/dump_web_opcodes.c index 62ddb69..5141191 100644 --- a/ueforth/web/dump_web_opcodes.c +++ b/ueforth/web/dump_web_opcodes.c @@ -1,7 +1,7 @@ #include #include -#include "opcodes.h" +#include "common/opcodes.h" #define PLATFORM_OPCODE_LIST \ X("CALL", OP_CALL, sp = jscall(sp, tos); DROP) \