2012-05-20 06:03:27 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2015-01-15 23:27:30 +08:00
|
|
|
| Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
|
2012-05-20 06:03:27 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Nikita Popov <nikic@php.net> |
|
2015-03-07 07:28:12 +08:00
|
|
|
| Bob Weinand <bobwei9@hotmail.com> |
|
2012-05-20 06:03:27 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifndef ZEND_GENERATORS_H
|
|
|
|
#define ZEND_GENERATORS_H
|
|
|
|
|
|
|
|
BEGIN_EXTERN_C()
|
2013-04-22 19:39:50 +08:00
|
|
|
|
2012-08-25 23:40:08 +08:00
|
|
|
extern ZEND_API zend_class_entry *zend_ce_generator;
|
2015-03-07 07:28:12 +08:00
|
|
|
extern ZEND_API zend_class_entry *zend_ce_ClosedGeneratorException;
|
2012-05-20 06:03:27 +08:00
|
|
|
|
2015-03-07 07:28:12 +08:00
|
|
|
typedef struct _zend_generator_node zend_generator_node;
|
|
|
|
typedef struct _zend_generator zend_generator;
|
|
|
|
|
|
|
|
struct _zend_generator_node {
|
|
|
|
zend_generator *parent; /* NULL for root */
|
|
|
|
uint32_t children;
|
|
|
|
union {
|
|
|
|
HashTable ht; /* if > 4 children */
|
|
|
|
struct {
|
|
|
|
zend_generator *leaf;
|
|
|
|
zend_generator *child;
|
|
|
|
} array[4]; /* if <= 4 children */
|
|
|
|
} child;
|
|
|
|
union {
|
|
|
|
zend_generator *leaf; /* if > 0 children */
|
|
|
|
zend_generator *root; /* if 0 children */
|
|
|
|
} ptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _zend_generator {
|
2012-05-23 20:20:25 +08:00
|
|
|
zend_object std;
|
|
|
|
|
2014-04-09 05:50:15 +08:00
|
|
|
zend_object_iterator *iterator;
|
2012-11-30 17:39:23 +08:00
|
|
|
|
2012-05-23 20:20:25 +08:00
|
|
|
/* The suspended execution context. */
|
|
|
|
zend_execute_data *execute_data;
|
2012-05-31 06:00:30 +08:00
|
|
|
|
2012-11-30 17:39:23 +08:00
|
|
|
/* The separate stack used by generator */
|
|
|
|
zend_vm_stack stack;
|
2012-05-31 06:00:30 +08:00
|
|
|
|
2012-05-26 23:53:13 +08:00
|
|
|
/* Current value */
|
2014-02-10 14:04:30 +08:00
|
|
|
zval value;
|
2012-05-30 08:44:06 +08:00
|
|
|
/* Current key */
|
2014-02-10 14:04:30 +08:00
|
|
|
zval key;
|
2015-02-20 03:17:37 +08:00
|
|
|
/* Return value */
|
|
|
|
zval retval;
|
2012-05-29 23:34:33 +08:00
|
|
|
/* Variable to put sent value into */
|
2014-02-10 14:04:30 +08:00
|
|
|
zval *send_target;
|
2012-05-30 11:05:49 +08:00
|
|
|
/* Largest used integer key for auto-incrementing keys */
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long largest_used_integer_key;
|
2012-08-25 23:40:08 +08:00
|
|
|
|
2015-03-07 07:28:12 +08:00
|
|
|
/* Values specified by "yield from" to yield from this generator.
|
2015-02-20 19:59:56 +08:00
|
|
|
* This is only used for arrays or non-generator Traversables.
|
|
|
|
* This zval also uses the u2 structure in the same way as
|
|
|
|
* by-value foreach. */
|
|
|
|
zval values;
|
|
|
|
|
2015-03-07 07:28:12 +08:00
|
|
|
/* Node of waiting generators when multiple "yield *" expressions
|
2015-02-20 19:59:56 +08:00
|
|
|
* are nested. */
|
2015-03-07 07:28:12 +08:00
|
|
|
zend_generator_node node;
|
|
|
|
|
|
|
|
/* Fake execute_data for stacktraces */
|
|
|
|
zend_execute_data execute_fake;
|
2015-02-20 19:59:56 +08:00
|
|
|
|
2012-08-25 23:40:08 +08:00
|
|
|
/* ZEND_GENERATOR_* flags */
|
|
|
|
zend_uchar flags;
|
2015-03-07 07:28:12 +08:00
|
|
|
};
|
2012-05-23 20:20:25 +08:00
|
|
|
|
2012-08-25 23:40:08 +08:00
|
|
|
static const zend_uchar ZEND_GENERATOR_CURRENTLY_RUNNING = 0x1;
|
|
|
|
static const zend_uchar ZEND_GENERATOR_FORCED_CLOSE = 0x2;
|
|
|
|
static const zend_uchar ZEND_GENERATOR_AT_FIRST_YIELD = 0x4;
|
2015-03-07 07:28:12 +08:00
|
|
|
static const zend_uchar ZEND_GENERATOR_DO_INIT = 0x8;
|
2012-05-27 05:59:22 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
void zend_register_generator_ce(void);
|
|
|
|
ZEND_API void zend_generator_create_zval(zend_execute_data *call, zend_op_array *op_array, zval *return_value);
|
|
|
|
ZEND_API void zend_generator_close(zend_generator *generator, zend_bool finished_execution);
|
|
|
|
ZEND_API void zend_generator_resume(zend_generator *generator);
|
2012-05-27 05:59:22 +08:00
|
|
|
|
2015-03-07 07:28:12 +08:00
|
|
|
void zend_generator_yield_from(zend_generator *this, zend_generator *from);
|
|
|
|
ZEND_API zend_generator *zend_generator_get_current(zend_generator *generator);
|
|
|
|
ZEND_API zend_execute_data *zend_generator_check_placeholder_frame(zend_execute_data *ptr);
|
|
|
|
|
2013-04-22 19:39:50 +08:00
|
|
|
END_EXTERN_C()
|
|
|
|
|
2012-05-20 06:03:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*/
|