> Date: Sat, 11 Apr 2015 17:31:30 +0300 > From: Sergey Korshunoff <[email protected]> > To: [email protected] > Subject: Re: [Tinycc-devel] Dollar Sign in Identifiers Extension > Message-ID: > <CAKG6wnZ9Re=wyyzukplozzod5nvjm5gq7d95q3fbxix7nkh...@mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > > Hi, Daniel Holden. >> I'm mainly interested in this change because I'm working on a new >> version of my library Cello: http://libcello.org/ which uses `$` and >> several variations of as macros. > > >From libCello docs: Lambda ... GNU99 C has a great feature that lets > you define functions inside functions > > tcc currently don't have a nested functions implemented. This is a > nice feature. But it is not implemented :-( >
As has been pointed out, within the context of C this is actually a mis-feature. However, if you REALLY like it, here's how to do it correctly: 1) Allow static functions to be defined inside of other functions: their namespacing should work like a static variable declared inside a function. 2) Implement a feature to return a pointer to the current "stack reference", whatever that is for the current architecture (on x86, presumably BP). You may want to add a special pointer type or something. 3) Implement a feature to allow a function to refer to another function invocation's arguments & local vars if it's both defined inside the relevant scope, and given a pointer to the invocation's "stack reference". If this sounds like a lot of work, well, yeah. It's absolutely the right way to have "proper" nested functions in C, though: the GCC style is appropriate for higher-level languages like LISP (which I assume was the point of inspiration), but not for lower-level languages like C. Step 1 could also be pretty nice all by itself, if the functions so declared were allowed to access all static variables that could be accessed by the enclosing function at that point of definition. _______________________________________________ Tinycc-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/tinycc-devel
