From mboxrd@z Thu Jan 1 00:00:00 1970 From: bakul at bitblocks.com (Bakul Shah) Date: Fri, 24 Jan 2020 16:09:12 -0800 Subject: [COFF] [TUHS] Unix quix In-Reply-To: <202001231551.00NFpVU4033383@tahoe.cs.Dartmouth.EDU> References: <202001231551.00NFpVU4033383@tahoe.cs.Dartmouth.EDU> Message-ID: <071C340F-3494-4B8D-98FD-29BF79731DB5@bitblocks.com> I read that thunks came about as an implementation of call by name for Algol. They were basically argument-less closures. Where as a general closure may accept args as well as refer to values in its environment (including those in its lexically enclosing function). I believe at one point gcc used (argument-less) thunks when it added support for nested functions so as to continue using a single ptr as a function argument. A proper closure representation needs a pair (a fun ptr & a ptr to env). The code for all this was stored on the stack & the thunk address actually pointed to this stacked code. I guess that had to be abandoned when storing code on stack was found to be a huge security hole (all because of C’s lax type system & stacks growing down to smaller addresses). Nicklaus Wirth carefully limited the scope of functional arguments in Pascal so as to avoid the “funarg problem” and GC. I think at least by 1975 (when I first studied software) it was clear how to implement “reentrant” functions; It is just that not everyone was convinced of the value of it. Even modern RISC processors don’t actually provide any support for stacks and it is just their “calling convention” that designates a specific GPR to be a stack ptr! No one questions the value of subroutines (even though the register to memory access ratio is soooo much worse now!) but closures and GC are still not so well accepted. On Jan 24, 2020, at 2:07 PM, Doug McIlroy wrote: > > Clem wrote, " the question came out language design of how the > stack or register call area was maintained: Was it/should it be the > responsibility of the calling routine or the called subroutine. Things > like Fortran's entry statement and other non-local goto's, > co-routines/setjmp/longjmp added fuel to the fire in the argument." > > I don't remember much prospective discussion of the subject, but > lots of retrospective discussion of techniques that didn't > quite work, going right back to Lisp's A-list and the ensuing > "funarg problem". The first PL/I out of Hursley got it wrong, too, > but they were able to correct it before the bad way became > ingrained. In C, which had no need for closures (thunks), > efficiency was the main concern in choice of stack protocol. > The only delicate situation, longjump, was sidestepped by > doing it via library rather than language. > > Doug > _______________________________________________ > COFF mailing list > COFF at minnie.tuhs.org > https://minnie.tuhs.org/cgi-bin/mailman/listinfo/coff