summary refs log tree commit diff
path: root/quine.asm
diff options
context:
space:
mode:
Diffstat (limited to 'quine.asm')
-rw-r--r--quine.asm190
1 files changed, 130 insertions, 60 deletions
diff --git a/quine.asm b/quine.asm
index 990f0ae..e37751f 100644
--- a/quine.asm
+++ b/quine.asm
@@ -2453,11 +2453,11 @@ cold_start:
   ; ELF, rather than the copy on the heap. Watch carefully for that, with all
   ; the lookups from here on.
   dq litstring, "emitstring", early_create, early_docol_codeword
-  dq litstring, "dup", early_find, early_comma
-  dq litstring, "stringlen", early_find, early_comma
-  dq litstring, "swap", early_find, early_comma
-  dq litstring, "sys-write", early_find, early_comma
-  dq litstring, "exit", early_find, early_comma
+  dq litstring, "dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "stringlen", early_find, entry_to_execution_token, early_comma
+  dq litstring, "swap", early_find, entry_to_execution_token, early_comma
+  dq litstring, "sys-write", early_find, entry_to_execution_token, early_comma
+  dq litstring, "exit", early_find, entry_to_execution_token, early_comma
   dq early_here, fetch, lit, 8, packalign, early_here_store
 
   dq litstring, "crash", early_create, early_self_codeword, early_here, fetch
@@ -2471,86 +2471,86 @@ cold_start:
   ; because the user of pack64 and its variants is always doing something
   ; where exact byte sizes are crucial.
   dq litstring, "pack64", early_create, early_docol_codeword
-  dq litstring, "swap", early_find, early_comma
-  dq litstring, "dup", early_find, early_comma
-  dq litstring, "3unroll", early_find, early_comma
-  dq litstring, "store", early_find, early_comma
-  dq litstring, "lit", early_find, early_comma
+  dq litstring, "swap", early_find, entry_to_execution_token, early_comma
+  dq litstring, "dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "3unroll", early_find, entry_to_execution_token, early_comma
+  dq litstring, "!", early_find, entry_to_execution_token, early_comma
+  dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 8, early_comma
-  dq litstring, "+", early_find, early_comma
-  dq litstring, "exit", early_find, early_comma
+  dq litstring, "+", early_find, entry_to_execution_token, early_comma
+  dq litstring, "exit", early_find, entry_to_execution_token, early_comma
   dq early_here, fetch, lit, 8, packalign, early_here_store
 
   dq litstring, "pack32", early_create, early_docol_codeword
-  dq litstring, "swap", early_find, early_comma
-  dq litstring, "dup", early_find, early_comma
-  dq litstring, "3unroll", early_find, early_comma
-  dq litstring, "store32", early_find, early_comma
-  dq litstring, "lit", early_find, early_comma
+  dq litstring, "swap", early_find, entry_to_execution_token, early_comma
+  dq litstring, "dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "3unroll", early_find, entry_to_execution_token, early_comma
+  dq litstring, "32!", early_find, entry_to_execution_token, early_comma
+  dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 4, early_comma
-  dq litstring, "+", early_find, early_comma
-  dq litstring, "exit", early_find, early_comma
+  dq litstring, "+", early_find, entry_to_execution_token, early_comma
+  dq litstring, "exit", early_find, entry_to_execution_token, early_comma
   dq early_here, fetch, lit, 8, packalign, early_here_store
 
   dq litstring, "pack16", early_create, early_docol_codeword
-  dq litstring, "swap", early_find, early_comma
-  dq litstring, "dup", early_find, early_comma
-  dq litstring, "3unroll", early_find, early_comma
-  dq litstring, "store16", early_find, early_comma
-  dq litstring, "lit", early_find, early_comma
+  dq litstring, "swap", early_find, entry_to_execution_token, early_comma
+  dq litstring, "dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "3unroll", early_find, entry_to_execution_token, early_comma
+  dq litstring, "16!", early_find, entry_to_execution_token, early_comma
+  dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 2, early_comma
-  dq litstring, "+", early_find, early_comma
-  dq litstring, "exit", early_find, early_comma
+  dq litstring, "+", early_find, entry_to_execution_token, early_comma
+  dq litstring, "exit", early_find, entry_to_execution_token, early_comma
   dq early_here, fetch, lit, 8, packalign, early_here_store
 
   dq litstring, "pack8", early_create, early_docol_codeword
