Added deepdup subroutine to VVS stdlib.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 26 Jul 2019 06:13:23 +0000 (23:13 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 26 Jul 2019 06:13:23 +0000 (23:13 -0700)
stdlib/README.md
stdlib/stack.pvvs

index e7ebedd..099a70e 100644 (file)
@@ -37,6 +37,7 @@ header comment for each function to learn the call and return stack.
            1001 ----- print number from stack       (stdio.pvvs)
            1010 ----- stackrotate                   (stack.pvvs)
            1011 ----- stackrotatereverse            (stack.pvvs)
            1001 ----- print number from stack       (stdio.pvvs)
            1010 ----- stackrotate                   (stack.pvvs)
            1011 ----- stackrotatereverse            (stack.pvvs)
+           1100 ----- deepdup                       (stack.pvvs)
          010xxx - math functions
           10000 ----- random                        (math.pvvs)
           10001 ----- absolute value                (math.pvvs)
          010xxx - math functions
           10000 ----- random                        (math.pvvs)
           10001 ----- absolute value                (math.pvvs)
@@ -63,8 +64,8 @@ header comment for each function to learn the call and return stack.
          111000 ----- dump heap                     (debug.pvvs)
          111001 ----- dump stack                    (debug.pvvs)
         1xxxxxx - reserved for less common entry points
          111000 ----- dump heap                     (debug.pvvs)
          111001 ----- dump stack                    (debug.pvvs)
         1xxxxxx - reserved for less common entry points
-        1000000 ----- slurp registers               (heap.pvvs)
-        1000001 ----- spew registers                (heap.pvvs)
+        1000000 ----- <empty>
+        1000001 ----- <empty>
         1000010 ----- print sign of number          (stdio.pvvs)
         1000011 ----- print magnitude of number     (stdio.pvvs)
         1000100 ----- print string from stack       (stdio.pvvs)
         1000010 ----- print sign of number          (stdio.pvvs)
         1000011 ----- print magnitude of number     (stdio.pvvs)
         1000100 ----- print string from stack       (stdio.pvvs)
index 0ef72bf..417b3bb 100644 (file)
@@ -210,5 +210,40 @@ TSSS                    | ADD
 TTT                     | LOAD
 NTN                     | RTS
 
 TTT                     | LOAD
 NTN                     | RTS
 
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+@ Name:
+@   deepdup
+@ Description:
+@   Duplicates an item deep on the stack, placing the duplicate on TOS.
+@   By default, maximum depth is 11.
+@   True maximum depth is (max depth of stackrotate & stackrotatereverse)-3.
+@ Call Stack:
+@   stack word n
+@   ...
+@   stack word 1
+@   dupdepth  <-- TOS
+@ Return Stack:
+@   stack word n
+@   ...
+@   stack word 1
+@   copy of stack word 3   <-- TOS
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+NSSVTTSSN               | Mark: 1100 (deepdup)
+
+@ Copy 'dupdepth' and use it to bring forth the desired stack word.
+SNS                     | DUP
+SSSTN                   | PUSH 1
+TSSS                    | ADD
+NSTTSTTN                | JSR > 1011 (stackrotatereverse)
+
+@ Copy the desired stack word and return it back into the stack.
+SNS                     | DUP
+SSSTTN                  | PUSH 3
+NSTTSTTN                | JSR > 1011 (stackrotatereverse)
+SSSTN                   | PUSH 1
+TSSS                    | ADD
+NSTTSTSN                | JSR > 1010 (stackrotate)
+NTN                     | RTS
+
 #endif
 
 #endif