diff options
| -rw-r--r-- | README.txt | 20 | ||||
| -rw-r--r-- | transform.e | 92 |
2 files changed, 74 insertions, 38 deletions
diff --git a/README.txt b/README.txt index e3e12c1..384c8f9 100644 --- a/README.txt +++ b/README.txt @@ -213,8 +213,20 @@ you're metacircular.) Although the hex transform doesn't yet work on Forth programs (only programs written in Evocation-assembly), if you intend to play around with this you may -wish to know how to attempt to run it on things. There is not yet a -recommended way to run the hex transform on evoke.e, but when there is it will -look like appending most of the Evocation-in-Evocation build steps to the -hex.hex build steps, swapping them in where hex.e is now. +wish to know how to attempt to run it on things. The latest draft way to do +that is: + + $ (cat labels.e elf.e transform.e; echo 's" xyzzy" allocate-string dup 1048576 read-to-buffer'; cat core.e linux.e output.e amd64.e execution-support.e log-load.e dynamic.e input.e interpret.e flow-control.e linux-dynamic.e labels.e elf.e transform.e execution.e; echo 's" pyrzqxgl" allocate-string dup 262144 read-to-buffer '; cat core.e linux.e output.e amd64.e execution-support.e log-load.e; echo pyrzqxgl swap 262144 read-to-buffer; cat core.e linux.e output.e amd64.e execution-support.e log-load.e dynamic.e input.e interpret.e flow-control.e linux-dynamic.e; echo pyrzqxgl; cat evoke.e; echo 'xyzzy s" evoke-source" variable 1024 1024 * allocate s" evoke-binary" variable 1024 1024 * allocate s" evoke-metadata" variable evoke-metadata evoke-binary dup evoke-source 5 roll hex-transform bye ' ) | ./evoke > evoke.hex + + It will likely crash somewhere inside label-loop. You may find it helpful +to modify transform.e's definition of hex-sys-write-replacement by adding +the words "sys-write" and "exit" at the start of it, thereby turning it off +and allowing crash dumps to print. + + It's worth understanding that, although the log-load transform's output +comes first in the executable, it conceptually depends on the label transform, +and is unlikely to get anywhere until that's complete. For development +purposes, it may make sense to comment out the call to output-warm-start in +evoke.e and set a placeholder value for the warm-start label. Now running it +will cause failure somewhere inside the log-load transform; get debugging! :) diff --git a/transform.e b/transform.e index 38cd951..95475c2 100644 --- a/transform.e +++ b/transform.e @@ -3311,7 +3311,9 @@ allocate-transformation-state s" transformation-state" variable substring-entry-stack-depth@ 1+ substring-entry-stack-depth! } { + ~ We still consume the value, so that our caller doesn't crash. drop + ." Substring entry stack overflow." newline } if-else ; @@ -3324,6 +3326,9 @@ allocate-transformation-state s" transformation-state" variable substring-entry-stack-depth@ 8 * + @ } { ." Substring entry stack underflow." newline + + ~ We still return a value, so that our caller doesn't crash. + 0 } if-else ; ~ (data start, data length, entry type, string pointer, entry pointer --) @@ -3762,38 +3767,44 @@ allocate-transformation-state s" transformation-state" variable pop-substring-entry-stack - dup hex-output-metadata-entry-type @ - hex-output-metadata-entry-type-push-substring-decimal = { - dup hex-output-metadata-entry-string @ . - } if - - dup hex-output-metadata-entry-type @ - hex-output-metadata-entry-type-push-substring-hex8 = { - ." 0x" - dup hex-output-metadata-entry-string @ .hex8 - } if - - dup hex-output-metadata-entry-type @ - hex-output-metadata-entry-type-push-substring-hex16 = { - ." 0x" - dup hex-output-metadata-entry-string @ .hex16 - } if - - dup hex-output-metadata-entry-type @ - hex-output-metadata-entry-type-push-substring-hex32 = { - ." 0x" - dup hex-output-metadata-entry-string @ .hex32 - } if - - dup hex-output-metadata-entry-type @ - hex-output-metadata-entry-type-push-substring-hex64 = { - ." 0x" - dup hex-output-metadata-entry-string @ .hex64 - } if - - dup hex-output-metadata-entry-type @ - hex-output-metadata-entry-type-push-substring-string = { - dup hex-output-metadata-entry-string @ emitstring + ~ If we underflowed the stack, we got zero back, so make sure not to + ~ crash. A crash here would be a pain to debug because it would be + ~ unclear how much of the overall system is working, and it's a + ~ complex system. + dup { + dup hex-output-metadata-entry-type @ + hex-output-metadata-entry-type-push-substring-decimal = { + dup hex-output-metadata-entry-string @ . + } if + + dup hex-output-metadata-entry-type @ + hex-output-metadata-entry-type-push-substring-hex8 = { + ." 0x" + dup hex-output-metadata-entry-string @ .hex8 + } if + + dup hex-output-metadata-entry-type @ + hex-output-metadata-entry-type-push-substring-hex16 = { + ." 0x" + dup hex-output-metadata-entry-string @ .hex16 + } if + + dup hex-output-metadata-entry-type @ + hex-output-metadata-entry-type-push-substring-hex32 = { + ." 0x" + dup hex-output-metadata-entry-string @ .hex32 + } if + + dup hex-output-metadata-entry-type @ + hex-output-metadata-entry-type-push-substring-hex64 = { + ." 0x" + dup hex-output-metadata-entry-string @ .hex64 + } if + + dup hex-output-metadata-entry-type @ + hex-output-metadata-entry-type-push-substring-string = { + dup hex-output-metadata-entry-string @ emitstring + } if } if ~ Tidy up. We want to treat the next character normally, so we @@ -3804,11 +3815,16 @@ allocate-transformation-state s" transformation-state" variable ~ (input point, first non-word character or 0, word pointer) drop + ~ If we underflow the stack, we'll get zeroes back here. In order + ~ to avoid causing more confusing problems later, we make sure to + ~ discard the zeroes instead of pushing them. As above, the + ~ reasoning is that it's easier to diagnose what's wrong with this + ~ subsystem when it runs to completion. pop-substring-entry-stack pop-substring-entry-stack swap - push-substring-entry-stack - push-substring-entry-stack + dup { push-substring-entry-stack } { drop } if-else + dup { push-substring-entry-stack } { drop } if-else ~ We want to ignore the next character, so that this word can be ~ used without creating spurious spaces in the output. @@ -3851,6 +3867,14 @@ allocate-transformation-state s" transformation-state" variable ~ ~ (length to write, base address --) : hex-sys-write-replacement + ~ In intended operation, the code under transformation is a compilation + ~ process, and it won't output anything that isn't executable binary. + ~ However, while developing, it's common to have crashes, and it's nice to + ~ get the crash dump as ASCII rather than hex. + dup is-in-label-loop-buffer not { + sys-write exit + } if + postprocess-metadata-entries { over 0 <= } { |