summary refs log tree commit diff
path: root/quine.asm
diff options
context:
space:
mode:
Diffstat (limited to 'quine.asm')
-rw-r--r--quine.asm108
1 files changed, 55 insertions, 53 deletions
diff --git a/quine.asm b/quine.asm
index 4e30307..806616b 100644
--- a/quine.asm
+++ b/quine.asm
@@ -6101,8 +6101,8 @@ cold_start:
   ; In:
   ;   pointer to buffer metadata
   ; Out:
-  ;   pointer to buffer "physical-end" field
-  dq litstring, "buffer-physical-end", early_create, early_docol_codeword
+  ;   pointer to buffer "physical-length" field
+  dq litstring, "buffer-physical-length", early_create, early_docol_codeword
   dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 8, early_comma
   dq litstring, "+", early_find, entry_to_execution_token, early_comma
@@ -6123,8 +6123,8 @@ cold_start:
   ; In:
   ;   pointer to buffer metadata
   ; Out:
-  ;   pointer to buffer "logical-end" field
-  dq litstring, "buffer-logical-end", early_create, early_docol_codeword
+  ;   pointer to buffer "logical-length" field
+  dq litstring, "buffer-logical-length", early_create, early_docol_codeword
   dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 3*8, early_comma
   dq litstring, "+", early_find, entry_to_execution_token, early_comma
@@ -6142,10 +6142,10 @@ cold_start:
   dq litstring, "exit", early_find, entry_to_execution_token, early_comma
   dq early_here, fetch, lit, 8, packalign, early_here_store
 
-  ;   Given an initialized buffer (input or otherwise), sets its "start" and
-  ; "end" pointers to indicate the buffer is empty. This relies on the buffer
-  ; having a backing store attached, but does not alter the backing store or
-  ; its contents.
+  ;   Given an initialized buffer (input or otherwise), sets its logical-start
+  ; and logical-length fields to indicate the buffer is empty. This relies on
+  ; the buffer having a backing store attached, but does not alter the backing
+  ; store or its contents.
   ;
   ; In:
   ;   pointer to buffer metadata
@@ -6154,18 +6154,19 @@ cold_start:
   dq litstring, "buffer-physical-start", early_find, entry_to_execution_token
   dq 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, "3roll", early_find, entry_to_execution_token, early_comma
-  ; (address of backing store, address of backing store, metadata pointer)
+  dq litstring, "swap", early_find, entry_to_execution_token, early_comma
+  ; (address of backing store, metadata pointer)
   dq litstring, "dup", early_find, entry_to_execution_token, early_comma
   dq litstring, "3unroll", early_find, entry_to_execution_token, early_comma
-  ; (address of backing store, metadata pointer,
-  ;  address of backing store, metadata pointer)
+  ; (metadata pointer, address of backing store, metadata pointer)
   dq litstring, "buffer-logical-start", early_find, entry_to_execution_token
   dq early_comma
   dq litstring, "!", early_find, entry_to_execution_token, early_comma
-  dq litstring, "buffer-logical-end", early_find, entry_to_execution_token
+  dq litstring, "buffer-logical-length", early_find, entry_to_execution_token
   dq early_comma
+  dq litstring, "lit", early_find, entry_to_execution_token, early_comma
+  dq lit, 0, early_comma
+  dq litstring, "swap", early_find, entry_to_execution_token, 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
@@ -6186,7 +6187,7 @@ cold_start:
   dq litstring, "swap", early_find, entry_to_execution_token, 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, "buffer-physical-end", early_find, entry_to_execution_token
+  dq litstring, "buffer-physical-length", early_find, entry_to_execution_token
   dq early_comma
   dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 0, early_comma
@@ -6200,7 +6201,7 @@ cold_start:
   dq litstring, "swap", early_find, entry_to_execution_token, 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, "buffer-logical-end", early_find, entry_to_execution_token
+  dq litstring, "buffer-logical-length", early_find, entry_to_execution_token
   dq early_comma
   dq litstring, "lit", early_find, entry_to_execution_token, early_comma
   dq lit, 0, early_comma
@@ -6264,13 +6265,14 @@ cold_start:
   dq early_comma
   dq litstring, "!", early_find, entry_to_execution_token, early_comma
   ; (capacity in bytes, metadata pointer, physical start)
-  dq litstring, "3roll", early_find, entry_to_execution_token, early_comma
-  dq litstring, "+", early_find, entry_to_execution_token, 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
-  ; (metadata pointer, physical end, metadata pointer)
-  dq litstring, "buffer-physical-end", early_find, entry_to_execution_token
+  dq litstring, "buffer-logical-start", early_find, entry_to_execution_token
+  dq early_comma
+  dq litstring, "!", early_find, entry_to_execution_token, early_comma
+  ; (capacity in bytes, metadata pointer)
+  dq litstring, "buffer-physical-length", early_find, entry_to_execution_token
   dq early_comma
   dq litstring, "!", early_find, entry_to_execution_token, early_comma
   ; (metadata pointer)
@@ -6301,17 +6303,15 @@ cold_start:
   dq litstring, "!", early_find, entry_to_execution_token, early_comma
   ; (string pointer, metadata pointer)
   dq litstring, "swap", early_find, entry_to_execution_token, 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, "+", early_find, entry_to_execution_token, early_comma
   dq litstring, "swap", early_find, entry_to_execution_token, early_comma
-  ; (string end pointer, metadata pointer)
+  ; (string length, metadata pointer)
   dq litstring, "2dup", early_find, entry_to_execution_token, early_comma
