X-Git-Url: http://git.subgeniuskitty.com/vvhitespace/.git/blobdiff_plain/ae1f85a178241c826a0b6a72ace12049b9907561..4fba07dca7fb9275b51e5095a774fe69eeab4660:/stdlib/debug.pvvs diff --git a/stdlib/debug.pvvs b/stdlib/debug.pvvs index 6328cf8..4114d22 100644 --- a/stdlib/debug.pvvs +++ b/stdlib/debug.pvvs @@ -1,19 +1,30 @@ #ifndef VVS_STDLIB_DEBUG #define VVS_STDLIB_DEBUG +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Some of the subroutines in this file duplicate other stdlib subroutines. +@ This is to avoid outside dependencies and allow debugging of stdlib code. +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ Name: @ dumpheap (111000) @ Description: @ Dumps the heap from 'startaddr' to 'endaddr'. -@ Call Stack: +@ This subroutine stomps on heap[1] after printing the first heap location. +@ If you dump starting from heap[0], then heap[1] will print inaccurately. +@ Starting the dump from any other location will work without error. +@ TODO: Should I use heap[0] and DIE rather than RTS? +@ At the moment, the ability to continue is too useful to me. +@ If it's useful to me, it's probably useful to other people. +@ For now, leave dumpheap as-is. +@ Call Stack: @ endaddr @ startaddr <-- TOS @ Return Stack: @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -#include -NSSVTTTSSSN | Mark: 111000 (dump heap) +NSSVTTTSSSN | Mark: 111000 (debug:dumpheap) @ Prepare a numeric address and value on the stack SNS | DUP @@ -22,12 +33,14 @@ TTT | LOAD SNT | SWAP @ Print output line for this memory location -NSTTSSSSTTN | JSR>1000011 (print absolute value of number) -SSSTTTSTSN | PUSH ASCII ':' +NSTTTTSTTN | JSR > 111011 (debug:printmagnitude) SSSTSSTN | PUSH ASCII '\t' +SSSTTTSTSN | PUSH ASCII ':' TNSS | PUTC TNSS | PUTC -NSTTSTSN | JSR>1010 (print number from stack) +SNS | DUP +NSTTTTSTSN | JSR > 111010 (debug:printsign) +NSTTTTSTTN | JSR > 111011 (debug:printmagnitude) SSSTSTSN | PUSH ASCII '\n' TNSS | PUTC @@ -44,7 +57,7 @@ SSSTN | PUSH 1 (ptr) TTT | LOAD SSSTN | PUSH 1 TSSS | ADD -NSNTTTSSSN | JMP>111000 (dump heap) +NSNTTTSSSN | JMP > 111000 (dump heap) @ Clean up and return NSSVSSTTTSSSSSSSSSSSN | Mark: 00111000 00000000 @@ -61,31 +74,151 @@ NTN | RTS @ Return Stack: @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -#include -NSSVTTTSSTN | Mark: 111001 (dump stack) +NSSVTTTSSTN | Mark: 111001 (debug:dumpstack) + +@ Orient the user +SSSSSSSSSN | PUSH ASCII '\0' +SSSSSSTSTSN | PUSH ASCII '\n' +SSSSTTTSTSN | PUSH ASCII ':' +SSSTSTSSTTN | PUSH ASCII 'S' +SSSTSSTTTTN | PUSH ASCII 'O' +SSSTSTSTSSN | PUSH ASCII 'T' +NSTTTTTSSN | JSR > 111100 (debug:printstring) @ Print output line for the current TOS. +NSSVSSTTTSSTSSSSSSSTN | Mark: 00111001 00000001 SNS | DUP -NSTTSSSSTTN | JSR>1000011 (print absolute value of number) -SSSTTTSTSN | PUSH ASCII ':' +NSTTTTSTTN | JSR > 111011 (debug:printmagnitude) SSSTSSTN | PUSH ASCII '\t' +SSSTTTSTSN | PUSH ASCII ':' TNSS | PUTC TNSS | PUTC SNT | SWAP -NSTTSTSN | JSR>1010 (print number from stack) +SNS | DUP +NSTTTTSTSN | JSR > 111010 (debug:printsign) +NSTTTTSTTN | JSR > 111011 (debug:printmagnitude) SSSTSTSN | PUSH ASCII '\n' TNSS | PUTC @ Figure out if the loop is complete. -SNS | DUP -NTSSSTTTSSTSSSSSSSSN | BRZ > 00111001 00000000 SSSTN | PUSH 1 TSST | SUBTRACT -NSNTTTSSTN | JMP>111001 (dump stack) +SNS | DUP +NTSSSTTTSSTSSSSSSSSN | BRZ > 00111001 00000000 +NSNSSTTTSSTSSSSSSSTN | JMP > 00111001 00000001 @ Clean up and return NSSVSSTTTSSTSSSSSSSSN | Mark: 00111001 00000000 SNN | DROP NTN | RTS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ printsign (111010) +@ Description: +@ Prints the sign of 'number'. +@ Call Stack: +@ number <-- TOS +@ Return Stack: +@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +NSSVTTTSTSN | Mark: 111010 (debug:printsign) +NTTSSTTTSTSSSSSSSSTN | BMI > 00111010 00000001 +SSSTSTSTTN | PUSH ASCII '+' +NSNSSTTTSTSSSSSSSTSN | JMP > 00111010 00000010 +NSSVSSTTTSTSSSSSSSSTN | Mark: 00111010 00000001 +SSSTSTTSTN | PUSH ASCII '-' +NSSVSSTTTSTSSSSSSSTSN | Mark: 00111010 00000010 +TNSS | PUTC +NTN | RTS + +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ printmagnitude (111011) +@ Description: +@ Prints the magnitude of 'number'. +@ Call Stack: +@ number <-- TOS +@ Return Stack: +@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +NSSVTTTSTTN | Mark: 111011 (debug:printmagnitude) + +@ Extract the magnitude of the number. +SNS | DUP +NTTSSTTTSTTSSSSSSSSN | BMI > 00111011 00000000 +NSNSSTTTSTTSSSSSSSTN | JMP > 00111011 00000001 +NSSVSSTTTSTTSSSSSSSSN | Mark: 00111011 00000000 +SSTTN | PUSH -1 +TSSN | MULTIPLY +NSSVSSTTTSTTSSSSSSSTN | Mark: 00111011 00000001 + +@ Prepare for building a string on the stack. +SSSSN | PUSH ASCII '\0' +SNT | SWAP + +@ Pick off one digit on each pass through this loop. +NSSVSSTTTSTTSSSSSSTSN | Mark: 00111011 00000010 +SNS | DUP + +@ Mod-off a digit, convert to ASCII, store on stack as part of the string. +SSSTSTSN | PUSH +10 +TSTT | MODULO +SSSTTSSSSN | PUSH ASCII '0' +TSSS | ADD +SNT | SWAP + +@ Divide down to next digit and keep looping if number != 0 yet. +SSSTSTSN | PUSH +10 +TSTS | DIVIDE +SNS | DUP +NTSSSTTTSTTSSSSSSTTN | BRZ > 00111011 00000011 +NSNSSTTTSTTSSSSSSTSN | JMP > 00111011 00000010 + +@ Print the string we have built on the stack. +NSSVSSTTTSTTSSSSSSTTN | Mark: 00111011 00000011 +SNN | DROP +NSTTTTTSSN | JSR > 111100 (debug:printstring) +NTN | RTS + +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ printstring (111100) +@ Description: +@ Prints a null-terminated string from the stack. +@ Call Stack: +@ null-terminator (ASCII '\0') +@ char n +@ ... +@ char 2 +@ char 1 <-- TOS +@ Return Stack: +@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +NSSVTTTTSSN | Mark: 111100 (debug:printstring) +SNS | DUP +NTSSSTTTTSSSSSSSSSTN | BRZ > 00111100 00000001 +TNSS | Print character +NSNTTTTSSN | JMP > 111100 +NSSVSSTTTTSSSSSSSSSTN | Mark: 00111100 00000001 +SNN | DROP +NTN | RTS + +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ printsignednumber (111101) +@ Description: +@ Prints 'number' from the stack in sign-magnitude format. +@ Leading zeros are suppressed. +@ Call Stack: +@ number <-- TOS +@ Return Stack: +@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +NSSVTTTTSTN | Mark: 111101 (debug:printsignednumber) +SNS | DUP +NSTTTTSTSN | JSR > 111010 (debug:printsign) +NSTTTTSTTN | JSR > 111011 (debug:printmagnitude) +NTN | RTS + #endif