This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Front-end Closures


Hey

Thanks for that didn't realise you could do that. I guess does this
mean i could do:

MODIFY_EXPR price = stmt_list

And gimple will be nice to me? Wo i am so impressed by this.

--Phil

On 6 February 2014 12:34, Florian Weimer <fweimer@redhat.com> wrote:
> On 02/06/2014 01:14 PM, Philip Herron wrote:
>
>> I am trying to understand what way i could compile this in GCC can you
>> do the following in GENERIC make a nested function decl kind of like a
>> closure not quite sure what to do here.
>
>
> It's just a statement expression.  The C front end supports them, so this
> might give you some idea how to implement them.
>
>
> void main (void) {
>      const char * item = "test";
>      const double price = ({
>
>          double ret_tmp;
>          if (item == "salad") {
>              ret_tmp = 3.50;
>          }
>          else if (item == "muffin") {
>              ret_tmp = 2.25;
>          }
>          else {
>              ret_tmp = 2.00;
>          }
>          ret_tmp;
>        });
> }
>
> To compile general closures, you have to apply a transformation called
> closure conversion.  GCC's nested functions only provide downward closures,
> and require an executable stack for trampolines on most architectures, which
> many systems do not support.
>
> --
> Florian Weimer / Red Hat Product Security Team


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]