Mercurial > cpython-lru_cache-weakref
comparison Python/Python-ast.c @ 36695:b6d2f6fd3e11 legacy-trunk
PEP 343 -- the with-statement.
This was started by Mike Bland and completed by Guido
(with help from Neal).
This still needs a __future__ statement added;
Thomas is working on Michael's patch for that aspect.
There's a small amount of code cleanup and refactoring
in ast.c, compile.c and ceval.c (I fixed the lltrace
behavior when EXT_POP is used -- however I had to make
lltrace a static global).
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 27 Feb 2006 22:32:47 +0000 |
| parents | 9504f7ac3669 |
| children | cd847e726837 |
comparison
equal
deleted
inserted
replaced
| 36694:dfab22ae48e3 | 36695:b6d2f6fd3e11 |
|---|---|
| 81 PyTypeObject *If_type; | 81 PyTypeObject *If_type; |
| 82 char *If_fields[]={ | 82 char *If_fields[]={ |
| 83 "test", | 83 "test", |
| 84 "body", | 84 "body", |
| 85 "orelse", | 85 "orelse", |
| 86 }; | |
| 87 PyTypeObject *With_type; | |
| 88 char *With_fields[]={ | |
| 89 "context_expr", | |
| 90 "optional_vars", | |
| 91 "body", | |
| 86 }; | 92 }; |
| 87 PyTypeObject *Raise_type; | 93 PyTypeObject *Raise_type; |
| 88 char *Raise_fields[]={ | 94 char *Raise_fields[]={ |
| 89 "type", | 95 "type", |
| 90 "inst", | 96 "inst", |
| 463 if (!For_type) return 0; | 469 if (!For_type) return 0; |
| 464 While_type = make_type("While", stmt_type, While_fields, 3); | 470 While_type = make_type("While", stmt_type, While_fields, 3); |
| 465 if (!While_type) return 0; | 471 if (!While_type) return 0; |
| 466 If_type = make_type("If", stmt_type, If_fields, 3); | 472 If_type = make_type("If", stmt_type, If_fields, 3); |
| 467 if (!If_type) return 0; | 473 if (!If_type) return 0; |
| 474 With_type = make_type("With", stmt_type, With_fields, 3); | |
| 475 if (!With_type) return 0; | |
| 468 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3); | 476 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3); |
| 469 if (!Raise_type) return 0; | 477 if (!Raise_type) return 0; |
| 470 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); | 478 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); |
| 471 if (!TryExcept_type) return 0; | 479 if (!TryExcept_type) return 0; |
| 472 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields, | 480 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields, |
| 998 p->lineno = lineno; | 1006 p->lineno = lineno; |
| 999 return p; | 1007 return p; |
| 1000 } | 1008 } |
| 1001 | 1009 |
| 1002 stmt_ty | 1010 stmt_ty |
| 1011 With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno, | |
| 1012 PyArena *arena) | |
| 1013 { | |
| 1014 stmt_ty p; | |
| 1015 if (!context_expr) { | |
| 1016 PyErr_SetString(PyExc_ValueError, | |
| 1017 "field context_expr is required for With"); | |
| 1018 return NULL; | |
| 1019 } | |
| 1020 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1021 if (!p) { | |
| 1022 PyErr_NoMemory(); | |
| 1023 return NULL; | |
| 1024 } | |
| 1025 p->kind = With_kind; | |
| 1026 p->v.With.context_expr = context_expr; | |
| 1027 p->v.With.optional_vars = optional_vars; | |
| 1028 p->v.With.body = body; | |
| 1029 p->lineno = lineno; | |
| 1030 return p; | |
| 1031 } | |
| 1032 | |
| 1033 stmt_ty | |
| 1003 Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, PyArena *arena) | 1034 Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, PyArena *arena) |
| 1004 { | 1035 { |
| 1005 stmt_ty p; | 1036 stmt_ty p; |
| 1006 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | 1037 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1007 if (!p) { | 1038 if (!p) { |
| 2057 goto failed; | 2088 goto failed; |
| 2058 Py_DECREF(value); | 2089 Py_DECREF(value); |
| 2059 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); | 2090 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2060 if (!value) goto failed; | 2091 if (!value) goto failed; |
| 2061 if (PyObject_SetAttrString(result, "orelse", value) == -1) | 2092 if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2093 goto failed; | |
| 2094 Py_DECREF(value); | |
| 2095 break; | |
| 2096 case With_kind: | |
| 2097 result = PyType_GenericNew(With_type, NULL, NULL); | |
| 2098 if (!result) goto failed; | |
| 2099 value = ast2obj_expr(o->v.With.context_expr); | |
| 2100 if (!value) goto failed; | |
| 2101 if (PyObject_SetAttrString(result, "context_expr", value) == -1) | |
| 2102 goto failed; | |
| 2103 Py_DECREF(value); | |
| 2104 value = ast2obj_expr(o->v.With.optional_vars); | |
| 2105 if (!value) goto failed; | |
| 2106 if (PyObject_SetAttrString(result, "optional_vars", value) == | |
| 2107 -1) | |
| 2108 goto failed; | |
| 2109 Py_DECREF(value); | |
| 2110 value = ast2obj_list(o->v.With.body, ast2obj_stmt); | |
| 2111 if (!value) goto failed; | |
| 2112 if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2062 goto failed; | 2113 goto failed; |
| 2063 Py_DECREF(value); | 2114 Py_DECREF(value); |
| 2064 break; | 2115 break; |
| 2065 case Raise_kind: | 2116 case Raise_kind: |
| 2066 result = PyType_GenericNew(Raise_type, NULL, NULL); | 2117 result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2920 return; | 2971 return; |
| 2921 if(PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return; | 2972 if(PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return; |
| 2922 if(PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return; | 2973 if(PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return; |
| 2923 if(PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; | 2974 if(PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; |
| 2924 if(PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; | 2975 if(PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; |
| 2976 if(PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return; | |
| 2925 if(PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return; | 2977 if(PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return; |
| 2926 if(PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < 0) | 2978 if(PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < 0) |
| 2927 return; | 2979 return; |
| 2928 if(PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < | 2980 if(PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < |
| 2929 0) return; | 2981 0) return; |
