From 53f52a67b7c5bb8af12c92a2f3a219e75dd9b0c3 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Wed, 20 May 2026 18:23:07 -0700 Subject: colon, semicolon, and compiled integers all work with log-load now yay next up is to figure out why calling newly-defined docol-based words with it does not work Force-Push: yes Change-Id: I9c5f50d20f43ad8a15b6db58e046f1e0bb158266 --- evoke.e | 25 ++++++++++--------------- execution-support.e | 18 ++++++++---------- log-load.e | 27 ++++++++++++++++++++++++++- transform.e | 32 ++++++++++++++++++++++---------- 4 files changed, 66 insertions(+), 36 deletions(-) diff --git a/evoke.e b/evoke.e index 4252e91..05e500e 100644 --- a/evoke.e +++ b/evoke.e @@ -8,7 +8,6 @@ s" source-to-precompile" variable -~ : fooze 4 . ; fooze 1024 read-to-buffer ~ We begin by outputting the actual docol routine, the one that codewords ~ should point to. Note that this is before we've done any word header. @@ -32,23 +31,19 @@ pack-next 8 packalign here ! +~ Now that we have docol, colon will work and we can define exit the normal +~ way. +: exit + [ here @ + :rsi pack-popcontrol + here ! ] ;asm -s" exit" create -here @ -dup 8 + pack64 -:rsi pack-popcontrol -here ! - -: foo [ crash 1 2 + ; +~ Now that we have exit, semicolon will also work and we can define +~ non-assembly words. +: foo 4 5 + ; -0 sys-exit +42 sys-exit -~ Now that we have docol, colon will work and we can define exit the normal -~ way. -~ : exit -~ [ here @ -~ :rsi pack-popcontrol -~ here ! ] ;asm pyrzqxgl ~ 0 sys-exit diff --git a/execution-support.e b/execution-support.e index 67f9162..05dfe6d 100644 --- a/execution-support.e +++ b/execution-support.e @@ -34,14 +34,14 @@ ~ Flags ~ * DF = 0 is required ~ -~ (base address -- new base address) +~ (output point -- output point) : pack-next - ~ Copy the next word's address from *rsi into rax. Increment rsi (as per the - ~ DF flag). + ~ Copy the next word's address from *rsi into rax. Increment rsi (as per + ~ the DF flag). lods64 - ~ Load the codeword from the word's contents, and jump to the interpreter it - ~ points to. + ~ Load the codeword from the word's contents, and jump to the interpreter + ~ it points to. :rax jmp-abs-indirect-reg64 ; @@ -64,7 +64,7 @@ ~ Thus, notionally we are doing just this one transfer of control before ~ eventually getting around to inlining "next". Hence the name. ~ -~ (target address, base address -- new base address) +~ (output point, target address -- output point) : pack-beforenext ~ Do a permanent transfer of control by setting rax and invoking the ~ codeword. Of course, we could jump to docol ourselves but this will work @@ -95,14 +95,12 @@ ~ ~ * rbp points to the top of the control stack. ~ -~ TODO can this be correct? it seems backwards? -~ (source register, base address -- new base address) +~ (output point, source register -- output point) : pack-pushcontrol swap :rbp -8 :rbp lea-reg64-disp8-reg64 swap :rbp 0 mov-disp8-reg64-reg64 ; -~ TODO can this be correct? it seems backwards? -~ (target register, base address -- new base address) +~ (output point, target register -- output point) : pack-popcontrol :rbp 0 3roll mov-reg64-disp8-reg64 :rbp 8 :rbp lea-reg64-disp8-reg64 ; diff --git a/log-load.e b/log-load.e index 2c82d9f..f386b26 100644 --- a/log-load.e +++ b/log-load.e @@ -249,11 +249,36 @@ ~ (log address, value, here) @ swap pack64 ~ (log address, updated here value) - 3roll log-load-here swap 3unroll + swap log-load-here swap 3unroll ~ (log address, updated here value, here) ! ; +~ This is the same as `;asm`, from interpret.e, except that it takes the +~ log's address as a parameter rather than hardcoding it, so that it can be +~ used in situations where the normal compilation process isn't yet available. +~ +~ Its two main responsibilities are to call `pack-next`, from +~ execution-support.e, and to overwrite the codeword. It also deals with +~ alignment. +~ (log address) +: log-load-semicolon-assembly + log-load-here @ + ~ (log address, output point) + + pack-next + 8 packalign + ~ (log address, output point) + + swap log-load-here swap 3unroll ! + ~ (log address) + + log-load-latest @ + ~ (log address, entry pointer) + entry-to-execution-token + dup 8 + swap ! ; + + ~ This is the same as "variable", from interpret.e, except that it takes the ~ log's address as a parameter rather than hardcoding it, so that it can be ~ used in situations where the normal compilation process isn't yet available. diff --git a/transform.e b/transform.e index 581cb0b..723484c 100644 --- a/transform.e +++ b/transform.e @@ -1466,6 +1466,7 @@ allocate-transform-state s" transform-state" variable swap-transform-variables ~ As usual, we do these in reverse. L@' log-load-comma + L@' lit L@' log-load-comma L@' log-load-find-execution-token L@' litstring @@ -1476,6 +1477,7 @@ allocate-transform-state s" transform-state" variable here @ s" lit" packstring 8 packalign here ! offset-to-target-address-space , ~ log-load-find-execution-token offset-to-target-address-space , ~ log-load-comma + offset-to-target-address-space , ~ lit swap , ~ the value offset-to-target-address-space , ~ log-load-comma @@ -1587,16 +1589,26 @@ allocate-transform-state s" transform-state" variable ~ below. It is likely to be extremely useful to read and understand ";asm" in ~ interpret.e before attempting to understand "log-load;asm". : log-load-semicolon-assembly-alternate - ~ TODO this is just unimplemented, which seems bad :D - ~ here @ pack-next 8 packalign here ! - ~ latest @ dup unhide-entry entry-to-execution-token - ~ ~ The codeword needs to be transformed to the target address space. - ~ dup 8 + host-address-space-to-target - ~ swap ! - - ~ ~ Since [ is an immediate word, we have to go to extra trouble to compile - ~ ~ it as part of ;asm. - ~ [ ' [ entry-to-execution-token , ] + ~ We generate code that statically invokes log-load-semicolon-assembly, + ~ which does all the actual work. There's quite a few steps, so it makes + ~ sense to have a word that bundles them up. + log-load-roll-log-address + + swap-transform-variables + ~ As usual, we do these in reverse. + L@' log-load-semicolon-assembly + swap-transform-variables + + ~ The stack delta of this call is 0. + offset-to-target-address-space , ~ log-load-semicolon-assembly + + log-load-unroll-log-address + + ~ This is where we would unhide the entry, but again, we don't do that. + + ~ Since [ is an immediate word, we have to go to extra trouble to compile + ~ it as part of ;. + [ ' [ entry-to-execution-token , ] ; make-immediate -- cgit 1.4.1