From d42b6d578cf67a675fcb5359e5b0dd4e30c8dbbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 9 Mar 2019 10:19:47 +0100 Subject: [PATCH] waforth2c: Improve table initialization --- experiments/waforth2c/Makefile | 3 ++- experiments/waforth2c/waforth2c.js | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/experiments/waforth2c/Makefile b/experiments/waforth2c/Makefile index 44f7ef9..f82f3c5 100644 --- a/experiments/waforth2c/Makefile +++ b/experiments/waforth2c/Makefile @@ -1,5 +1,6 @@ CFLAGS= CPPFLAGS=-I. -Iwaforth.gen -Iwasm2c +LINKFLAGS=-g .DEFAULT_GOAL := all @@ -17,7 +18,7 @@ example: ./main main: $(OBJECTS) - $(CC) -o $@ $(OBJECTS) + $(CC) $(LINKFLAGS) -o $@ $(OBJECTS) clean: -rm -rf $(OBJECTS) waforth_core.c waforth_core.h main $(WAFORTH_MODULE_HEADERS) $(WAFORTH_MODULE_SOURCES) diff --git a/experiments/waforth2c/waforth2c.js b/experiments/waforth2c/waforth2c.js index d5d3c6f..9545343 100755 --- a/experiments/waforth2c/waforth2c.js +++ b/experiments/waforth2c/waforth2c.js @@ -113,12 +113,18 @@ WebAssembly.instantiate(coreWasm, { "#undef WASM_RT_MODULE_PREFIX" ]; const init = [ + "#include ", '#include "waforth_modules.h"', - "void waforth_modules_init() {" + "static const u8 dictionary[] = { " + + Array.from(memory8.slice(dictionaryStart, savedHere)).join(", ") + + " };", + "void waforth_modules_init() {", + "memcpy(&Z_envZ_memory->data[" + + dictionaryStart + + "], dictionary, " + + (savedHere - dictionaryStart) + + ");" ]; - for (let i = dictionaryStart; i < savedHere; ++i) { - init.push("Z_envZ_memory->data[" + i + "] = " + memory8[i] + ";\n"); - } const objects = ["waforth.gen/waforth_modules.o"]; const moduleHeaders = []; const moduleSources = [];