-  dq litstring, "swap", early_find, early_comma
-  dq litstring, "dup", early_find, early_comma
-  dq litstring, "3unroll", early_find, early_comma
-  dq litstring, "store8", early_find, early_comma
-  dq litstring, "lit", early_find, early_comma
+  dq litstring, "swap", early_find, entry_to_execution_token, early_comma
+  dq litstring, "dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "3unroll", early_find, entry_to_execution_token, early_comma
+  dq litstring, "8!", early_find, entry_to_execution_token, early_comma
+  dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 1, early_comma
-  dq litstring, "+", early_find, early_comma
-  dq litstring, "exit", early_find, early_comma
+  dq litstring, "+", early_find, entry_to_execution_token, early_comma
+  dq litstring, "exit", early_find, entry_to_execution_token, early_comma
   dq early_here, fetch, lit, 8, packalign, early_here_store
 
   dq litstring, "packstring", early_create, early_docol_codeword
-  dq litstring, "dup", early_find, early_comma
-  dq litstring, "stringlen", early_find, early_comma
-  dq litstring, "lit", early_find, early_comma
+  dq litstring, "dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "stringlen", early_find, entry_to_execution_token, early_comma
+  dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 1, early_comma
-  dq litstring, "+", early_find, early_comma
-  dq litstring, "dup", early_find, early_comma
-  dq litstring, "lit", early_find, early_comma
+  dq litstring, "+", early_find, entry_to_execution_token, early_comma
+  dq litstring, "dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 4, early_comma
-  dq litstring, "roll", early_find, early_comma
-  dq litstring, "dup", early_find, early_comma
-  dq litstring, "lit", early_find, early_comma
+  dq litstring, "roll", early_find, entry_to_execution_token, early_comma
+  dq litstring, "dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 5, early_comma
-  dq litstring, "unroll", early_find, early_comma
-  dq litstring, "+", early_find, early_comma
-  dq litstring, "lit", early_find, early_comma
+  dq litstring, "unroll", early_find, entry_to_execution_token, early_comma
+  dq litstring, "+", early_find, entry_to_execution_token, early_comma
+  dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 4, early_comma
-  dq litstring, "unroll", early_find, early_comma
-  dq litstring, "memcopy", early_find, early_comma
-  dq litstring, "exit", early_find, early_comma
+  dq litstring, "unroll", early_find, entry_to_execution_token, early_comma
+  dq litstring, "memcopy", early_find, entry_to_execution_token, early_comma
+  dq litstring, "exit", early_find, entry_to_execution_token, early_comma
   dq early_here, fetch, lit, 8, packalign, early_here_store
 
   dq litstring, "packalign", early_create, early_docol_codeword
-  dq litstring, "2dup", early_find, early_comma
-  dq litstring, "/%", early_find, early_comma
-  dq litstring, "drop", early_find, early_comma
-  dq litstring, "0branch", early_find, early_comma
+  dq litstring, "2dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "/%", early_find, entry_to_execution_token, early_comma
+  dq litstring, "drop", early_find, entry_to_execution_token, early_comma
+  dq litstring, "0branch", early_find, entry_to_execution_token, early_comma
   dq lit, 8*8, early_comma
-  dq litstring, "swap", early_find, early_comma
-  dq litstring, "lit", early_find, early_comma
+  dq litstring, "swap", early_find, entry_to_execution_token, early_comma
+  dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 0, early_comma
-  dq litstring, "pack8", early_find, early_comma
-  dq litstring, "swap", early_find, early_comma
-  dq litstring, "branch", early_find, early_comma
+  dq litstring, "pack8", early_find, entry_to_execution_token, early_comma
+  dq litstring, "swap", early_find, entry_to_execution_token, early_comma
+  dq litstring, "branch", early_find, entry_to_execution_token, early_comma
   dq lit, -11*8, early_comma
