summary refs log tree commit diff
path: root/quine.asm
diff options
context:
space:
mode:
Diffstat (limited to 'quine.asm')
-rw-r--r--quine.asm38
1 files changed, 38 insertions, 0 deletions
diff --git a/quine.asm b/quine.asm
index b47eb5a..3002cab 100644
--- a/quine.asm
+++ b/quine.asm
@@ -3035,6 +3035,26 @@ cold_start:
   dq litstring, "exit", early_find, entry_to_execution_token, early_comma
   dq early_here, fetch, lit, 8, packalign, early_here_store
 
+  ; This was "pack_raw_string".
+  dq litstring, "pack-raw-string", early_create, early_docol_codeword
+  dq litstring, "dup", early_find, entry_to_execution_token, early_comma
+  dq litstring, "stringlen", 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, 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
+  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, 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, entry_to_execution_token, early_comma
   dq litstring, "/%", early_find, entry_to_execution_token, early_comma
@@ -9539,6 +9559,24 @@ defword packstring, 0
   dq memcopy
   dq exit
 
+;   This also works on C-style strings, relying on the null terminator, but
+; the packed data does not include it.
+;
+; Stack in:
+;   base address, string pointer
+; Stack out:
+;   new base address
+defword pack_raw_string, 0
+  dq docol
+  dq dup, stringlen, dup
+  ; base/destination, source, length, length
+  dq lit, 4, roll, dup, lit, 4, unroll
+  ; source, destination, length, length, base/destination
+  dq add, lit, 4, unroll
+  ; new base, source, destination, length
+  dq memcopy
+  dq exit
+
 ; Stack in:
 ;   base address
 ;   byte size