From mboxrd@z Thu Jan 1 00:00:00 1970 Message-Id: <200207191819.TAA08286@cthulhu.dircon.co.uk> Subject: Re: [9fans] useful language extension, or no? In-Reply-To: from "forsyth@vitanuova.com" at "Jul 19, 2002 04:45:14 pm" To: 9fans@cse.psu.edu From: Digby Tarvin MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Date: Fri, 19 Jul 2002 19:19:43 +0100 Topicbox-Message-UUID: d2e7d56a-eaca-11e9-9e20-41e7f4b1d025 Thanks - I guess that confirms it does what I thought. Are there any good papers on this sort of stuff, or does one just have to wade through the source code? Any recomendations on a worthy successor to the K&R book as a good reference on the current state of the art of the language...? Regards, DigbyT > it only uses the trampoline code when you call g indirectly through > a function pointer. if you call it directly it can provide the static link > itself without that fuss. when you create a function pointer to g, > as in the call to printf, it does generate code onto the stack that > loads the static link register then enters g. > leal -16(%ebp),%eax > movl $g.9-10,%edx > movb $185,(%eax) > movl %ebp,1(%eax) > movb $233,5(%eax) > subl %eax,%edx > movl %edx,6(%eax) > that's the generation on the fly of the trampoline code. > note the movl %ebp,1(%eax), which stores the current frame pointer > as a literal in the generated code. > the `function pointer' that is later passed to printf is the address of > -16(%ebp) [offsets might be different in your case], which when > called will load the literal, and enter g with a pc-relative reference > (i think that's about right). > > you'd need to flush the cache(s) on some architectures, which is > tricky when it's a privileged operation. > > the problem it is trying to solve is to get the right value for the static link register, > without passing the required value along with the function pointer as a pair. > providing the right value for the static link register is > easiest to do if it doesn't exist. there are several > approaches to implementing displays, and one of them allows nested > function pointers as a single word but without this crud. > > all these implementations of nested functions in C go sadly wrong if > you call a nested function indirectly when it has gone out of scope. > > -- Digby R. S. Tarvin digbyt@acm.org http://www.cthulhu.dircon.co.uk