discuss-gnustep
[Top][All Lists]
Advanced

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

Re: GSPredicate


From: David Chisnall
Subject: Re: GSPredicate
Date: Mon, 18 Jun 2018 10:06:38 +0100

On 17 Jun 2018, at 22:48, Fred Kiefer <fredkiefer@gmx.de> wrote:
> 
> I was hoping for someone with a working knowledge of blocks to step in here. 
> But currently I seem to be the only one operating this mailing list :-)
> 
> If you have a look in the file Tests/base/NSArray/blocks.m you will find 
> examples on how to write an NSBlock for a compiler that supports it. A very 
> simple one would be this:
> ^() { return YES; }
> 
> You should also be able to simulate blocks with gcc, but I am not sure how to 
> do this :-(

You can, in theory, simulate blocks with any C compiler, but in practice it’s 
too hard. A block is a structure that contains pointers to other structures 
that describe all of the captured variables and how to copy them.  For anything 
beyond a simple function written as a block, the compiler is generating a load 
of helper code for copying the captures.

The GSBlock stuff allows a legacy compiler to *call* blocks (by casting them to 
a compatible structure type and calling the invoke function with a pointer to 
the struct as the first argument) but it doesn’t make any attempt to allow 
compilers for pre-2007 dialects of Objective-C to generate blocks.  The logic 
in the compiler for doing so is several hundred lines of code and integrates 
with understanding of object lifetimes - replicating this in C macros is not 
feasible.

David




reply via email to

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