Z-Geek Tutorial on Stack Frames
- Begin: 1998-04-26, 0040
- Participants: amu, eichin, map, seph, xela
- 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?
- mmm, there's some loose connection, at least.
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...
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.
err, agree on *where*.
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
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.
(Lost me in the C specifics, Mark....)
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 :-)
mmm, what non-lisp-like languages do you know?
(or what instruction sets? :-)
> 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.
IMO perl can be called a programming language :)
automatics in C are *like* "my $foo;" in perl,
but not exactly.
No, perl is a kludging language. :-)
[actually, perl is a *large number* of
programming languages. That's both it's prime feature and it's worst problem.]
I didn't say "good" ... :)
it also occurs to me that "my" variables are
like automatics because *I* use them that way :-)
Perl may be a real language, seph; my knowledge of it isn't....
hmm, I wonder if there would be value in a
"hello world" turorial -- start with hello world and analyze it down
to the registers...