Make it possible to defer start, boost web memory.

This commit is contained in:
Brad Nelson
2023-02-20 18:11:45 -08:00
parent 5a40463464
commit d2c62a35b9
3 changed files with 48 additions and 7 deletions

View File

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

27
web/lazy_terminal.html Normal file
View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<!--
Copyright 2022 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.
-->
<script>
var ueforth = null;
window.onload = function() {
window.onclick = function() {
window.onclick = null;
ueforth.Start();
};
};
</script>
<script src="ueforth.js"></script>

View File

@ -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 {
if (globalObj.ueforth === null) {
globalObj.ueforth = context;
context.Start = Start;
} else {
window.addEventListener('load', function() {
Init();
setTimeout(run, 0);
});
}
}
})();