diff options
| -rw-r--r-- | execution.e | 16 | ||||
| -rw-r--r-- | input.e | 31 | ||||
| -rw-r--r-- | interpret.e | 45 | ||||
| -rw-r--r-- | transform.e | 3 |
4 files changed, 59 insertions, 36 deletions
diff --git a/execution.e b/execution.e index ce4c2c4..0aa5491 100644 --- a/execution.e +++ b/execution.e @@ -483,11 +483,17 @@ ~ Now everything we need has been added to the log and we're almost ready ~ to jump into it. It's inconvenient for code under the log-load transform - ~ to interact with the label system, so we initialize main-input-buffer - ~ here. - ~ - ~ TODO or not ;) - ~ main-input-buffer boot-source attach-string-to-input-buffer + ~ to interact with the label system, so if we want to point + ~ main-input-buffer at a string, this is the place to do it. + + ~ The next layer is built now, so let's move on to it. + L@' litstring offset-to-target-address-space pack64 + s" quit" packstring 8 packalign + L@' log-load-find-execution-token offset-to-target-address-space pack64 + L@' swap offset-to-target-address-space pack64 + ~ Get rid of that heap pointer on the stack, we're finally done with it! + L@' drop offset-to-target-address-space pack64 + L@' execute offset-to-target-address-space pack64 ; diff --git a/input.e b/input.e index c7a1c02..8203673 100644 --- a/input.e +++ b/input.e @@ -178,8 +178,7 @@ ~ If the buffer is empty, make sure its logical position is at the ~ physical start. Otherwise, leave it alone. ~ -~ In: -~ pointer to buffer metadata +~ (metadata pointer --) : normalize-buffer dup buffer-logical-length @ 0 = { dup buffer-physical-start @ swap @@ -195,18 +194,32 @@ ~ If the buffer is full, this will return as normal but the length will ~ be zero. The caller should make sure to respect that. ~ -~ In: -~ pointer to buffer metadata -~ Out: -~ destination start -~ destination length +~ (metadata pointer -- destination start, destination length) : compute-next-buffer-free-block dup buffer-physical-start @ swap dup buffer-physical-length @ swap 3unroll + swap -~ (physical end, metadata pointer) + ~ (physical end, metadata pointer) dup buffer-logical-start @ swap dup buffer-logical-length @ swap 3unroll + swap 3unroll -~ (metadata pointer, physical end, logical end not yet wrapped) + ~ (metadata pointer, physical end, logical end not yet wrapped) + + 2dup >= { + ~ If the logical end is greater than or equal to the physical end, find + ~ where it wraps to and start from there. + swap - swap dup buffer-physical-start @ swap 3unroll + + ~ (metadata pointer, destination start) + ~ In this scenario, the logical start is the end of the free space, so + ~ compute how far away it is. + dup 3roll + ~ (destination start, destination start, metadata pointer) + buffer-logical-start @ swap - + } { + 3roll drop + dup 3roll swap - + ~ If the logical end is less than the physical end, it is the destination; + ~ the physical end is also the end of the free space, so compute how far + ~ away it is. + } if-else ; ~ (metadata pointer --) diff --git a/interpret.e b/interpret.e index 516c728..3e30523 100644 --- a/interpret.e +++ b/interpret.e @@ -450,27 +450,6 @@ 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... : interpret word @@ -536,5 +515,27 @@ 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 +~ 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 ! + [ s" refill-input-buffer-from-stdin" + find entry-to-execution-token literal ] + main-input-buffer input-buffer-refill ! + ; + +~ Of course it is perfectly reasonable to change this, but for now it's +~ hardcoded. +relink-main-input-buffer-to-stdin diff --git a/transform.e b/transform.e index 4d7c32c..7b82eae 100644 --- a/transform.e +++ b/transform.e @@ -747,6 +747,9 @@ allocate-transform-state s" transform-state" variable dup s" compute-next-buffer-free-block" stringcmp 0 = { drop 1 exit } if dup s" refill-input-buffer-from-stdin" stringcmp 0 = { drop -1 exit } if dup s" main-input-buffer" stringcmp 0 = { drop 1 exit } if + dup s" consume" stringcmp 0 = { drop 0 exit } if + dup s" peek" stringcmp 0 = { drop 1 exit } if + dup s" key" stringcmp 0 = { drop 1 exit } if ~ From interpret.e. dup s" unroll-past-string" stringcmp 0 = { drop 0 exit } if |