Commit 438f341c authored by Jeremy Hylton's avatar Jeremy Hylton

Refactor future feature handling

Replace individual slots in PyFutureFeatures with a single bitmask
with one field per feature.  The flags for this bitmask are the same
as the flags used in the co_flags slot of a code object.

    XXX This means we waste several bits, because they are used
    for co_flags but have no meaning for future statements.  Don't
    think this is an issue.

Remove the NESTED_SCOPES_DEFAULT define and others.  Not sure what
they were for anyway.

Remove all the PyCF_xxx flags, but define PyCF_MASK in terms of the
CO_xxx flags that are relevant for this release.

Change definition of PyCompilerFlags so that cf_flags matches
co_flags.
parent 82259055
...@@ -41,7 +41,6 @@ typedef struct { ...@@ -41,7 +41,6 @@ typedef struct {
effect, this passes on the "from __future__ import generators" state effect, this passes on the "from __future__ import generators" state
in effect when the code block was compiled. */ in effect when the code block was compiled. */
#define CO_GENERATOR_ALLOWED 0x1000 #define CO_GENERATOR_ALLOWED 0x1000
/* XXX Ditto for future division */
#define CO_FUTURE_DIVISION 0x2000 #define CO_FUTURE_DIVISION 0x2000
extern DL_IMPORT(PyTypeObject) PyCode_Type; extern DL_IMPORT(PyTypeObject) PyCode_Type;
...@@ -64,22 +63,15 @@ DL_IMPORT(int) PyCode_Addr2Line(PyCodeObject *, int); ...@@ -64,22 +63,15 @@ DL_IMPORT(int) PyCode_Addr2Line(PyCodeObject *, int);
typedef struct { typedef struct {
int ff_found_docstring; int ff_found_docstring;
int ff_last_lineno; int ff_last_lineno;
int ff_nested_scopes; int ff_features;
int ff_generators;
int ff_division;
} PyFutureFeatures; } PyFutureFeatures;
DL_IMPORT(PyFutureFeatures *) PyNode_Future(struct _node *, char *); DL_IMPORT(PyFutureFeatures *) PyNode_Future(struct _node *, char *);
DL_IMPORT(PyCodeObject *) PyNode_CompileFlags(struct _node *, char *, DL_IMPORT(PyCodeObject *) PyNode_CompileFlags(struct _node *, char *,
PyCompilerFlags *); PyCompilerFlags *);
#define NESTED_SCOPES_DEFAULT 1
#define FUTURE_NESTED_SCOPES "nested_scopes" #define FUTURE_NESTED_SCOPES "nested_scopes"
#define GENERATORS_DEFAULT 0
#define FUTURE_GENERATORS "generators" #define FUTURE_GENERATORS "generators"
#define DIVISION_DEFAULT 0
#define FUTURE_DIVISION "division" #define FUTURE_DIVISION "division"
/* for internal use only */ /* for internal use only */
......
...@@ -7,14 +7,9 @@ ...@@ -7,14 +7,9 @@
extern "C" { extern "C" {
#endif #endif
/* These flags are named after the __future__ statements that introduced #define PyCF_MASK (CO_GENERATOR_ALLOWED | CO_FUTURE_DIVISION)
them. May not remain true for later additions, so fiddle this comment
accordingly then. */
#define PyCF_NESTED_SCOPES (0x00000001UL)
#define PyCF_GENERATORS (0x00000002UL)
#define PyCF_DIVISION (0x00000004UL)
typedef struct { typedef struct {
unsigned long cf_flags; /* bitmask of PyCF_xxx flags */ int cf_flags; /* bitmask of CO_xxx flags relevant to future */
} PyCompilerFlags; } PyCompilerFlags;
DL_IMPORT(void) Py_SetProgramName(char *); DL_IMPORT(void) Py_SetProgramName(char *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment