First draft of a real README for the VVS stdlib.
[vvhitespace] / stdlib / stdio.pvvs
index 54bb2ac..26171e6 100644 (file)
@@ -1,3 +1,6 @@
+@ (c) 2020 Aaron Taylor <ataylor at subgeniuskitty dot com>
+@ See LICENSE.txt file for copyright and license details.
+
 #ifndef VVS_STDLIB_STDIO
 #define VVS_STDLIB_STDIO
 
 #ifndef VVS_STDLIB_STDIO
 #define VVS_STDLIB_STDIO
 
@@ -97,8 +100,17 @@ NTN                     | RTS
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 #include <math.pvvs>
 NSSVTSSSSTTN            | Mark: 1000011 (print magnitude of number from stack)
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 #include <math.pvvs>
 NSSVTSSSSTTN            | Mark: 1000011 (print magnitude of number from stack)
-NSTTSSSTN               | JSR > 10001 (absolute value)
 
 
+@ Catch -(2^63) as a special case since its absolute value will overflow
+@ a twos-complement 64-bit word.
+SNS                     | DUP
+SSTTSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSN | -(2^63)
+TSST                    | SUBTRACT
+NTSSTSSSSTTSSSSSSTSN    | BRZ > 01000011 00000010
+
+@ No special case applies. Prepare for computation by converting the number
+@ to absolute value and preparing a string on the stack.
+NSTTSSSTN               | JSR > 10001 (absolute value)
 SSSSN                   | PUSH ASCII '\0'
 SNT                     | SWAP
 
 SSSSN                   | PUSH ASCII '\0'
 SNT                     | SWAP
 
@@ -126,6 +138,12 @@ SNN                     | DROP
 NSTTSSSTSSN             | JSR > 1000100 (print string from stack)
 NTN                     | RTS
 
 NSTTSSSTSSN             | JSR > 1000100 (print string from stack)
 NTN                     | RTS
 
+@ Replace the number on the stack with its decimal ASCII representation.
+NSSVSTSSSSTTSSSSSSTSN   | BRZ > 01000011 00000010
+SNN                     | DROP
+A"-9223372036854775808"
+NSNSTSSSSTTSSSSSSSTN    | JMP > 01000011 00000001
+
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @ Name:
 @   printf
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @ Name:
 @   printf
@@ -244,7 +262,7 @@ TSST                    | SUBTRACT
 NTSSSSSTSSSSSSSSTSSN    | BRZ > 00001000 00000100
 @ Check for ASCII '\t'
 SNS                     | DUP
 NTSSSSSTSSSSSSSSTSSN    | BRZ > 00001000 00000100
 @ Check for ASCII '\t'
 SNS                     | DUP
-SSSTSSTN                | PUSH ASCII '\t'
+SSSTTTSTSSN             | PUSH ASCII 't'
 TSST                    | SUBTRACT
 NTSSSSSTSSSSSSSSTSTN    | BRZ > 00001000 00000101
 @ No substitution necessary. Print literally.
 TSST                    | SUBTRACT
 NTSSSSSTSSSSSSSSTSTN    | BRZ > 00001000 00000101
 @ No substitution necessary. Print literally.
@@ -370,6 +388,7 @@ NSNSSSSTSSSSSSSSSSTN    | JMP > 00001000 00000001
 @ Found an ASCII "\0" when processing the format string. Clean up and exit.
 NSSVSSSSTSSSSSSSSSSSN   | Mark: 00001000 00000000
 SNN                     | DROP
 @ Found an ASCII "\0" when processing the format string. Clean up and exit.
 NSSVSSSSTSSSSSSSSSSSN   | Mark: 00001000 00000000
 SNN                     | DROP
+SNN                     | DROP
 NTN                     | RTS
 
 @ Move the next string character to TOS.
 NTN                     | RTS
 
 @ Move the next string character to TOS.