Related articles |
---|
Request for more info on trampolines holmer@rose.eecs.nwu.edu (1993-07-07) |
Re: Request for more info on trampolines eb@kaleida.com (1993-07-07) |
Re: Request for more info on trampolines max@nic.gac.edu (1993-07-08) |
Re: Request for more info on trampolines pardo@cs.washington.edu (1993-07-08) |
Re: Request for more info on trampolines eb@kaleida.com (1993-07-09) |
Re: Request for more info on trampolines pardo@cs.washington.edu (1993-07-10) |
Re: Request for more info on trampolines chased@rbbb.Eng.Sun.COM (1993-07-16) |
Re: Request for more info on trampolines jfc@athena.mit.edu (1993-07-18) |
Newsgroups: | comp.compilers |
From: | eb@kaleida.com (Eric Benson) |
Keywords: | GCC, code |
Organization: | Kaleida Labs, Inc., Mountain View, CA |
References: | 93-07-026 |
Date: | Wed, 7 Jul 1993 22:42:24 GMT |
The term "trampoline" has been used in the Lisp world for years to
describe a small piece of code that is called, performs some small amount
of work, usually picking up some extra arguments, then jumps to the real
target of the call. For example, interpreted functions are often
represented as very small compiled functions that do nothing more than
pick up the expression to be interpreted and pass it along to the main
interpreter routine. This allows compiled code to call interpreted code
directly, without the caller knowing whether the function is interpreted
or compiled. More generally, the term is often used to refer to one way
of representing closures in Lisp. A closure is a function with state, and
there may be several closures created from the same "code" with different
state. A separate trampoline can be created for each closure made from
the same code, each one of which loads a reference to its state and jumps
to the "real" code.
In GNU CC, trampolines are used for nested functions having references to
the local variables of the functions in which they are nested. Nested
functions are provided as an extension to C in GNU CC, but the facility
was added to the compiler to support languages such as Pascal and Ada,
which include them normally. Section 7.4 of the Red Dragon book describes
the problem and a variety of solutions. The most common solution is some
form of "display", essentially and extra argument that points to the outer
stack frame. This is fine when a function is called directly by name, but
when the address of a function is taken it must be callable in the same
way as any other function. This is why the trampoline is used. The
trampoline is callable as an ordinary C function, but it just picks up the
display and calls the "real" code.
Non-C-based systems, e.g. those whose standard system programming language
is something more Pascal-like, often represent function parameters as two
words, a pointer to code and a pointer to "state", the latter of which
could be used for a display. It is of course much easier to represent a
function without state as one with state than the other way around!
Eric Benson
Kaleida Labs, Inc.
eb@kaleida.com
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.