diff options
author | Georg Brandl <georg@python.org> | 2007-02-09 21:28:07 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2007-02-09 21:28:07 +0000 |
commit | 88fc6646d1b97cb3ba6188808e7c016884d44a73 (patch) | |
tree | 4cf73aca05a06e89ae71a719c7b2329af51392b8 /Python | |
parent | 08c47ba0df4ba87cdce34c126e5bdb28f8c6034c (diff) | |
download | cpython-git-88fc6646d1b97cb3ba6188808e7c016884d44a73.tar.gz |
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/Python-ast.c | 47 | ||||
-rw-r--r-- | Python/bltinmodule.c | 2 | ||||
-rw-r--r-- | Python/ceval.c | 76 | ||||
-rw-r--r-- | Python/compile.c | 47 | ||||
-rw-r--r-- | Python/symtable.c | 5 | ||||
-rw-r--r-- | Python/sysmodule.c | 2 |
6 files changed, 2 insertions, 177 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 9908326e8a..d0b4b29dab 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -61,12 +61,6 @@ static char *AugAssign_fields[]={ "op", "value", }; -static PyTypeObject *Print_type; -static char *Print_fields[]={ - "dest", - "values", - "nl", -}; static PyTypeObject *For_type; static char *For_fields[]={ "target", @@ -480,8 +474,6 @@ static int init_types(void) if (!Assign_type) return 0; AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); if (!AugAssign_type) return 0; - Print_type = make_type("Print", stmt_type, Print_fields, 3); - if (!Print_type) return 0; For_type = make_type("For", stmt_type, For_fields, 4); if (!For_type) return 0; While_type = make_type("While", stmt_type, While_fields, 3); @@ -949,25 +941,6 @@ AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int } stmt_ty -Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset, - PyArena *arena) -{ - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) { - PyErr_NoMemory(); - return NULL; - } - p->kind = Print_kind; - p->v.Print.dest = dest; - p->v.Print.values = values; - p->v.Print.nl = nl; - p->lineno = lineno; - p->col_offset = col_offset; - return p; -} - -stmt_ty For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int lineno, int col_offset, PyArena *arena) { @@ -2118,25 +2091,6 @@ ast2obj_stmt(void* _o) goto failed; Py_DECREF(value); break; - case Print_kind: - result = PyType_GenericNew(Print_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Print.dest); - if (!value) goto failed; - if (PyObject_SetAttrString(result, "dest", value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.Print.values, ast2obj_expr); - if (!value) goto failed; - if (PyObject_SetAttrString(result, "values", value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_bool(o->v.Print.nl); - if (!value) goto failed; - if (PyObject_SetAttrString(result, "nl", value) == -1) - goto failed; - Py_DECREF(value); - break; case For_kind: result = PyType_GenericNew(For_type, NULL, NULL); if (!result) goto failed; @@ -3149,7 +3103,6 @@ init_ast(void) return; if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) return; - if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return; if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return; if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 9aa34f24ad..c71aed1dd7 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1398,7 +1398,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds) if (dummy_args == NULL) return NULL; - if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:Print", + if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:print", kwlist, &sep, &end, &file)) return NULL; if (file == NULL || file == Py_None) diff --git a/Python/ceval.c b/Python/ceval.c index 059ed4a92d..7511bb6a5d 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -524,7 +524,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) register PyObject *w; register PyObject *u; register PyObject *t; - register PyObject *stream = NULL; /* for PRINT opcodes */ register PyObject **fastlocals, **freevars; PyObject *retval = NULL; /* Return value */ PyThreadState *tstate = PyThreadState_GET(); @@ -1508,81 +1507,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) Py_XDECREF(x); break; - case PRINT_ITEM_TO: - w = stream = POP(); - /* fall through to PRINT_ITEM */ - - case PRINT_ITEM: - v = POP(); - if (stream == NULL || stream == Py_None) { - w = PySys_GetObject("stdout"); - if (w == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "lost sys.stdout"); - err = -1; - } - } - /* PyFile_SoftSpace() can exececute arbitrary code - if sys.stdout is an instance with a __getattr__. - If __getattr__ raises an exception, w will - be freed, so we need to prevent that temporarily. */ - Py_XINCREF(w); - if (w != NULL && PyFile_SoftSpace(w, 0)) - err = PyFile_WriteString(" ", w); - if (err == 0) - err = PyFile_WriteObject(v, w, Py_PRINT_RAW); - if (err == 0) { - /* XXX move into writeobject() ? */ - if (PyString_Check(v)) { - char *s = PyString_AS_STRING(v); - Py_ssize_t len = PyString_GET_SIZE(v); - if (len == 0 || - !isspace(Py_CHARMASK(s[len-1])) || - s[len-1] == ' ') - PyFile_SoftSpace(w, 1); - } -#ifdef Py_USING_UNICODE - else if (PyUnicode_Check(v)) { - Py_UNICODE *s = PyUnicode_AS_UNICODE(v); - Py_ssize_t len = PyUnicode_GET_SIZE(v); - if (len == 0 || - !Py_UNICODE_ISSPACE(s[len-1]) || - s[len-1] == ' ') - PyFile_SoftSpace(w, 1); - } -#endif - else - PyFile_SoftSpace(w, 1); - } - Py_XDECREF(w); - Py_DECREF(v); - Py_XDECREF(stream); - stream = NULL; - if (err == 0) - continue; - break; - - case PRINT_NEWLINE_TO: - w = stream = POP(); - /* fall through to PRINT_NEWLINE */ - - case PRINT_NEWLINE: - if (stream == NULL || stream == Py_None) { - w = PySys_GetObject("stdout"); - if (w == NULL) - PyErr_SetString(PyExc_RuntimeError, - "lost sys.stdout"); - } - if (w != NULL) { - err = PyFile_WriteString("\n", w); - if (err == 0) - PyFile_SoftSpace(w, 0); - } - Py_XDECREF(stream); - stream = NULL; - break; - - #ifdef CASE_TOO_BIG default: switch (opcode) { #endif diff --git a/Python/compile.c b/Python/compile.c index e3bdaf5a1e..927569a928 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -734,14 +734,6 @@ opcode_stack_effect(int opcode, int oparg) case PRINT_EXPR: return -1; - case PRINT_ITEM: - return -1; - case PRINT_NEWLINE: - return 0; - case PRINT_ITEM_TO: - return -2; - case PRINT_NEWLINE_TO: - return -1; case INPLACE_LSHIFT: case INPLACE_RSHIFT: case INPLACE_AND: @@ -1626,43 +1618,6 @@ compiler_lambda(struct compiler *c, expr_ty e) } static int -compiler_print(struct compiler *c, stmt_ty s) -{ - int i, n; - bool dest; - - assert(s->kind == Print_kind); - n = asdl_seq_LEN(s->v.Print.values); - dest = false; - if (s->v.Print.dest) { - VISIT(c, expr, s->v.Print.dest); - dest = true; - } - for (i = 0; i < n; i++) { - expr_ty e = (expr_ty)asdl_seq_GET(s->v.Print.values, i); - if (dest) { - ADDOP(c, DUP_TOP); - VISIT(c, expr, e); - ADDOP(c, ROT_TWO); - ADDOP(c, PRINT_ITEM_TO); - } - else { - VISIT(c, expr, e); - ADDOP(c, PRINT_ITEM); - } - } - if (s->v.Print.nl) { - if (dest) - ADDOP(c, PRINT_NEWLINE_TO) - else - ADDOP(c, PRINT_NEWLINE) - } - else if (dest) - ADDOP(c, POP_TOP); - return 1; -} - -static int compiler_if(struct compiler *c, stmt_ty s) { basicblock *end, *next; @@ -2236,8 +2191,6 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s) break; case AugAssign_kind: return compiler_augassign(c, s); - case Print_kind: - return compiler_print(c, s); case For_kind: return compiler_for(c, s); case While_kind: diff --git a/Python/symtable.c b/Python/symtable.c index d275cb9034..5f0290afa1 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -990,11 +990,6 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) VISIT(st, expr, s->v.AugAssign.target); VISIT(st, expr, s->v.AugAssign.value); break; - case Print_kind: - if (s->v.Print.dest) - VISIT(st, expr, s->v.Print.dest); - VISIT_SEQ(st, expr, s->v.Print.values); - break; case For_kind: VISIT(st, expr, s->v.For.target); VISIT(st, expr, s->v.For.iter); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index f17fd05e1e..3f2d5b7f6e 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -904,7 +904,7 @@ exitfunc -- if sys.exitfunc exists, this routine is called when Python exits\n\ Assigning to sys.exitfunc is deprecated; use the atexit module instead.\n\ \n\ stdin -- standard input file object; used by raw_input() and input()\n\ -stdout -- standard output file object; used by the print statement\n\ +stdout -- standard output file object; used by print()\n\ stderr -- standard error object; used for error messages\n\ By assigning other file objects (or objects that behave like files)\n\ to these, it is possible to redirect all of the interpreter's I/O.\n\ |