diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-05-01 14:27:36 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-05-01 14:27:36 -0700 |
| commit | cb555fc1884824fc7c0e9de7cb3e04b61f623838 (patch) | |
| tree | a67827bb77348a9812aac0f23a42bb0f60b06f7e /quine.asm | |
| parent | 4334c11d934cd41f3804820515ff70edac291553 (diff) | |
this avoids the problem where there's no way to represent most entirely-full states because they would be the same as the empty states Force-Push: yes Change-Id: Ia38a57d756b62ad1c8301603cb9d9a99f2a1dbc4
Diffstat (limited to 'quine.asm')
| -rw-r--r-- | quine.asm | 108 |
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 |