diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-05-21 23:38:32 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-05-21 23:38:32 -0700 |
| commit | 5ae0fdad3c7df2fc02acfc3b8f36d96c5d07bcd4 (patch) | |
| tree | d3ef7a92ca411be57de91c27ad1881e976cd0d9e /interpret.e | |
| parent | ff9b791acf12688caec27e8ca883f3eefac8891d (diff) | |
the interpreter fully compiles now
doesn't work quite yet. close :) Force-Push: yes Change-Id: I71b6e788790fe2ca8e07dae95e9ad6e39d0664c0
Diffstat (limited to 'interpret.e')
| -rw-r--r-- | interpret.e | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/interpret.e b/interpret.e index ee0a52b..516c728 100644 --- a/interpret.e +++ b/interpret.e @@ -450,8 +450,28 @@ latest @ ; make-immediate +~ Though we only do it once, this is a bit involved so we provide it as a +~ word. Notionally there are situations in which it could come up again, so +~ it seems worth having around. +~ +~ It actually needs to run as a compiled word no matter what; if it were +~ run in interpret mode it would cut itself off from the rest of itself. +~ However, if we didn't want to keep it around we could have it forget +~ itself... +~ +~ It depends on ', so it's here in interpret.e. +: relink-main-input-buffer-to-stdin + 1024 allocate dup main-input-buffer buffer-physical-start ! + main-input-buffer buffer-logical-start ! + 1024 main-input-buffer buffer-physical-length ! + 0 main-input-buffer buffer-logical-length ! + ' refill-input-buffer-from-stdin entry-to-execution-token + main-input-buffer input-buffer-refill ! + ; + + -~ ~ Now the single most important word... +~ Now the single most important word... : interpret word @@ -493,7 +513,7 @@ latest @ ~ ourselves are compiled, hardcoded; doing a dynamic lookup would ~ require dealing with what happens if it's not found. dropstring-with-result - [ ' lit entry-to-execution-token literal ] + ' lit entry-to-execution-token , , exit } if @@ -507,24 +527,14 @@ latest @ ~ If it's neither in the dictionary nor a number, just print an error. s" No such word: " emitstring value@ emitstring dropstring ; -~ ~ TODO for ease of debugging, this isn't the full implementation, which lets -~ ~ us exit it to the outer "quit" -~ : quit { interpret } forever ; -~ -~ ~ Now we switch into the new interpreter, enabling the three words we'd been -~ ~ keeping hidden and then calling "quit". -~ dup entry-flags@ 0x80 invert & entry-flags! -~ dup entry-flags@ 0x80 invert & entry-flags! -~ dup entry-flags@ 0x80 invert & entry-flags! -~ quit -~ -~ ~ -0x10 newline . newline -~ compile ~ 4 5 + . : za 13 12 - . ; za -~ ~ ~ : ' word value@ find dropstring-with-result -~ ~ ~ interpreter-flags @ 1 & { literal } if ; make-immediate -~ ~ ' za . newline -~ ~ : piz ' za . newline ; piz -~ ~ ~ ' interpret forget quit 2 3 * . -~ ~ ' ' describe ' za describe ' piz describe -~ ~ bye -~ ~ +: quit r0 @ control! { interpret } forever ; + +~ Now we enable the three words we'd been keeping hidden. It would be a +~ good idea to call "quit" as soon as possible after this, but we leave it to +~ the user. +dup entry-flags@ 0x80 invert & entry-flags! +dup entry-flags@ 0x80 invert & entry-flags! +dup entry-flags@ 0x80 invert & entry-flags! + +relink-main-input-buffer-to-stdin quit + |