mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
Part way to allowing "from __future__ import generators" to communicate
that info to code dynamically compiled *by* code compiled with generators enabled. Doesn't yet work because there's still no way to tell the parser that "yield" is OK (unlike nested_scopes, the parser has its fingers in this too). Replaced PyEval_GetNestedScopes by a more-general PyEval_MergeCompilerFlags. Perhaps I should not have? I doubted it was *intended* to be part of the public API, so just did.
This commit is contained in:
parent
4dbf87152e
commit
5ba5866281
11 changed files with 77 additions and 33 deletions
|
|
@ -96,8 +96,8 @@
|
|||
#include "pystate.h"
|
||||
|
||||
#include "modsupport.h"
|
||||
#include "ceval.h"
|
||||
#include "pythonrun.h"
|
||||
#include "ceval.h"
|
||||
#include "sysmodule.h"
|
||||
#include "intrcheck.h"
|
||||
#include "import.h"
|
||||
|
|
|
|||
|
|
@ -31,7 +31,11 @@ DL_IMPORT(PyObject *) PyEval_GetLocals(void);
|
|||
DL_IMPORT(PyObject *) PyEval_GetOwner(void);
|
||||
DL_IMPORT(PyObject *) PyEval_GetFrame(void);
|
||||
DL_IMPORT(int) PyEval_GetRestricted(void);
|
||||
DL_IMPORT(int) PyEval_GetNestedScopes(void);
|
||||
|
||||
/* Look at the current frame's (if any) code's co_flags, and turn on
|
||||
the corresponding compiler flags in cf->cf_flags. Return 1 if any
|
||||
flag was set, else return 0. */
|
||||
DL_IMPORT(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
|
||||
|
||||
DL_IMPORT(int) Py_FlushLine(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,13 @@ typedef struct {
|
|||
#define CO_VARKEYWORDS 0x0008
|
||||
#define CO_NESTED 0x0010
|
||||
#define CO_GENERATOR 0x0020
|
||||
/* XXX Temporary hack. Until generators are a permanent part of the
|
||||
language, we need a way for a code object to record that generators
|
||||
were *possible* when it was compiled. This is so code dynamically
|
||||
compiled *by* a code object knows whether to allow yield stmts. In
|
||||
effect, this passes on the "from __future__ import generators" state
|
||||
in effect when the code block was compiled. */
|
||||
#define CO_GENERATOR_ALLOWED 0x1000
|
||||
|
||||
extern DL_IMPORT(PyTypeObject) PyCode_Type;
|
||||
|
||||
|
|
@ -56,6 +63,7 @@ typedef struct {
|
|||
int ff_found_docstring;
|
||||
int ff_last_lineno;
|
||||
int ff_nested_scopes;
|
||||
int ff_generators;
|
||||
} PyFutureFeatures;
|
||||
|
||||
DL_IMPORT(PyFutureFeatures *) PyNode_Future(struct _node *, char *);
|
||||
|
|
|
|||
|
|
@ -7,8 +7,13 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* These flags are named after the __future__ statements that introduced
|
||||
them. May not remain true for later additions, so fiddle this comment
|
||||
accordingly then. */
|
||||
#define PyCF_NESTED_SCOPES (0x00000001UL)
|
||||
#define PyCF_GENERATORS (0x00000002UL)
|
||||
typedef struct {
|
||||
int cf_nested_scopes;
|
||||
unsigned long cf_flags; /* bitmask of PyCF_xxx flags */
|
||||
} PyCompilerFlags;
|
||||
|
||||
DL_IMPORT(void) Py_SetProgramName(char *);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue