From 86606391c738c5b9022f3bf3c1fe52f2fb27f292 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sun, 10 May 2026 03:41:03 -0700 Subject: defined interpreter-state that was quite some debugging. the write-up is still in progress (see the TODO) Force-Push: yes Change-Id: Ia1494bcde2b66e82efe8598899e93bdff60841d4 --- interpret.e | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'interpret.e') diff --git a/interpret.e b/interpret.e index 4517b25..7884feb 100644 --- a/interpret.e +++ b/interpret.e @@ -154,6 +154,11 @@ ~ (size, here value, here value) 3roll + 8 packalign here ! ; +: hide-entry dup entry-flags@ 0x80 | entry-flags! ; + +: unhide-entry dup entry-flags@ 0x80 invert & entry-flags! ; + + ~ TODO ~ buffer-physical-start 0000001000018240 ~ buffer-physical-length 0000001000018270 @@ -186,7 +191,7 @@ : is-alphanumeric ~ We don't have a character-literal syntax; the hex constants here are ~ ASCII codes. - dup 0x30 stackhex > { drop 0 exit } if ~ Less than "0". + dup 0x30 > { drop 0 exit } if ~ Less than "0". dup 0x39 >= { drop 1 exit } if ~ Less than or equal to "9". dup 0x41 > { drop 0 exit } if ~ Less than "A". dup 0x5a >= { drop 1 exit } if ~ Less than or equal to "Z". @@ -354,7 +359,6 @@ ~ (result, zero exit code) swap -1 * swap ; - ~ Here, we allocate a single machine word's worth of space to use as the ~ backing store of a mutable variable, initialized to zero. Then we define the ~ variable which points to that address. @@ -364,29 +368,24 @@ ~ harder for words that attempt to work with the contents of other words. So ~ we give it a name. -~ TODO this is the "create" / "here" conflict thing -describe-compilation -' interpreter-flags-storage describe -' interpreter-flags describe -newline -~ here @ hexdump -~ s" interpreter-flags-storage" stackhex create stackhex ~ make-immediate 0 , -~ ~ latest @ dup unhide-entry s" interpreter-flags" variable -~ describe-compilation -~ ~ here @ hexdump - - -: hide-entry dup entry-flags@ 0x80 | entry-flags! ; - -: unhide-entry dup entry-flags@ 0x80 invert & entry-flags! ; +s" interpreter-flags-storage" create make-immediate +latest @ unhide-entry +here @ +0 , +s" interpreter-flags" variable +~ There's an important bootstrapping concern: If you're loading this +~ interpreter into a running Evocation, it's important to not use the wrong +~ interpreter state value. TODO longer explanation ~ TODO the definition of set-word-immediate would come here; is it needed? : [ interpreter-flags @ 0x01 invert & interpreter-flags ! ; make-immediate +latest @ dup hide-entry : ] interpreter-flags @ 0x01 | interpreter-flags ! ; - +latest @ dup hide-entry +~ (pointer to [ entry, pointer to ] entry) ~ It may seem nonsensical to use : to define :, but the bootstrapping stuff ~ overrides what it does, so it works. The same, of course, goes for all these @@ -403,9 +402,12 @@ newline lit exit , latest @ unhide-entry ~ See above regarding [. Since it's an immediate word, we have to go to - ~ extra trouble to compile it as part of ;. - [ ' [ entry-to-execution-token , ] + ~ extra trouble to compile it as part of ;. Since it's also hidden, we have + ~ to go behind the interpreter's back to even get its entry pointer. + [ over entry-to-execution-token , ] ; make-immediate +latest @ dup hide-entry +~ (pointer to [ entry, pointer to ] entry, pointer to ; entry) ~ Although we will eventually define the word "'" to give us the symbol of @@ -503,11 +505,14 @@ newline ~ us exit it to the outer "quit" : quit { interpret } forever ; -~ quit +~ Now we switch into the new interpreter, enabling the three words we'd been +~ keeping hidden and then calling "quit". +unhide-entry unhide-entry unhide-entry quit + -0x10 newline . newline 4 5 + . : za 13 12 - . ; za -: ' word value@ find dropstring-with-result - interpreter-flags @ 1 & { literal } if ; make-immediate +~ : ' word value@ find dropstring-with-result +~ interpreter-flags @ 1 & { literal } if ; make-immediate ' za . newline : piz ' za . newline ; piz ~ ' interpret forget quit 2 3 * . -- cgit 1.4.1