The Call Stack and Stack Pointer

Top  Previous  Next

During the execution of a program, procedures usually call other procedures. The calling procedures are not just left and forgotten; they are placed on the call stack.

The call stack can be toggled by View > Call Stack. It lists the sequence of procedure calls which lead to the current procedure (the one in which the Program Pointer is located). The current procedure is listed at the top of the stack. Once it finishes executing, execution returns to the caller (the procedure one line below in the stack). In the caller procedure, execution resumes from the line immediately following the one which called the procedure which has just ended.

So, if the procedure (event handler, actually) on_timer called the procedure error_handler, which in turn called the procedure write_logfile, our call stack would look like this:

 

tide_callstack

 

When pausing a program in the midst of code execution, the program pointer appears. In the Call Stack pane, the function which currently contains the program pointer is highlighted in yellow. It is the currently executing function, so it is always the first one on the Call Stack list.

note_further-wt

Technically speaking, the top function on the call stack isn't actually a part of the stack itself, because it is currently executing, and the real stack only contains functions to which execution should later return. It still appears on the same list, for consistency and convenience.

The Stack Pointer

Double-clicking on any procedure within the call stack which is not the currently executing procedure would display the stack pointer. This pointer would be displayed in the source code, within the procedure you double-clicked, and would highlight the line from which execution would resume once control returns to this procedure. The watch pane would also interpret variables as relative to the procedure you've just highlighted.

The stack pointer is light blue in color. On the call stack list, it looks like this:

 

tide_callstack_pointer

 

In the code editing pane, it looks like this:

 

tide_callstack_pointer_in_code

 

Once again, double-clicking on the functions in th call stack does not move actual execution (the program pointer). Any sort of stepping would bring back the yellow program pointer, both in the source code and in the call stack.