I think this doesn't bring anything further to talk about how to
implement this in the parser.

After reading the thread again, I would like to say that
- either this should be implemented as currently defined
- or it is implemented with the generator-keyword. But then it isn't a
function anymore, because that's is ridiculous.

In that case it should look like this:
generator g() {
     yield;
     return;
}



2012/8/20 Ángel González <keis...@gmail.com>:
> On 20/08/12 15:12, Nikita Popov wrote:
>>> You could not decorate it and rely instead on the presence of the yield
>>> keyword, but parsers will thank knowing about it from the start rather
>>> than realising at mid-parsing that the function is a completely
>>> different beast.
>> No, parsers don't care about this. It's trivial to detect in both cases.
>>
>> Nikita
> Yes, it's trivial to detect, but how much work is for it to do so?
> Suppose the parser reads php code and outputs machine instructions. When
> it encouters a function(), it adds the function prologue, goes reserving
> stack
> space for the variables it encounters, and so on. Then you find a yield
> keyword.
> Options:
> - Discard the generated code and go back to the function begin, using
> this time
> an storage into an object instead of the stack.
> - Copy all the state to an object and return it.
> - Add an initial pass checking which functions are generators.
>
> PHP being a dynamic language, it may be able to move the function variables
> to a class. But it's not trivial for any parser.
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
Freundliche Grüße
Alex Aulbach

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to