At 04:28 PM 3/15/2002 -0500, Dan Sugalski wrote:
>At 4:01 PM -0500 3/15/02, Clinton A. Pierce wrote:
>>I'm in the midst of writing some routines to debug pasm code, and one of
>>the things I dearly want is a "stack dump" routine. I can *almost* code
>>this in pasm, except I'm missing one last component: a way to tell the
>>depth of the stack without causing the runtime to bail.
>>
>>Any of the following would help:
>>
>>1. a rotate_up() that doesn't take an argument, instead the WHOLE stack
>>rotates.
>>
>>2. an opcode that will tell me the stack depth
>>
>>3. A mod to rotate_up or entrytype that lets me start indexing from the
>>*bottom* of the stack.
>>
>>4. some way of harmlessly catching the internal error "Stack Depth Wrong"
>>
>>[I'm not subscribed to p6i, cc me if you can otherwise I'll catch it in
>>archives. Thanks.]
>
>#4 needs to go in when we put in exceptions. Other than that... which do
>you want? They're all reasonable, and while I don't want to do all of
>them, any one of #s 1-3 are fine.
#3 is a can of worms best not opened, I think.
#2 on CPU's that I'm familiar with is usually done by querying the stack
pointer register. In parrotish:
set I0, SP
dec I0
set SP, I0 # For a pop-without-a-target-register kind of action.
Dunno if that's the kind of design goal you're looking for. Seems a shame
to use a whole opcode just for querying/setting the stack depth. But now
that I think about it, this might be fun because then you can:
set I0, SP # Stake in the ground
save X
save Y
save Z etc...
(bunch of processing)
ne some_exception_condition, okay
# Whoops, error.
set SP, I0 # Go back to your stake
branch exception_handler
okay: (more processing)
#1 seems the cleanest, because you don't have to add anything new except
some parsing bits. But going through a deep stack would get
loopy. :) Hopefully, other than things like stack dumps, it won't happen
often.
Sorry I'm so non-commital. I'm approaching this like a fun little CPU to
play with, but am (purposefully) trying to avoid developing an agenda or
inject design.