diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-05-04 02:19:50 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-05-04 02:19:50 -0700 |
| commit | 8242abf31c9c0c2bad87514cf69f610bf67c4411 (patch) | |
| tree | e6fdd5a47c1de9c3268d178a22a901a5c4646971 /quine.asm | |
| parent | bd4fa17e0c0a8550ea5e66d787e94eeba3e95ba3 (diff) | |
hexadecimal literals are implemented!
yay they use C-style syntax. also, the number lexing code is better organized now. Force-Push: yes Change-Id: Ibe28ba553e4970e76eb562dddd4e2387ba0090f4
Diffstat (limited to 'quine.asm')
| -rw-r--r-- | quine.asm | 374 |
1 files changed, 332 insertions, 42 deletions
diff --git a/quine.asm b/quine.asm index 6208f85..a2eff4a 100644 --- a/quine.asm +++ b/quine.asm @@ -6968,98 +6968,277 @@ cold_start: ; In: - ; string pointer + ; character ; Out: - ; result (if successful) - ; error indicator (zero indicates success) - dq litstring, "read-decimal-unsigned", early_create, early_docol_codeword - - ; If the first byte is null, this is an error - dq litstring, "unpack8", early_find, entry_to_execution_token, early_comma + ; 1 for true, 0 for false + dq litstring, "is-alphanumeric", early_create, early_docol_codeword dq litstring, "dup", 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 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, 6*8, early_comma + dq lit, 5*8, early_comma + + ; Less than "0". dq litstring, "drop", 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, "exit", 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, "9", 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 + + ; Less than or equal to "9". dq litstring, "drop", 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, "exit", early_find, entry_to_execution_token, early_comma - ; If the first byte is less than "0", this is an error. dq litstring, "dup", 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 lit, "A", 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, 6*8, early_comma + dq lit, 5*8, early_comma + + ; Less than "A". dq litstring, "drop", 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, "exit", 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, "Z", 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 + + ; Less than or equal to "Z". dq litstring, "drop", 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, "exit", early_find, entry_to_execution_token, early_comma - ; If the first byte is greater than "9", this is an error. dq litstring, "dup", early_find, entry_to_execution_token, early_comma dq litstring, "lit", early_find, entry_to_execution_token, early_comma - dq lit, "9", early_comma - dq litstring, "<", early_find, entry_to_execution_token, early_comma + dq lit, "a", 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, 6*8, early_comma + dq lit, 5*8, early_comma + + ; Less than "a". dq litstring, "drop", 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, "exit", 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, "z", 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 + + ; Less than or equal to "z". dq litstring, "drop", 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, "exit", early_find, entry_to_execution_token, early_comma - ; The first byte is a valid digit, so let's get started. + ; Greater than "z". + dq litstring, "drop", 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, "exit", early_find, entry_to_execution_token, early_comma + dq early_here, fetch, lit, 8, packalign, early_here_store + + + ; In: + ; character + ; Out: + ; value + dq litstring, "generalized-digit-value", early_create, early_docol_codeword + + dq litstring, "dup", early_find, entry_to_execution_token, early_comma + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, "a", 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, 8*8, early_comma + + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, "a", 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, 10, early_comma + dq litstring, "+", early_find, entry_to_execution_token, early_comma + dq litstring, "exit", 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, "A", 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, 8*8, early_comma + + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, "A", 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, 10, early_comma + dq litstring, "+", early_find, entry_to_execution_token, early_comma + dq litstring, "exit", 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, "exit", early_find, entry_to_execution_token, early_comma + dq early_here, fetch, lit, 8, packalign, early_here_store + + + ; In: + ; character + ; base + ; Out: + ; value (if successful) + ; error indicator (zero indicates success) + dq litstring, "decode-generalized-digit", 0, early_create + dq early_docol_codeword dq litstring, "swap", early_find, entry_to_execution_token, early_comma - ; (result so far, current point in string) + dq litstring, "dup", early_find, entry_to_execution_token, early_comma + dq litstring, "is-alphanumeric", early_find, entry_to_execution_token + dq early_comma + dq litstring, "0branch", early_find, entry_to_execution_token, early_comma + dq lit, 14*8, early_comma - ; Start of the loop. + ; It's alphanumeric. + ; (base, character) + dq litstring, "generalized-digit-value", early_find + dq entry_to_execution_token, early_comma + ; (base, value) + dq litstring, "dup", early_find, entry_to_execution_token, early_comma + dq litstring, "3roll", early_find, entry_to_execution_token, early_comma + ; (value, value, base) + dq litstring, ">", early_find, entry_to_execution_token, early_comma + dq litstring, "0branch", early_find, entry_to_execution_token, early_comma + dq lit, 4*8, early_comma + + ; It's in range. + ; (value) + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, 0, early_comma + dq litstring, "exit", early_find, entry_to_execution_token, early_comma + + ; It's out of range. + ; (value) + dq litstring, "drop", 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, "exit", early_find, entry_to_execution_token, early_comma + + ; It's not alphanumeric. + ; (base, character) + dq litstring, "drop", early_find, entry_to_execution_token, early_comma + dq litstring, "drop", 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, "exit", early_find, entry_to_execution_token, early_comma + dq early_here, fetch, lit, 8, packalign, early_here_store + + + ; In: + ; string pointer + ; base + ; Out: + ; result (if successful) + ; error indicator (zero indicates success) + dq litstring, "read-base-unsigned", early_create, early_docol_codeword + dq litstring, "swap", early_find, entry_to_execution_token, early_comma + + ; If the first byte is null, this is an error dq litstring, "unpack8", early_find, entry_to_execution_token, early_comma + ; (numeric base, current point in string, character) dq litstring, "dup", 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, 7*8, early_comma + dq litstring, "drop", early_find, entry_to_execution_token, early_comma + dq litstring, "drop", early_find, entry_to_execution_token, early_comma + dq litstring, "drop", 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, "exit", early_find, entry_to_execution_token, early_comma + + ; Decode the first byte as a generalized digit in the base. + ; (numeric base, current point in string, character) + ; If the first byte is less than "0", this is an error. + dq litstring, "3roll", 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, "unroll", early_find, entry_to_execution_token, early_comma + ; (numeric base, current point in string, character, numeric base) + dq litstring, "decode-generalized-digit", 0, early_find + dq entry_to_execution_token, early_comma + dq litstring, "0branch", early_find, entry_to_execution_token, early_comma dq lit, 6*8, early_comma - ; A null after the first character is valid, and indicates we're done. + ; (numeric base, current point in string) dq litstring, "drop", early_find, entry_to_execution_token, early_comma dq litstring, "drop", 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 lit, 1, early_comma dq litstring, "exit", early_find, entry_to_execution_token, early_comma - ; If the latest character is less than "0", that's an error. - ; (result so far, current point in string, latest byte) + ; The first byte is a valid generalized digit in the appropriate base, so + ; let's get started. + ; (numeric base, current point in string, initial value) + dq litstring, "swap", early_find, entry_to_execution_token, early_comma + + ; Start of the loop. + ; (numeric base, result so far, current point in string) + dq litstring, "unpack8", 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, "0", early_comma - dq litstring, ">", 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, 7*8, early_comma + dq lit, 8*8, early_comma + + ; A null after the first character is valid, and indicates we're done. dq litstring, "drop", early_find, entry_to_execution_token, early_comma dq litstring, "drop", early_find, entry_to_execution_token, early_comma + dq litstring, "swap", early_find, entry_to_execution_token, early_comma dq litstring, "drop", 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 lit, 0, early_comma dq litstring, "exit", early_find, entry_to_execution_token, early_comma - ; If the latest character is greater than "9", that's an error. - ; (result so far, current point in string, latest byte) + ; Decode the latest byte as a generalized digit in the base. + ; (numeric base, result so far, current point in string, latest byte) + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, 4, 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, "9", early_comma - dq litstring, "<", early_find, entry_to_execution_token, early_comma + dq lit, 5, early_comma + dq litstring, "unroll", early_find, entry_to_execution_token, early_comma + ; (numeric base, result so far, current point in string, character + ; numeric base) + dq litstring, "decode-generalized-digit", 0, early_find + dq entry_to_execution_token, early_comma dq litstring, "0branch", early_find, entry_to_execution_token, early_comma dq lit, 7*8, early_comma + + ; If the latest character is not a valid digit, that's an error. + ; (numeric base, result so far, current point in string) dq litstring, "drop", early_find, entry_to_execution_token, early_comma dq litstring, "drop", early_find, entry_to_execution_token, early_comma dq litstring, "drop", early_find, entry_to_execution_token, early_comma @@ -7067,23 +7246,83 @@ cold_start: dq lit, 1, early_comma dq litstring, "exit", early_find, entry_to_execution_token, early_comma - ; (result so far, current point in string, latest byte) - 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 + ; The latest character is valid, so incorporate it and loop. + ; (numeric base, result so far, current point in string, latest value) dq litstring, "3roll", early_find, entry_to_execution_token, early_comma dq litstring, "lit", early_find, entry_to_execution_token, early_comma - dq lit, 10, early_comma + dq lit, 4, 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, entry_to_execution_token, early_comma dq litstring, "*", 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, "branch", early_find, entry_to_execution_token, early_comma - dq lit, -46*8, early_comma + dq lit, -42*8, early_comma dq early_here, fetch, lit, 8, packalign, early_here_store - dq litstring, "read-decimal", early_create, early_docol_codeword + ; In: + ; string pointer + ; Out: + ; result (if successful) + ; error indicator (zero indicates success) + dq litstring, "read-integer-unsigned", early_create, early_docol_codeword + dq litstring, "dup", early_find, entry_to_execution_token, early_comma + dq litstring, "unpack8", 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, 6*8, early_comma + + ; This is the case where the leading digit is not a zero. + ; (original string pointer, advanced string pointer) + dq litstring, "drop", early_find, entry_to_execution_token, early_comma + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, 10, early_comma + dq litstring, "read-base-unsigned", early_find, entry_to_execution_token + dq early_comma + dq litstring, "exit", early_find, entry_to_execution_token, early_comma + + ; This is the case where the leading digit is a zero. + ; (original string pointer, advanced string pointer) + dq litstring, "unpack8", early_find, entry_to_execution_token, early_comma + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, "x", 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 + + ; This is the case where the second character is equal to "x". + ; (original string pointer, doubly advanced string pointer) + dq litstring, "swap", early_find, entry_to_execution_token, early_comma + dq litstring, "drop", early_find, entry_to_execution_token, early_comma + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, 16, early_comma + dq litstring, "read-base-unsigned", early_find, entry_to_execution_token + dq early_comma + dq litstring, "exit", early_find, entry_to_execution_token, early_comma + + ; This is the case where the second character is something else. + ; (original string pointer, doubly advanced string pointer) + dq litstring, "drop", early_find, entry_to_execution_token, early_comma + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, 10, early_comma + dq litstring, "read-base-unsigned", early_find, entry_to_execution_token + dq early_comma + dq litstring, "exit", early_find, entry_to_execution_token, early_comma + + + ; In: + ; string pointer + ; Out: + ; result (if successful) + ; error indicator (zero indicates success) + dq litstring, "read-integer", early_create, early_docol_codeword dq litstring, "dup", early_find, entry_to_execution_token, early_comma dq litstring, "unpack8", early_find, entry_to_execution_token, early_comma dq litstring, "lit", early_find, entry_to_execution_token, early_comma @@ -7095,7 +7334,7 @@ cold_start: ; This is the case where it's non-negative. ; (original string pointer, advanced string pointer) dq litstring, "drop", early_find, entry_to_execution_token, early_comma - dq litstring, "read-decimal-unsigned", early_find, entry_to_execution_token + dq litstring, "read-integer-unsigned", early_find, entry_to_execution_token dq early_comma dq litstring, "exit", early_find, entry_to_execution_token, early_comma @@ -7103,7 +7342,58 @@ cold_start: ; (original string pointer, advanced string pointer) dq litstring, "swap", early_find, entry_to_execution_token, early_comma dq litstring, "drop", early_find, entry_to_execution_token, early_comma - dq litstring, "read-decimal-unsigned", early_find, entry_to_execution_token + dq litstring, "read-integer-unsigned", early_find, entry_to_execution_token + dq early_comma + ; (result maybe, exit code) + dq litstring, "dup", early_find, entry_to_execution_token, early_comma + dq litstring, "0branch", early_find, entry_to_execution_token, early_comma + dq lit, 2*8, early_comma + + ; Failure + ; (non-zero exit code) + dq litstring, "exit", early_find, entry_to_execution_token, early_comma + + ; Success + ; (result, zero exit code) + dq litstring, "swap", 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, "exit", early_find, entry_to_execution_token, early_comma + dq early_here, fetch, lit, 8, packalign, early_here_store + + + ; In: + ; string pointer + ; Out: + ; result (if successful) + ; error indicator (zero indicates success) + dq litstring, "read-decimal", early_create, early_docol_codeword + dq litstring, "dup", early_find, entry_to_execution_token, early_comma + dq litstring, "unpack8", early_find, entry_to_execution_token, early_comma + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, "-", 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, 6*8, early_comma + + ; This is the case where it's non-negative. + ; (original string pointer, advanced string pointer) + dq litstring, "drop", early_find, entry_to_execution_token, early_comma + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, 10, early_comma + dq litstring, "read-base-unsigned", early_find, entry_to_execution_token + dq early_comma + dq litstring, "exit", early_find, entry_to_execution_token, early_comma + + ; This is the case where it's negative. + ; (original string pointer, advanced string pointer) + dq litstring, "swap", early_find, entry_to_execution_token, early_comma + dq litstring, "drop", early_find, entry_to_execution_token, early_comma + dq litstring, "lit", early_find, entry_to_execution_token, early_comma + dq lit, 10, early_comma + dq litstring, "read-base-unsigned", early_find, entry_to_execution_token dq early_comma ; (result maybe, exit code) dq litstring, "dup", early_find, entry_to_execution_token, early_comma @@ -7337,7 +7627,7 @@ cold_start: ; As before, we get the stack address and use it as a string pointer. ; (string) dq litstring, "value@", early_find, entry_to_execution_token, early_comma - dq litstring, "read-decimal", early_find, entry_to_execution_token + dq litstring, "read-integer", 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 |