From d2c62a35b9ffbb6275cd994373e5de3873ccb953 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Mon, 20 Feb 2023 18:11:45 -0800 Subject: [PATCH] Make it possible to defer start, boost web memory. --- Makefile | 5 ++++- web/lazy_terminal.html | 27 +++++++++++++++++++++++++++ web/web.template.js | 23 +++++++++++++++++------ 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 web/lazy_terminal.html diff --git a/Makefile b/Makefile index 58872d8..ab100a4 100644 --- a/Makefile +++ b/Makefile @@ -346,7 +346,7 @@ $(RES)/ueforth_res64.res: windows/ueforth.rc $(RES)/eforth.ico # ---- WEB ---- web: web_target web_tests -web_target: $(WEB)/terminal.html $(WEB)/ueforth.js +web_target: $(WEB)/terminal.html $(WEB)/lazy_terminal.html $(WEB)/ueforth.js $(WEB): mkdir -p $(WEB) @@ -354,6 +354,9 @@ $(WEB): $(WEB)/terminal.html: web/terminal.html | $(WEB) cp $< $@ +$(WEB)/lazy_terminal.html: web/lazy_terminal.html | $(WEB) + cp $< $@ + $(WEB)/ueforth.js: \ web/fuse_web.js \ web/web.template.js \ diff --git a/web/lazy_terminal.html b/web/lazy_terminal.html new file mode 100644 index 0000000..61929cd --- /dev/null +++ b/web/lazy_terminal.html @@ -0,0 +1,27 @@ + + + + + diff --git a/web/web.template.js b/web/web.template.js index d049685..c526ca0 100644 --- a/web/web.template.js +++ b/web/web.template.js @@ -16,7 +16,7 @@ (function() { -const HEAP_SIZE = (1024 * 1024); +const HEAP_SIZE = (4 * 1024 * 1024); const STACK_CELLS = 4096; const VOCABULARY_DEPTH = 16; @@ -601,18 +601,29 @@ function getGlobalObj() { var globalObj = getGlobalObj(); var module = VM(globalObj, ffi, heap); + function run() { module.run(); setTimeout(run, 0); } -if (globalObj.write) { + +function Start() { Init(); setTimeout(run, 0); +} + +if (globalObj.write) { + Start(); } else { - window.addEventListener('load', function() { - Init(); - setTimeout(run, 0); - }); + if (globalObj.ueforth === null) { + globalObj.ueforth = context; + context.Start = Start; + } else { + window.addEventListener('load', function() { + Init(); + setTimeout(run, 0); + }); + } } })();