-  dq litstring, "buffer-physical-end", early_find, entry_to_execution_token
+  dq litstring, "buffer-physical-length", early_find, entry_to_execution_token
   dq early_comma
   dq litstring, "!", early_find, entry_to_execution_token, early_comma
-  ; (string end pointer, metadata pointer)
-  dq litstring, "buffer-logical-end", early_find, entry_to_execution_token
+  ; (string length, metadata pointer)
+  dq litstring, "buffer-logical-length", early_find, entry_to_execution_token
   dq early_comma
   dq litstring, "!", early_find, entry_to_execution_token, early_comma
   dq litstring, "exit", early_find, entry_to_execution_token, early_comma
@@ -6363,21 +6363,16 @@ cold_start:
   dq litstring, "main-input-buffer", early_find, entry_to_execution_token
   dq early_comma
   dq litstring, "dup", early_find, entry_to_execution_token, early_comma
-  dq litstring, "buffer-logical-start", early_find, entry_to_execution_token
+  dq litstring, "buffer-logical-length", early_find, entry_to_execution_token
   dq early_comma
   dq litstring, "@", early_find, entry_to_execution_token, 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, "buffer-logical-end", early_find, entry_to_execution_token
-  dq early_comma
-  dq litstring, "@", early_find, entry_to_execution_token, early_comma
-  dq litstring, "swap", early_find, entry_to_execution_token, early_comma
-  dq litstring, "3unroll", 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, "=", early_find, entry_to_execution_token, early_comma
   dq litstring, "0branch", early_find, entry_to_execution_token, early_comma
   dq lit, 5*8, early_comma
 
-  ; If the start and end pointers are equal, there is no input; return zero.
+  ; If the length is zero, there is no input; return zero.
   ; TODO This would also be the place to call the "refill" word.
   ; (metadata pointer)
   dq litstring, "drop", early_find, entry_to_execution_token, early_comma
@@ -6393,6 +6388,20 @@ cold_start:
   dq litstring, "@", early_find, entry_to_execution_token, early_comma
   dq litstring, "unpack8", early_find, entry_to_execution_token, early_comma
   ; (metadata pointer, updated input pointer, result byte)
+  ; Decrement the logical length.
+  dq litstring, "3roll", early_find, entry_to_execution_token, early_comma
+  dq litstring, "dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "buffer-logical-length", early_find, entry_to_execution_token
+  dq early_comma
+  dq litstring, "dup", 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, 1, early_comma
+  dq litstring, "-", early_find, entry_to_execution_token, early_comma
+  dq litstring, "swap", early_find, entry_to_execution_token, early_comma
+  dq litstring, "!", early_find, entry_to_execution_token, early_comma
+  dq litstring, "3unroll", early_find, entry_to_execution_token, early_comma
+  ; (metadata pointer, updated input pointer, result byte)
   dq litstring, "swap", 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
@@ -6404,31 +6413,25 @@ cold_start:
   dq litstring, "3unroll", early_find, entry_to_execution_token, early_comma
   ; (result byte, updated input pointer, metadata pointer,
   ;  updated input pointer, metadata pointer)
-  dq litstring, "buffer-physical-end", early_find, entry_to_execution_token
+  dq litstring, "dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "buffer-physical-start", early_find, entry_to_execution_token
+  dq early_comma
+  dq litstring, "@", early_find, entry_to_execution_token, early_comma
+  dq litstring, "swap", early_find, entry_to_execution_token, early_comma
+  dq litstring, "buffer-physical-length", early_find, entry_to_execution_token
   dq early_comma
   dq litstring, "@", early_find, entry_to_execution_token, early_comma
+  dq litstring, "+", early_find, entry_to_execution_token, early_comma
+  ; (result byte, updated input pointer, metadata pointer,
+  ;  updated input pointer, physical end pointer)
   dq litstring, "=", early_find, entry_to_execution_token, early_comma
   dq litstring, "0branch", early_find, entry_to_execution_token, early_comma
-  dq lit, 13*8, early_comma
+  dq lit, 7*8, early_comma
 
   ; If the logical start pointer is now equal to the physical end pointer,
   ; we want to wrap to the physical start. That's what makes it a circular
   ; buffer.
-  ;
-  ; However, we skip over this behavior if the logical start is also equal to
-  ; the logical end. Otherwise it would loop forever, re-reading the same
-  ; input.
-  ; (result byte, updated input pointer, metadata pointer)
-  dq litstring, "2dup", early_find, entry_to_execution_token, early_comma
-  dq litstring, "buffer-logical-end", early_find, entry_to_execution_token
-  dq early_comma
-  dq litstring, "@", early_find, entry_to_execution_token, early_comma
-  dq litstring, "!=", early_find, entry_to_execution_token, early_comma
-  dq litstring, "0branch", early_find, entry_to_execution_token, early_comma
-  dq lit, 7*8, early_comma
-
   ; (result byte, updated input pointer, metadata pointer)
-  ; Here's the part where we swap in the physical start.
   dq litstring, "swap", early_find, entry_to_execution_token, early_comma
   dq litstring, "drop", early_find, entry_to_execution_token, early_comma
   dq litstring, "dup", early_find, entry_to_execution_token, early_comma
@@ -6436,9 +6439,8 @@ cold_start:
   dq early_comma
   dq litstring, "@", early_find, entry_to_execution_token, early_comma
   dq litstring, "swap", early_find, entry_to_execution_token, early_comma
-  ; Fall through to the other half of both branches.
 
-  ; However we got here, save the updated logical end pointer.
+  ; However we got here, save the updated logical start pointer.
   ; (result byte, updated input pointer, metadata pointer)
   dq litstring, "buffer-logical-start", early_find, entry_to_execution_token
   dq early_comma