On Fri, 8 Jun 2012 13:24:49 +0200, Nikita Popov wrote:
Are you planning on any internal API for functions to implement
generators
(though I really haven't thought how that would work)?
I don't think that this is possible. Generators require that the
execution context is suspended in some way and we have to that
control
only over userland code, not internal C code.
Couldn't we simulate this by saving the state in a heap allocated
structure (whose exact form would depend on the generator
implementation). Something like:
struct generator_context {
zval *(*yield_next)(struct generator_context*);
}
struct spec_generator_context {
struct generator_context parent;
int foo;
}
PHP_FUNCTION(get_generator)
{
struct spec_generator_context *ctx = emalloc(*ctx);
ctx->parent.yield_next = foo_bar();
return_value = make_internal_generator(ctx);
}
And you could also change the yield_next pointer in foo_bar() to avoid
going through goto's or switch statements. Possibly yield_next could be
take the arg with double indirection and you could also completely
replace the context.
I understand this has the problem that the internal and userspace
implementations would be markedly different.
--
Gustavo Lopes
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php