tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Local procedures


From: Antti-Juhani Kaijanaho
Subject: Re: [Tinycc-devel] Local procedures
Date: Wed, 12 Sep 2007 07:17:51 +0300
User-agent: Mutt/1.5.16 (2007-06-11)

On Tue, Sep 11, 2007 at 03:33:45PM -0500, Rob Landley wrote:
> > No.  It is an ordinary function in a function-local namespace.
> 
> If it was a normal function it couldn't access the caller's local variables.

It can't and it doesn't.  That would be a violation of lexical scoping
rules.  What it can do is access the variables visible at the point
where the address of the function was taken; this process of bundling
such variables with the function pointer is usually called *creating a
closure* and is a well-understood procedure.  The simplest technique is
to bundle the static link (the frame pointer of the function creating
the function pointer) with the code pointer in the function pointer, but
this makes the function pointer fat (two words long) and changes the
ABI.

> > The only really funky thing about is the trampoline technique used to
> > make them work with function pointers.
> 
> That and it's accessing some local variables with a negative offset...

It's not.  What it does is load the static link (the frame pointer of
the lexically enclosing function) to a temp register and then access
those variables with a positive offset relative to that register,
instead of relative to EBP.

Your comment is a bit weird also from the point of view that on x86-32,
function parameters lie at negative offsets :)

> I'm really not motivated to do any work to add this feature myself.  If 
> somebody wants to send me a patch, I'll look at it...

I, myself, am not interested in doing the work, as I won't be using
local functions in C as they are non-portable (because they were
not included the standard).  I'm just correcting your misconceptions
about the feature :)

-- 
Antti-Juhani Kaijanaho, Jyväskylä
http://antti-juhani.kaijanaho.fi/newblog/
http://www.flickr.com/photos/antti-juhani/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]