[Cst-1b] Compiler Construction 1.19 - Static Chain method

Matthew Richards mwr22@cam.ac.uk
Thu, 4 May 2000 00:04:16 +0100


Imagine you have a function G, and another function F declared within it.
Say G calls F, and F then calls itself. So the stack looks like this:

G's frame | F's frame | another F's frame

The P pointer in the second F frame points back to the first F frame. But
the S pointer points to G's frame, because it's G that is the next level up
in the display. This makes sense because the second F can't access any of
the first F's variables (there would be no way to refer to them in the
program's code). The static chain points back through the stack frames of
the functions which "textually enclose" the current one, whereas the P
pointer points back through the sequence of function calls that have been
made (I think that's called a dynamic chain).

I hope that helps (and I also hope I've got it right!)

Matthew


-----Original Message-----
From: cst-1b-admin@srcf.ucam.org [mailto:cst-1b-admin@srcf.ucam.org]On
Behalf Of Martin Harper
Sent: Wednesday, May 03, 2000 11:24 PM
To: cst-1b@srcf.ucam.org
Subject: [Cst-1b] Compiler Construction 1.19 - Static Chain method


I'm not clear (at all) on the difference between the "P" frame pointer, and
the "S" static frame pointer, in the "static chain method" on page 23 of the
main notes. :(
>From my understanding, The P pointer points to the previous stack frame.-
the
one that you return to after termination of the function call. The S pointer
points to the stack frame that contains the next level up of the "display".
But surely these two stack frames will always be identical?
Help, pointers, insults welcome...
Martin.




_______________________________________________
CST-1B mailing list
CST-1B@srcf.ucam.org
http://www.srcf.ucam.org/mailman/listinfo/cst-1b