summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-05-16 01:24:16 -0700
committerIrene Knapp <ireneista@irenes.space>2026-05-16 01:24:16 -0700
commit8c5b92312f9e7bc2fff7b547a03805d9bf47d26e (patch)
tree41ef59e7c860cc06cb180c6159667e408630ce19
parentb564cab848ca4de050304cc8b53196a3420018a6 (diff)
word labels are now stored as offsets
also, the various address spaces in use are described better, and there's helper functions to convert between them.

Force-Push: yes
Change-Id: Idb56d2b6299d6e7071c9d42b2eb1138b17b85c69
-rw-r--r--execution.e2
-rw-r--r--transform.e69
2 files changed, 57 insertions, 14 deletions
diff --git a/execution.e b/execution.e
index 8410678..bd27f7e 100644
--- a/execution.e
+++ b/execution.e
@@ -481,7 +481,7 @@
   current-offset L!' warm-start
 
   ~ TODO this is tied to the specific example in evoke
-  over L@' happy-path swap - L@' origin + pack64
+  L@' happy-path L@' origin + pack64
 
   ~   Before handing off to us, cold-start pushed a single value onto the
   ~ stack, a pointer to the beginning of the heap. Now, we load our entire
diff --git a/transform.e b/transform.e
index e788836..f8a4ee4 100644
--- a/transform.e
+++ b/transform.e
@@ -163,12 +163,52 @@ allocate-transform-state s" transform-state" variable
   latest @ transform-state transform-state-saved-latest @
   latest ! transform-state transform-state-saved-latest ! ;
 
-~ (address within the output buffer -- address at generated binary's runtime)
-: transform-offset
+~   We deal with a few address spaces. There's the "host" address space, the
+~ space this process performing the compilation is using for itself. There's
+~ the "target" address space, the address space that will exist later, when
+~ the program we've compiled is running.
+~
+~   Then there's "offsets", which are relative to the start of the output
+~ buffer. For clarity's sake, we always refer to these as offsets, rather than
+~ as addresses.
+~
+~   When we define labels for compiled words, we set their values to be
+~ offsets pointing to the generated codeword. This is done by "Lcreate". We
+~ then need to convert them either to the host or the target address space,
+~ depending on how we're using them.
+~
+~   There's no approach here that isn't confusing, but the hope is that by
+~ using offsets, so that we always have to convert them regardless of what
+~ we're doing with them, we won't miss a spot where conversion needs to
+~ happen.
+~
+~ (output offset -- target address)
+: offset-to-target-address-space
+  ~ Don't transform null pointers.
+  dup { swap-transform-variables L@' origin swap-transform-variables + } if ;
+
+~ (target address -- output offset)
+: target-address-space-to-offset
   ~ Don't transform null pointers.
-  dup { transform-state transform-state-output-buffer-start @ -
-        swap-transform-variables L@' origin swap-transform-variables
-        + } if ;
+  dup { swap-transform-variables L@' origin swap-transform-variables - } if ;
+
+~ (output offset -- host address)
+: offset-to-host-address-space
+  ~ Don't transform null pointers
+  dup { transform-state transform-state-output-buffer-start @ + } if ;
+
+~ (host address --output offset)
+: host-address-space-to-offset
+  ~ Don't transform null pointers
+  dup { transform-state transform-state-output-buffer-start @ - } if ;
+
+~ (host address inside the output buffer -- target address)
+: host-address-space-to-target
+  host-address-space-to-offset offset-to-target-address-space ;
+
+~ (target address -- host address)
+: target-address-space-to-host
+  target-address-space-to-offset offset-to-host-address-space ;
 
 
 ~   This is the alternate version of "create" for use with the label
@@ -180,9 +220,11 @@ allocate-transform-state s" transform-state" variable
   here @ 10 + 3unroll memmove
   here @
 
-  ~   This value of "latest" is going into the generated output, so call
-  ~ transform-offset on it first.
-  latest @ transform-offset pack64
+  ~   This value of "latest" is going into the generated output, so we need
+  ~ to map it to the target address space. It's stored in the host address
+  ~ space to make immediate words work as expected, so the appropriate
+  ~ conversion is host-address-space-to-target.
+  latest @ host-address-space-to-target pack64
   0 pack8
   0 pack8
   +
@@ -191,7 +233,8 @@ allocate-transform-state s" transform-state" variable
 
   ~   Now we're immediately after the word header, which is where the codeword
   ~ will be. This is the value the label should taken on, so we set it.
-  dup here @ 10 +
+  dup host-address-space-to-offset
+  here @ 10 +
   swap-transform-variables
   intern-label set-label
   swap-transform-variables
@@ -226,7 +269,7 @@ allocate-transform-state s" transform-state" variable
   swap-transform-variables
   L@' exit
   swap-transform-variables
-  transform-offset ,
+  offset-to-target-address-space ,
 
   latest @ unhide-entry
 
@@ -244,7 +287,7 @@ allocate-transform-state s" transform-state" variable
   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 + transform-offset
+  dup 8 + host-address-space-to-target
   swap !
 
   ~   Since [ is an immediate word, we have to go to extra trouble to compile
@@ -347,7 +390,7 @@ allocate-transform-state s" transform-state" variable
         ~
         ~   Fortunately we don't have to look at it, just append it to the heap
         ~ and clean up.
-        transform-offset , drop dropstring 0 exit
+        offset-to-target-address-space , drop dropstring 0 exit
       } if
     } if
   } if
@@ -380,7 +423,7 @@ allocate-transform-state s" transform-state" variable
 
       ~ We look up "lit" as a label.
       swap-transform-variables L@' lit swap-transform-variables
-      transform-offset
+      offset-to-target-address-space
       , ,
       0 exit
     } if