Re: Stack frames & static predecessors

Paolo Bonzini <bonzini@gnu.org>
Fri, 24 Aug 2007 14:49:50 -0000

          From comp.compilers

Related articles
Stack frames & static predecessors wollenberg@web.de (Till Wollenberg) (2007-08-24)
Re: Stack frames & static predecessors torbenm@app-3.diku.dk (2007-08-24)
Re: Stack frames & static predecessors gah@ugcs.caltech.edu (glen herrmannsfeldt) (2007-08-24)
Re: Stack frames & static predecessors tk@ic.unicamp.br (Tomasz Kowaltowski) (2007-08-24)
Re: Stack frames & static predecessors bonzini@gnu.org (Paolo Bonzini) (2007-08-24)
Re: Stack frames & static predecessors gene.ressler@gmail.com (Gene) (2007-08-24)
Re: Stack frames & static predecessors anton@mips.complang.tuwien.ac.at (2007-08-25)
Re: Stack frames & static predecessors dnovillo@acm.org (Diego Novillo) (2007-08-25)
Re: Stack frames & static predecessors bobduff@shell01.TheWorld.com (Robert A Duff) (2007-08-25)
Re: Stack frames & static predecessors bobduff@shell01.TheWorld.com (Robert A Duff) (2007-08-25)
Re: Stack frames & static predecessors DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-08-26)
| List of all articles for this month |

From: Paolo Bonzini <bonzini@gnu.org>
Newsgroups: comp.compilers
Date: Fri, 24 Aug 2007 14:49:50 -0000
Organization: Compilers Central
References: 07-08-065
Keywords: code, Pascal
Posted-Date: 25 Aug 2007 10:36:59 EDT

> [The calling procedure passes in pointers to the stack frames of all
> of the lexically enclosing procedures, a structure known as a display.
> The code to create the display at each call point is tedious but not
> complex, and the techniques have been known since Algol 60, if not
> longer. This used to be a standard topic in compiler texts, at least
> until the academic world switched from Pascal to C. Take a look at the
> x86 ENTER instruction, which is specifically designed to create stack
> frames with displays. -John]


If you are passing the inner function around using a function pointer
(or in Pascal a function parameter), this is not possible, because
your "procedure Bar" is actually a "procedure Bar (var x: integer)" so
to speak. Therefore, the compiler will build on-the-fly (on the stack
likely) the executable code to "add" the initial parameter, and pass a
pointer to the "trampoline" that it has built on the stack.


On the x86, for example, the trampoline may look like


      PUSH [ESP]
      MOV [ESP+4], <static chain pointer>
      JMP Bar


where the static chain pointer is known at trampoline-generation time,
and thus can be written as an immediate.


Paolo



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.