Is there any documentation on the call stack used in Spin?· Is it the same when calling methods within the same object versus methods in other objects?
There's no formal "documentation" on Spin's call stack, only some threads discussing it. The Propeller Wiki (propeller.wikispaces.com/) does have some information on the method call process and stack frame. See "Software", then "Method Calls" for more information.
There are routines in the SPUD package that will trace the stack for you assuming the Spin interpreter has been loaded and is paused on an instruction step. Tracing the stack is quite difficult and it is possible that my interpretation is incomplete as I remember having tons of trouble, however it seems to work in the posted package. Have a look at the .zip's spin\SpinDebugger.spin methods isFrame, DisplayStackAddrs, and getStackFrame. http://forums.parallax.com/showthread.php?p=878067
Thanks for your responses.· I looked at the wiki, and it contains some very useful information.· jazzed, I'll have to try SPUD sometime.· It looks very useful.
I ran a few tests and verified that the call stack contains 2 words with return state information, the return value, the method arguments and the local variables in that order.· This seems to be independent of whether the called method is in the same object or another object.
The main reason I need to know about the call stack is so that I can create methods that handle a variable number of arguments, such as printf.· I created a function printfx that gets it arguments off of a list.· The list is just a pointer to the first argument in the functions printf0, printf1 and printf2.· Spin code requires that the number of arguments used in the call match the number of arguments in the method.· However, I only need one function to do the processing, and I just need the inteface functions to match the number of agurments needed.
Comments
http://forums.parallax.com/showthread.php?p=878067
Thanks for your responses.· I looked at the wiki, and it contains some very useful information.· jazzed, I'll have to try SPUD sometime.· It looks very useful.
Dave
The main reason I need to know about the call stack is so that I can create methods that handle a variable number of arguments, such as printf.· I created a function printfx that gets it arguments off of a list.· The list is just a pointer to the first argument in the functions printf0, printf1 and printf2.· Spin code requires that the number of arguments used in the call match the number of arguments in the method.· However, I only need one function to do the processing, and I just need the inteface functions to match the number of agurments needed.
A partial example of the code is shown below.
Dave
PUB printf0(format)
· printfx(@format)
PUB printf1(format, arg1)
· printfx(@format)
PUB printf2(format, arg1, arg2)
· printfx(@format)
PUB printfx(arglist) | format, arg
· format := LONG[noparse][[/noparse]arglist][noparse][[/noparse]0]
· arg := LONG[noparse][[/noparse]arglist][noparse][[/noparse]1]
· arglist += 8
· ...