Mercurial > cpython-lru_cache-weakref
comparison Python/Python-ast.c @ 39782:c94f37054f19
Patch #1550800: make exec a function.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Wed, 06 Sep 2006 06:51:57 +0000 |
| parents | da3a9f402886 |
| children | 7a0ad110e91e |
comparison
equal
deleted
inserted
replaced
| 39710:89176e65add2 | 39782:c94f37054f19 |
|---|---|
| 120 static PyTypeObject *ImportFrom_type; | 120 static PyTypeObject *ImportFrom_type; |
| 121 static char *ImportFrom_fields[]={ | 121 static char *ImportFrom_fields[]={ |
| 122 "module", | 122 "module", |
| 123 "names", | 123 "names", |
| 124 "level", | 124 "level", |
| 125 }; | |
| 126 static PyTypeObject *Exec_type; | |
| 127 static char *Exec_fields[]={ | |
| 128 "body", | |
| 129 "globals", | |
| 130 "locals", | |
| 131 }; | 125 }; |
| 132 static PyTypeObject *Global_type; | 126 static PyTypeObject *Global_type; |
| 133 static char *Global_fields[]={ | 127 static char *Global_fields[]={ |
| 134 "names", | 128 "names", |
| 135 }; | 129 }; |
| 492 Import_type = make_type("Import", stmt_type, Import_fields, 1); | 486 Import_type = make_type("Import", stmt_type, Import_fields, 1); |
| 493 if (!Import_type) return 0; | 487 if (!Import_type) return 0; |
| 494 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, | 488 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
| 495 3); | 489 3); |
| 496 if (!ImportFrom_type) return 0; | 490 if (!ImportFrom_type) return 0; |
| 497 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3); | |
| 498 if (!Exec_type) return 0; | |
| 499 Global_type = make_type("Global", stmt_type, Global_fields, 1); | 491 Global_type = make_type("Global", stmt_type, Global_fields, 1); |
| 500 if (!Global_type) return 0; | 492 if (!Global_type) return 0; |
| 501 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); | 493 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
| 502 if (!Expr_type) return 0; | 494 if (!Expr_type) return 0; |
| 503 Pass_type = make_type("Pass", stmt_type, NULL, 0); | 495 Pass_type = make_type("Pass", stmt_type, NULL, 0); |
| 1168 p->col_offset = col_offset; | 1160 p->col_offset = col_offset; |
| 1169 return p; | 1161 return p; |
| 1170 } | 1162 } |
| 1171 | 1163 |
| 1172 stmt_ty | 1164 stmt_ty |
| 1173 Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset, | |
| 1174 PyArena *arena) | |
| 1175 { | |
| 1176 stmt_ty p; | |
| 1177 if (!body) { | |
| 1178 PyErr_SetString(PyExc_ValueError, | |
| 1179 "field body is required for Exec"); | |
| 1180 return NULL; | |
| 1181 } | |
| 1182 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1183 if (!p) { | |
| 1184 PyErr_NoMemory(); | |
| 1185 return NULL; | |
| 1186 } | |
| 1187 p->kind = Exec_kind; | |
| 1188 p->v.Exec.body = body; | |
| 1189 p->v.Exec.globals = globals; | |
| 1190 p->v.Exec.locals = locals; | |
| 1191 p->lineno = lineno; | |
| 1192 p->col_offset = col_offset; | |
| 1193 return p; | |
| 1194 } | |
| 1195 | |
| 1196 stmt_ty | |
| 1197 Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) | 1165 Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1198 { | 1166 { |
| 1199 stmt_ty p; | 1167 stmt_ty p; |
| 1200 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | 1168 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1201 if (!p) { | 1169 if (!p) { |
| 2269 goto failed; | 2237 goto failed; |
| 2270 Py_DECREF(value); | 2238 Py_DECREF(value); |
| 2271 value = ast2obj_int(o->v.ImportFrom.level); | 2239 value = ast2obj_int(o->v.ImportFrom.level); |
| 2272 if (!value) goto failed; | 2240 if (!value) goto failed; |
| 2273 if (PyObject_SetAttrString(result, "level", value) == -1) | 2241 if (PyObject_SetAttrString(result, "level", value) == -1) |
| 2274 goto failed; | |
| 2275 Py_DECREF(value); | |
| 2276 break; | |
| 2277 case Exec_kind: | |
| 2278 result = PyType_GenericNew(Exec_type, NULL, NULL); | |
| 2279 if (!result) goto failed; | |
| 2280 value = ast2obj_expr(o->v.Exec.body); | |
| 2281 if (!value) goto failed; | |
| 2282 if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2283 goto failed; | |
| 2284 Py_DECREF(value); | |
| 2285 value = ast2obj_expr(o->v.Exec.globals); | |
| 2286 if (!value) goto failed; | |
| 2287 if (PyObject_SetAttrString(result, "globals", value) == -1) | |
| 2288 goto failed; | |
| 2289 Py_DECREF(value); | |
| 2290 value = ast2obj_expr(o->v.Exec.locals); | |
| 2291 if (!value) goto failed; | |
| 2292 if (PyObject_SetAttrString(result, "locals", value) == -1) | |
| 2293 goto failed; | 2242 goto failed; |
| 2294 Py_DECREF(value); | 2243 Py_DECREF(value); |
| 2295 break; | 2244 break; |
| 2296 case Global_kind: | 2245 case Global_kind: |
| 2297 result = PyType_GenericNew(Global_type, NULL, NULL); | 2246 result = PyType_GenericNew(Global_type, NULL, NULL); |
| 3080 return; | 3029 return; |
| 3081 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) | 3030 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
| 3082 return; | 3031 return; |
| 3083 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < | 3032 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
| 3084 0) return; | 3033 0) return; |
| 3085 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return; | |
| 3086 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) | 3034 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
| 3087 return; | 3035 return; |
| 3088 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return; | 3036 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return; |
| 3089 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return; | 3037 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return; |
| 3090 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return; | 3038 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return; |
