Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 19158:97a3d3d7029f legacy-trunk
Refactor future feature handling
Replace uses of PyCF_xxx with CO_xxx.
Replace individual feature slots in PyFutureFeatures with single
bitmask ff_features.
When flags must be transfered among the three parts of the interpreter
that care about them -- the pythonrun layer, the compiler, and the
future feature parser -- can simply or (|) the definitions.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Fri, 10 Aug 2001 21:41:33 +0000 |
| parents | de5d7a9428ef |
| children | e110cd4fc3c6 |
comparison
equal
deleted
inserted
replaced
| 19157:b7658e665d2e | 19158:97a3d3d7029f |
|---|---|
| 554 ps2 = PyString_AsString(w); | 554 ps2 = PyString_AsString(w); |
| 555 } | 555 } |
| 556 n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar, | 556 n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar, |
| 557 Py_single_input, ps1, ps2, &err, | 557 Py_single_input, ps1, ps2, &err, |
| 558 (flags && | 558 (flags && |
| 559 flags->cf_flags & PyCF_GENERATORS) ? | 559 flags->cf_flags & CO_GENERATOR_ALLOWED) ? |
| 560 PyPARSE_YIELD_IS_KEYWORD : 0); | 560 PyPARSE_YIELD_IS_KEYWORD : 0); |
| 561 Py_XDECREF(v); | 561 Py_XDECREF(v); |
| 562 Py_XDECREF(w); | 562 Py_XDECREF(w); |
| 563 if (n == NULL) { | 563 if (n == NULL) { |
| 564 if (err.error == E_EOF) { | 564 if (err.error == E_EOF) { |
| 1007 PyObject * | 1007 PyObject * |
| 1008 PyRun_StringFlags(char *str, int start, PyObject *globals, PyObject *locals, | 1008 PyRun_StringFlags(char *str, int start, PyObject *globals, PyObject *locals, |
| 1009 PyCompilerFlags *flags) | 1009 PyCompilerFlags *flags) |
| 1010 { | 1010 { |
| 1011 return run_err_node(PyParser_SimpleParseStringFlags( | 1011 return run_err_node(PyParser_SimpleParseStringFlags( |
| 1012 str, start, | 1012 str, start, |
| 1013 (flags && flags->cf_flags & PyCF_GENERATORS) ? | 1013 (flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ? |
| 1014 PyPARSE_YIELD_IS_KEYWORD : 0), | 1014 PyPARSE_YIELD_IS_KEYWORD : 0), |
| 1015 "<string>", globals, locals, flags); | 1015 "<string>", globals, locals, flags); |
| 1016 } | 1016 } |
| 1017 | 1017 |
| 1018 PyObject * | 1018 PyObject * |
| 1026 PyObject * | 1026 PyObject * |
| 1027 PyRun_FileExFlags(FILE *fp, char *filename, int start, PyObject *globals, | 1027 PyRun_FileExFlags(FILE *fp, char *filename, int start, PyObject *globals, |
| 1028 PyObject *locals, int closeit, PyCompilerFlags *flags) | 1028 PyObject *locals, int closeit, PyCompilerFlags *flags) |
| 1029 { | 1029 { |
| 1030 node *n = PyParser_SimpleParseFileFlags(fp, filename, start, | 1030 node *n = PyParser_SimpleParseFileFlags(fp, filename, start, |
| 1031 (flags && flags->cf_flags & PyCF_GENERATORS) ? | 1031 (flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ? |
| 1032 PyPARSE_YIELD_IS_KEYWORD : 0); | 1032 PyPARSE_YIELD_IS_KEYWORD : 0); |
| 1033 if (closeit) | 1033 if (closeit) |
| 1034 fclose(fp); | 1034 fclose(fp); |
| 1035 return run_err_node(n, filename, globals, locals, flags); | 1035 return run_err_node(n, filename, globals, locals, flags); |
| 1036 } | 1036 } |
| 1083 "Bad code object in .pyc file"); | 1083 "Bad code object in .pyc file"); |
| 1084 return NULL; | 1084 return NULL; |
| 1085 } | 1085 } |
| 1086 co = (PyCodeObject *)v; | 1086 co = (PyCodeObject *)v; |
| 1087 v = PyEval_EvalCode(co, globals, locals); | 1087 v = PyEval_EvalCode(co, globals, locals); |
| 1088 if (v && flags) { | 1088 if (v && flags) |
| 1089 if (co->co_flags & CO_NESTED) | 1089 flags->cf_flags |= (co->co_flags & PyCF_MASK); |
| 1090 flags->cf_flags |= PyCF_NESTED_SCOPES; | |
| 1091 if (co->co_flags & CO_GENERATOR_ALLOWED) | |
| 1092 flags->cf_flags |= PyCF_GENERATORS; | |
| 1093 #if 0 | |
| 1094 fprintf(stderr, "run_pyc_file: nested_scopes: %d\n", | |
| 1095 flags->cf_flags & PyCF_NESTED_SCOPES); | |
| 1096 fprintf(stderr, "run_pyc_file: generators: %d\n", | |
| 1097 flags->cf_flags & PyCF_GENERATORS); | |
| 1098 #endif | |
| 1099 } | |
| 1100 Py_DECREF(co); | 1090 Py_DECREF(co); |
| 1101 return v; | 1091 return v; |
| 1102 } | 1092 } |
| 1103 | 1093 |
| 1104 PyObject * | 1094 PyObject * |
| 1112 PyCompilerFlags *flags) | 1102 PyCompilerFlags *flags) |
| 1113 { | 1103 { |
| 1114 node *n; | 1104 node *n; |
| 1115 PyCodeObject *co; | 1105 PyCodeObject *co; |
| 1116 n = PyParser_SimpleParseStringFlags(str, start, | 1106 n = PyParser_SimpleParseStringFlags(str, start, |
| 1117 (flags && flags->cf_flags & PyCF_GENERATORS) ? | 1107 (flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ? |
| 1118 PyPARSE_YIELD_IS_KEYWORD : 0); | 1108 PyPARSE_YIELD_IS_KEYWORD : 0); |
| 1119 if (n == NULL) | 1109 if (n == NULL) |
| 1120 return NULL; | 1110 return NULL; |
| 1121 co = PyNode_CompileFlags(n, filename, flags); | 1111 co = PyNode_CompileFlags(n, filename, flags); |
| 1122 PyNode_Free(n); | 1112 PyNode_Free(n); |
