Z-Geek Tutorial on Stack Frames
Setting
- Begin: 1998-04-26, 0040
- Participants: amu, eichin, map, seph, xela
Discussion
- xela/0040
- If I followed that --- bear in mind that my model of a stack is based
in box & pointer diagramms..... Um, is a stack frame an environment?
- eichin/0041
- mmm, there's some loose connection, at least.
- map/0042
-
Well, a traditional execution stack is linear memory, and not a linked list
like box and pointer diagrams. But some applications that want stack-like
functionality, do use linked lists. But the "stack-frame" reference is
almost always to a linear memory execution stack...
- eichin/0044
-
in the simplest case with a semi-modern
machine, a function call pushes the return address and branches to the
routine... and that's *it*. Next step up, you actually pass arguments
on the stack - to provide cross module and cross language interfacing,
you have to agree on there.
- eichin/0044
-
err, agree on *where*.
- eichin/0045
-
next up from that, there's an optimization
where modern machines can do short offsets from a register quickly -
so you clump all the local variables (C "automatics") together on the
stack, and define a local variable pointer that all the references go
through.
- xela/0046
-
Right.... 6.001 is about to hit register machines, which is one of the
things I felt *seriously* shortchanged on when I took it last term.
That stuff .... resonates for me somehow, maybe this will make a bit
more sense in 2 weeks.
- xela/0047
-
(Lost me in the C specifics, Mark....)
- eichin/0047
-
Then you start doing hairier things, but
basically that short-offset pointer is the "frame pointer". Once you
get even *more* advanced, or hairier chipsets (with more on chip
registers for example), that's no longer the fastest way to reference
data, so you start optimizing away from it... or better, you keep
track in the compiler of where the stack pointer is *at that line of
code* and do the reference relative to it, instead... tricky because
the SP is moving :-)
- eichin/0047
-
mmm, what non-lisp-like languages do you know?
- eichin/0047
-
(or what instruction sets? :-)
- xela/0049
-
> mmm, what non-lisp-like languages do you know?
'()
(Oh, a touch of Perl, a bit of a few scripting languages (sh, zwgc.desc,
hypertalk) But nothing I'd really call a programming language but scheme.
- seph/0049
-
IMO perl can be called a programming language :)
- eichin/0050
-
automatics in C are *like* "my $foo;" in perl,
but not exactly.
- amu/0050
-
No, perl is a kludging language. :-)
- eichin/0050
-
[actually, perl is a *large number* of
programming languages. That's both it's prime feature and it's worst problem.]
- amu/0050
-
s/it's/its/g
- seph/0051
-
I didn't say "good" ... :)
- eichin/0051
-
it also occurs to me that "my" variables are
like automatics because *I* use them that way :-)
- xela/0051
-
Perl may be a real language, seph; my knowledge of it isn't....
- eichin/0054
-
hmm, I wonder if there would be value in a
"hello world" turorial -- start with hello world and analyze it down
to the registers...