From c07be3978a76b7f946479e708e540435d541aa68 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Thu, 14 Jul 2022 15:15:14 -0700 Subject: [PATCH] Shows text is page. --- web/fini.fs | 38 +++++++++++++++++++++++++++++++++++++- web/web.template.js | 13 ++++--------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/web/fini.fs b/web/fini.fs index a8b666a..9ce5f7d 100644 --- a/web/fini.fs +++ b/web/fini.fs @@ -19,7 +19,43 @@ forth definitions internals ( Bring a forth to the top of the vocabulary. ) : ok ." uEforth" raw-ok ; -: web-type 0 call ; ' web-type is type +: jseval! ( a n index -- ) 0 call ; + +r| +(function(sp) { + var n = i32[sp>>2]; sp -= 4; + var a = i32[sp>>2]; sp -= 4; + var text = GetString(a, n); + eval(text); + return sp; +}) +| 2 jseval! +: jseval ( a n -- ) 2 call ; + +r| + if (!globalObj['write']) { + var console = document.createElement('pre'); + console.id = 'console'; + document.body.appendChild(console); + } +| jseval + +r| +(function(sp) { + var n = i32[sp>>2]; sp -= 4; + var a = i32[sp>>2]; sp -= 4; + var text = GetString(a, n); + if (globalObj['write']) { + write(text); + } else { + var console = document.getElementById('console'); + console.innerText += text.replace(/[\r]/g, ''); + } + return sp; +}) +| 1 jseval! + +: web-type 1 call ; ' web-type is type : web-key yield 0 ; ' web-key is key : web-key? yield 0 ; ' web-key? is key? diff --git a/web/web.template.js b/web/web.template.js index 952f16d..2a0306d 100644 --- a/web/web.template.js +++ b/web/web.template.js @@ -36,20 +36,15 @@ var u16 = new Uint16Array(heap); var u8 = new Uint8Array(heap); var builtins = []; var opcodes = {}; -var objects = [Type, Eval]; +var objects = [SetEval]; {{sys}} -function Type(sp) { +function SetEval(sp) { + var index = i32[sp>>2]; sp -= 4; var n = i32[sp>>2]; sp -= 4; var a = i32[sp>>2]; sp -= 4; - console.log(GetString(a, n)); -} - -function Eval(sp) { - var n = i32[sp>>2]; sp -= 4; - var a = i32[sp>>2]; sp -= 4; - eval(GetString(a, n)); + objects[index] = eval(GetString(a, n)); } function Call(sp) {