-  dq litstring, "drop", early_find, early_comma
-  dq litstring, "exit", early_find, early_comma
+  dq litstring, "drop", early_find, entry_to_execution_token, early_comma
+  dq litstring, "exit", early_find, entry_to_execution_token, early_comma
   dq early_here, fetch, lit, 8, packalign, early_here_store
 
   dq litstring, "litpack64", early_create, early_self_codeword
@@ -2595,6 +2595,8 @@ cold_start:
   dq swap, unroll3, pack_beforenext
   dq lit, 8, packalign, early_here_store
 
+  dq litstring, "pack8", early_find, early_show_source, lit, 0, sys_exit
+
   ;;; For triage's sake, here's an inventory of everything else in the file.
   ;;;
   ;;; Macros:
@@ -3627,6 +3629,10 @@ defword emitstring, 0
   dq docol, dup, stringlen, swap, sys_write, exit
 
 
+defword emitinteger, 0
+  dq docol, drop, litstring, "(int goes here)", emitstring, exit
+
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Development utilities ;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -4882,6 +4888,7 @@ defword find_in, 0
 ;   heap address
 ;   entry address
 ; Stack out:
+;   heap address
 ;   entry address or 0
 defword early_next_newer_entry, 0
   dq docol
@@ -4925,9 +4932,40 @@ defword entry_to_name, 0
   dq lit, 10, add
   dq exit
 
+; Stack in:
+;   heap address
+;   entry address
+; Stack out:
+;   heap address
+;   guessed entry end address (first byte that's not part of it)
+defword early_guess_entry_end, 0
+  dq docol
+  dq swap, early_here, fetch, swap, early_latest, fetch, swap
+  ; (entry, here, latest, heap)
+  dq lit, 4, unroll, roll3
+  ; (heap, here, latest, entry)
+  dq guess_entry_end_in
+  dq exit
+
+; Stack in:
+;   "here" value
+;   dictionary to search within
+;   entry address
+; Stack out:
+;   next entry address or 0
+defword guess_entry_end_in, 0
+  dq docol
+  dq next_newer_entry_in
+  ; (here, next entry address or 0)
+  dq dup, lit, 0, eq, zbranch, 3*8
+  ; This is the branch where it's not found. Return "here".
+  dq drop, exit
+  ; This is the branch where it's found. Return the next entry address.
+  dq swap, drop, exit
+
 ;   Jonesforth calls this "CFA>". Jonesforth's implementation searches the
 ; entire dictionary, since its word header format isn't designed to be
-; traversed in reverse as ours is.
+; traversed in reverse, but ours is, so it should be fast.
 defword execution_token_to_entry, 0
   dq docol
   dq lit, 1, sub
@@ -4936,6 +4974,38 @@ defword execution_token_to_entry, 0
   dq lit, 9, sub
   dq exit
 
+; Stack in:
+;   heap address
+;   entry address
+; Stack out:
+;   heap address
+defword early_show_source, 0
+  dq docol
+  dq dup, unroll3, early_guess_entry_end, swap, unroll3
+  ; (heap address, entry address, end address)
+  dq show_source_between
+  dq exit
+
+; Stack in:
+;   entry address
+;   end address
+defword show_source_between, 0
+  dq docol
+  dq swap, entry_to_execution_token, lit, 8, add
+  ; (end address, current address)
+  dq dup2, lt, zbranch, 4*8, drop, drop, exit
+  dq dup, fetch, execution_token_to_entry, entry_to_name
+  ; (end address, current address, name)
+  dq dup, emitstring, litstring, " ", emitstring
+  dq swap, lit, 8, add, swap
+  dq dup, litstring, "lit", stringcmp, zbranch, 4*8
+  ; This is the non-lit branch.
+  dq drop, branch, -29*8
+  ; This is the lit branch.
+  dq drop, dup, fetch, emitinteger, litstring, " ", emitstring
+  dq lit, 8, add
+  dq branch, -41*8
+
 ;   Allocate space by incrementing "here", and output a word header in it.
 ; Also add it to the "latest" linked list. Use zero as the flag values;
 ; callers that want something else can do that themselves.