waforth2c: Improve table initialization

This commit is contained in:
Remko Tronçon 2019-03-09 10:19:47 +01:00
parent 93e3591205
commit d42b6d578c
2 changed files with 12 additions and 5 deletions

View file

@ -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)

View file

@ -113,12 +113,18 @@ WebAssembly.instantiate(coreWasm, {
"#undef WASM_RT_MODULE_PREFIX"
];
const init = [
"#include <memory.h>",
'#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 = [];