diff options
Diffstat (limited to 'transform.e')
| -rw-r--r-- | transform.e | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/transform.e b/transform.e index 7952152..2516e53 100644 --- a/transform.e +++ b/transform.e @@ -88,15 +88,15 @@ ~ concern, since the variables must point to one of those addresses or the ~ other, not both. ~ -~ We resolve the issue by running our own, alternate versions of the words -~ "create", ":", ";", and ";asm" which use the label facility to compute the -~ addresses that will be needed at runtime. These alternates run instead of -~ the normal versions of these words. The code being compiled is responsible -~ for not doing anything else that would rely on "here" and "latest" matching -~ their runtime addresses, though it is otherwise allowed to modify and rely -~ on them in all the usual ways. The alternate versions are defined in this -~ file as their own words, "Lcreate", "L:", "L;", and "L;asm". -~ TODO note L@' and L!' +~ We resolve the issue by running our own, alternate versions of most of the +~ critical word-defining words, including for example "create", ":", and ";". +~ These alternates run instead of the normal versions of these words, and use +~ the label facility to compute the addresses that will be needed at runtime. +~ The code being compiled is responsible for not doing anything else that +~ would rely on "here" and "latest" matching their runtime addresses, though +~ it is otherwise allowed to modify and rely on them in all the usual ways. +~ The alternate versions are defined in this file as their own words, +~ "label-create-alternate" and so on. ~ ~ Note that these alternates are applied via a purely lexical ~ transformation: when a word would be looked up in the dictionary to @@ -271,9 +271,9 @@ allocate-transform-state s" transform-state" variable ~ 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. +~ offsets pointing to the generated codeword. This is done by +~ label-create-alternate. 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 @@ -328,8 +328,8 @@ allocate-transform-state s" transform-state" variable ~ This is the alternate version of "create" for use with the label ~ transform. Its code is the same as the regular "create" except as noted ~ below. It is likely to be extremely useful to read and understand "create" -~ in interpret.e before attempting to understand "Lcreate". -: Lcreate +~ in interpret.e before attempting to understand label-create-alternate. +: label-create-alternate dup stringlen 1 + dup 3unroll here @ 10 + 3unroll memmove here @ @@ -359,10 +359,10 @@ allocate-transform-state s" transform-state" variable ~ This is the alternate version of ":" for use with the label transform. Its ~ code is the same as the regular "create" except as noted below. It is likely ~ to be extremely useful to read and understand ":" in interpret.e before -~ attempting to understand "L:". -: L: - ~ This calls "Lcreate" instead of "create". - word value@ Lcreate dropstring +~ attempting to understand label-colon-alternate. +: label-colon-alternate + ~ This calls label-create-alternate instead of "create". + word value@ label-create-alternate dropstring ~ This looks up "docol" by label. swap-transform-variables @@ -377,8 +377,8 @@ allocate-transform-state s" transform-state" variable ~ This is the alternate version of ";" for use with the label transform. Its ~ code is the same as the regular "create" except as noted below. It is likely ~ to be extremely useful to read and understand ";" in interpret.e before -~ attempting to understand "L;". -: L; +~ attempting to understand label-semicolon-alternate. +: label-semicolon-alternate ~ This looks up "exit" by label. swap-transform-variables L@' exit @@ -396,8 +396,8 @@ allocate-transform-state s" transform-state" variable ~ This is the alternate version of ";asm" for use with the label transform. ~ Its code is the same as the regular "create" except as noted below. It is ~ likely to be extremely useful to read and understand ";asm" in interpret.e -~ before attempting to understand "L;asm". -: L;asm +~ before attempting to understand label-semicolon-assembly-alternate. +: label-semicolon-assembly-alternate 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. @@ -414,7 +414,7 @@ allocate-transform-state s" transform-state" variable ~ ~ (string pointer --) : label-keyword-alternate - Lcreate + label-create-alternate here @ dup ~ (self execution token, output point) @@ -494,10 +494,11 @@ allocate-transform-state s" transform-state" variable ~ the alternate if so. dup 0 swap ~ (name as stack string, name pointer, placeholder, name pointer) - dup s" create" stringcmp 0 = { swap drop ' Lcreate swap } if - dup s" :" stringcmp 0 = { swap drop ' L: swap } if - dup s" ;" stringcmp 0 = { swap drop ' L; swap } if - dup s" ;asm" stringcmp 0 = { swap drop ' L;asm swap } if + dup s" create" stringcmp 0 = { swap drop ' label-create-alternate swap } if + dup s" :" stringcmp 0 = { swap drop ' label-colon-alternate swap } if + dup s" ;" stringcmp 0 = { swap drop ' label-semicolon-alternate swap } if + dup s" ;asm" stringcmp 0 = { + swap drop ' label-semicolon-assembly-alternate swap } if dup s" L@'" stringcmp 0 = { swap drop ' label-L@'-alternate swap } if dup s" L!'" stringcmp 0 = { swap drop ' label-L!'-alternate swap } if dup s" keyword" stringcmp 0 = { @@ -557,8 +558,9 @@ allocate-transform-state s" transform-state" variable intern-label use-label swap-transform-variables - ~ Labels point to codewords (because that's what "Lcreate" does), - ~ which is already what we want to output. + ~ Labels point to codewords (because that's what + ~ label-create-alternate does), which is already what we want to + ~ output. ~ ~ An important caveat: Though it would require something weird to be ~ happening, such as a forced forward reference, the label may be |