Shop OBEX P1 Docs P2 Docs Learn Events
Call Stack — Parallax Forums

Call Stack

Dave HeinDave Hein Posts: 6,347
edited 2010-03-02 03:39 in Propeller 1
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?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-03-01 19:35
    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.
  • jazzedjazzed Posts: 11,803
    edited 2010-03-01 20:22
    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
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-03-01 21:33
    Mike and jazzed,

    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
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-03-02 03:39
    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.

    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
    · ...
Sign In or Register to comment.