Rearranging output in debug functions.
[vvhitespace] / stdlib / debug.pvvs
CommitLineData
1a56830d
AT
1#ifndef VVS_STDLIB_DEBUG
2#define VVS_STDLIB_DEBUG
3
9f7f68e5
AT
4@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
5@ Some of the subroutines in this file duplicate other stdlib subroutines.
6@ This is to avoid outside dependencies and allow debugging of stdlib code.
7@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
8
1a56830d 9@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bb21580a
AT
10@ Name:
11@ dumpheap (111000)
1a56830d 12@ Description:
bb21580a 13@ Dumps the heap from 'startaddr' to 'endaddr'.
6cb31a3e
AT
14@ This subroutine stomps on heap[1] after printing the first heap location.
15@ If you dump starting from heap[0], then heap[1] will print inaccurately.
16@ Starting the dump from any other location will work without error.
17@ TODO: Should I use heap[0] and DIE rather than RTS?
18@ At the moment, the ability to continue is too useful to me.
19@ If it's useful to me, it's probably useful to other people.
20@ For now, leave dumpheap as-is.
9f7f68e5 21@ Call Stack:
1a56830d
AT
22@ endaddr
23@ startaddr <-- TOS
24@ Return Stack:
25@ <empty>
26@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
27NSSVTTTSSSN | Mark: 111000 (dump heap)
28
29@ Prepare a numeric address and value on the stack
30SNS | DUP
31SNS | DUP
32TTT | LOAD
33SNT | SWAP
34
35@ Print output line for this memory location
9f7f68e5 36NSTTTTSTTN | JSR > 111011 (debug:printmagnitude)
1a56830d 37SSSTSSTN | PUSH ASCII '\t'
c6e2791f 38SSSTTTSTSN | PUSH ASCII ':'
1a56830d
AT
39TNSS | PUTC
40TNSS | PUTC
9f7f68e5
AT
41SNS | DUP
42NSTTTTSTSN | JSR > 111010 (debug:printsign)
43NSTTTTSTTN | JSR > 111011 (debug:printmagnitude)
1a56830d
AT
44SSSTSTSN | PUSH ASCII '\n'
45TNSS | PUTC
46
47@ Figure out if the loop is complete.
bb21580a 48SSSTN | PUSH 1 (ptr)
1a56830d
AT
49SNT | SWAP
50TTS | STORE
51SNS | DUP
bb21580a 52SSSTN | PUSH 1 (ptr)
1a56830d
AT
53TTT | LOAD
54TSST | SUBTRACT
55NTSSSTTTSSSSSSSSSSSN | BRZ > 00111000 00000000
bb21580a 56SSSTN | PUSH 1 (ptr)
1a56830d
AT
57TTT | LOAD
58SSSTN | PUSH 1
59TSSS | ADD
9f7f68e5 60NSNTTTSSSN | JMP > 111000 (dump heap)
1a56830d
AT
61
62@ Clean up and return
63NSSVSSTTTSSSSSSSSSSSN | Mark: 00111000 00000000
64SNN | DROP
65NTN | RTS
66
ae1f85a1
AT
67@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
68@ Name:
69@ dumpstack (111001)
70@ Description:
71@ Dumps 'count' entries from the stack.
72@ Call Stack:
73@ count <-- TOS
74@ Return Stack:
75@ <empty>
76@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ae1f85a1
AT
77NSSVTTTSSTN | Mark: 111001 (dump stack)
78
9f7f68e5
AT
79@ Orient the user
80SSSSSSSSSN | PUSH ASCII '\0'
81SSSSSSTSTSN | PUSH ASCII '\n'
82SSSSTTTSTSN | PUSH ASCII ':'
83SSSTSTSSTTN | PUSH ASCII 'S'
84SSSTSSTTTTN | PUSH ASCII 'O'
85SSSTSTSTSSN | PUSH ASCII 'T'
86NSTTTTTSSN | JSR > 111100 (debug:printstring)
87
ae1f85a1 88@ Print output line for the current TOS.
9f7f68e5 89NSSVSSTTTSSTSSSSSSSTN | Mark: 00111001 00000001
ae1f85a1 90SNS | DUP
9f7f68e5 91NSTTTTSTTN | JSR > 111011 (debug:printmagnitude)
ae1f85a1 92SSSTSSTN | PUSH ASCII '\t'
c6e2791f 93SSSTTTSTSN | PUSH ASCII ':'
ae1f85a1
AT
94TNSS | PUTC
95TNSS | PUTC
96SNT | SWAP
9f7f68e5
AT
97SNS | DUP
98NSTTTTSTSN | JSR > 111010 (debug:printsign)
99NSTTTTSTTN | JSR > 111011 (debug:printmagnitude)
ae1f85a1
AT
100SSSTSTSN | PUSH ASCII '\n'
101TNSS | PUTC
102
103@ Figure out if the loop is complete.
104SNS | DUP
105NTSSSTTTSSTSSSSSSSSN | BRZ > 00111001 00000000
106SSSTN | PUSH 1
107TSST | SUBTRACT
9f7f68e5 108NSNSSTTTSSTSSSSSSSTN | JMP > 00111001 00000001
ae1f85a1
AT
109
110@ Clean up and return
111NSSVSSTTTSSTSSSSSSSSN | Mark: 00111001 00000000
112SNN | DROP
113NTN | RTS
114
9f7f68e5
AT
115@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
116@ Name:
117@ printsign (111010)
118@ Description:
119@ Prints the sign of 'number'.
120@ Call Stack:
121@ number <-- TOS
122@ Return Stack:
123@ <empty>
124@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
125NSSVTTTSTSN | Mark: 111010 (debug:printsign)
126NTTSSTTTSTSSSSSSSSTN | BMI > 00111010 00000001
127SSSTSTSTTN | PUSH ASCII '+'
128NSNSSTTTSTSSSSSSSTSN | JMP > 00111010 00000010
129NSSVSSTTTSTSSSSSSSSTN | Mark: 00111010 00000001
130SSSTSTTSTN | PUSH ASCII '-'
131NSSVSSTTTSTSSSSSSSTSN | Mark: 00111010 00000010
132TNSS | PUTC
133NTN | RTS
134
135@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
136@ Name:
137@ printmagnitude (111011)
138@ Description:
139@ Prints the magnitude of 'number'.
140@ Call Stack:
141@ number <-- TOS
142@ Return Stack:
143@ <empty>
144@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
145NSSVTTTSTTN | Mark: 111011 (debug:printmagnitude)
146
147@ Extract the magnitude of the number.
148SNS | DUP
149NTTSSTTTSTTSSSSSSSSN | BMI > 00111011 00000000
150NSNSSTTTSTTSSSSSSSTN | JMP > 00111011 00000001
151NSSVSSTTTSTTSSSSSSSSN | Mark: 00111011 00000000
152SSTTN | PUSH -1
153TSSN | MULTIPLY
154NSSVSSTTTSTTSSSSSSSTN | Mark: 00111011 00000001
155
156@ Prepare for building a string on the stack.
157SSSSN | PUSH ASCII '\0'
158SNT | SWAP
159
160@ Pick off one digit on each pass through this loop.
161NSSVSSTTTSTTSSSSSSTSN | Mark: 00111011 00000010
162SNS | DUP
163
164@ Mod-off a digit, convert to ASCII, store on stack as part of the string.
165SSSTSTSN | PUSH +10
166TSTT | MODULO
167SSSTTSSSSN | PUSH ASCII '0'
168TSSS | ADD
169SNT | SWAP
170
171@ Divide down to next digit and keep looping if number != 0 yet.
172SSSTSTSN | PUSH +10
173TSTS | DIVIDE
174SNS | DUP
175NTSSSTTTSTTSSSSSSTTN | BRZ > 00111011 00000011
176NSNSSTTTSTTSSSSSSTSN | JMP > 00111011 00000010
177
178@ Print the string we have built on the stack.
179NSSVSSTTTSTTSSSSSSTTN | Mark: 00111011 00000011
180SNN | DROP
181NSTTTTTSSN | JSR > 111100 (debug:printstring)
182NTN | RTS
183
184@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
185@ Name:
186@ printstring (111100)
187@ Description:
188@ Prints a null-terminated string from the stack.
189@ Call Stack:
190@ null-terminator (ASCII '\0')
191@ char n
192@ ...
193@ char 2
194@ char 1 <-- TOS
195@ Return Stack:
196@ <empty>
197@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
198NSSVTTTTSSN | Mark: 111100 (debug:printstring)
199SNS | DUP
200NTSSSTTTTSSSSSSSSSTN | BRZ > 00111100 00000001
201TNSS | Print character
202NSNTTTTSSN | JMP > 111100
203NSSVSSTTTTSSSSSSSSSTN | Mark: 00111100 00000001
204SNN | DROP
205NTN | RTS
206
1a56830d 207#endif