Modified stdlib to use stack rotations to timeshare heap registers.
[vvhitespace] / stdlib / debug.pvvs
... / ...
CommitLineData
1#ifndef VVS_STDLIB_DEBUG
2#define VVS_STDLIB_DEBUG
3
4@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
5@ Name:
6@ dumpheap (111000)
7@ Description:
8@ Dumps the heap from 'startaddr' to 'endaddr'.
9@ This subroutine stomps on heap[1] after printing the first heap location.
10@ If you dump starting from heap[0], then heap[1] will print inaccurately.
11@ Starting the dump from any other location will work without error.
12@ TODO: Should I use heap[0] and DIE rather than RTS?
13@ At the moment, the ability to continue is too useful to me.
14@ If it's useful to me, it's probably useful to other people.
15@ For now, leave dumpheap as-is.
16@ Call Stack:
17@ endaddr
18@ startaddr <-- TOS
19@ Return Stack:
20@ <empty>
21@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
22#include <stdio.pvvs>
23NSSVTTTSSSN | Mark: 111000 (dump heap)
24
25@ Prepare a numeric address and value on the stack
26SNS | DUP
27SNS | DUP
28TTT | LOAD
29SNT | SWAP
30
31@ Print output line for this memory location
32NSTTSSSSTTN | JSR>1000011 (print absolute value of number)
33SSSTTTSTSN | PUSH ASCII ':'
34SSSTSSTN | PUSH ASCII '\t'
35TNSS | PUTC
36TNSS | PUTC
37NSTTSSTN | JSR>1001 (print number from stack)
38SSSTSTSN | PUSH ASCII '\n'
39TNSS | PUTC
40
41@ Figure out if the loop is complete.
42SSSTN | PUSH 1 (ptr)
43SNT | SWAP
44TTS | STORE
45SNS | DUP
46SSSTN | PUSH 1 (ptr)
47TTT | LOAD
48TSST | SUBTRACT
49NTSSSTTTSSSSSSSSSSSN | BRZ > 00111000 00000000
50SSSTN | PUSH 1 (ptr)
51TTT | LOAD
52SSSTN | PUSH 1
53TSSS | ADD
54NSNTTTSSSN | JMP>111000 (dump heap)
55
56@ Clean up and return
57NSSVSSTTTSSSSSSSSSSSN | Mark: 00111000 00000000
58SNN | DROP
59NTN | RTS
60
61@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
62@ Name:
63@ dumpstack (111001)
64@ Description:
65@ Dumps 'count' entries from the stack.
66@ Call Stack:
67@ count <-- TOS
68@ Return Stack:
69@ <empty>
70@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
71#include <stdio.pvvs>
72NSSVTTTSSTN | Mark: 111001 (dump stack)
73
74@ Print output line for the current TOS.
75SNS | DUP
76NSTTSSSSTTN | JSR>1000011 (print absolute value of number)
77SSSTTTSTSN | PUSH ASCII ':'
78SSSTSSTN | PUSH ASCII '\t'
79TNSS | PUTC
80TNSS | PUTC
81SNT | SWAP
82NSTTSSTN | JSR>1001 (print number from stack)
83SSSTSTSN | PUSH ASCII '\n'
84TNSS | PUTC
85
86@ Figure out if the loop is complete.
87SNS | DUP
88NTSSSTTTSSTSSSSSSSSN | BRZ > 00111001 00000000
89SSSTN | PUSH 1
90TSST | SUBTRACT
91NSNTTTSSTN | JMP>111001 (dump stack)
92
93@ Clean up and return
94NSSVSSTTTSSTSSSSSSSSN | Mark: 00111001 00000000
95SNN | DROP
96NTN | RTS
97
98#endif