mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Essential changes for print function changes.
Lib will be changed in a separate run.
This commit is contained in:
parent
21298cfea6
commit
452bf519a7
9 changed files with 1060 additions and 1197 deletions
35
Python/ast.c
35
Python/ast.c
|
@ -2218,37 +2218,6 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
|
|||
}
|
||||
}
|
||||
|
||||
static stmt_ty
|
||||
ast_for_print_stmt(struct compiling *c, const node *n)
|
||||
{
|
||||
/* print_stmt: 'print' ( [ test (',' test)* [','] ]
|
||||
| '>>' test [ (',' test)+ [','] ] )
|
||||
*/
|
||||
expr_ty dest = NULL, expression;
|
||||
asdl_seq *seq;
|
||||
bool nl;
|
||||
int i, j, start = 1;
|
||||
|
||||
REQ(n, print_stmt);
|
||||
if (NCH(n) >= 2 && TYPE(CHILD(n, 1)) == RIGHTSHIFT) {
|
||||
dest = ast_for_expr(c, CHILD(n, 2));
|
||||
if (!dest)
|
||||
return NULL;
|
||||
start = 4;
|
||||
}
|
||||
seq = asdl_seq_new((NCH(n) + 1 - start) / 2, c->c_arena);
|
||||
if (!seq)
|
||||
return NULL;
|
||||
for (i = start, j = 0; i < NCH(n); i += 2, ++j) {
|
||||
expression = ast_for_expr(c, CHILD(n, i));
|
||||
if (!expression)
|
||||
return NULL;
|
||||
asdl_seq_SET(seq, j, expression);
|
||||
}
|
||||
nl = (TYPE(CHILD(n, NCH(n) - 1)) == COMMA) ? false : true;
|
||||
return Print(dest, seq, nl, LINENO(n), n->n_col_offset, c->c_arena);
|
||||
}
|
||||
|
||||
static asdl_seq *
|
||||
ast_for_exprlist(struct compiling *c, const node *n, expr_context_ty context)
|
||||
{
|
||||
|
@ -3089,14 +3058,12 @@ ast_for_stmt(struct compiling *c, const node *n)
|
|||
if (TYPE(n) == small_stmt) {
|
||||
REQ(n, small_stmt);
|
||||
n = CHILD(n, 0);
|
||||
/* small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt
|
||||
/* small_stmt: expr_stmt | del_stmt | pass_stmt
|
||||
| flow_stmt | import_stmt | global_stmt | assert_stmt
|
||||
*/
|
||||
switch (TYPE(n)) {
|
||||
case expr_stmt:
|
||||
return ast_for_expr_stmt(c, n);
|
||||
case print_stmt:
|
||||
return ast_for_print_stmt(c, n);
|
||||
case del_stmt:
|
||||
return ast_for_del_stmt(c, n);
|
||||
case pass_stmt:
|
||||
|
|
|
@ -1446,7 +1446,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
}
|
||||
|
||||
PyDoc_STRVAR(print_doc,
|
||||
"Print(value, ..., file=None, sep=' ', end='\\n')\n\
|
||||
"print(value, ..., file=None, sep=' ', end='\\n')\n\
|
||||
\n\
|
||||
Prints the values to a stream, or to sys.stdout by default.\n\
|
||||
Optional keyword arguments:\n\
|
||||
|
@ -2056,7 +2056,7 @@ static PyMethodDef builtin_methods[] = {
|
|||
{"open", (PyCFunction)builtin_open, METH_VARARGS | METH_KEYWORDS, open_doc},
|
||||
{"ord", builtin_ord, METH_O, ord_doc},
|
||||
{"pow", builtin_pow, METH_VARARGS, pow_doc},
|
||||
{"Print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc},
|
||||
{"print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc},
|
||||
{"range", builtin_range, METH_VARARGS, range_doc},
|
||||
{"reload", builtin_reload, METH_O, reload_doc},
|
||||
{"repr", builtin_repr, METH_O, repr_doc},
|
||||
|
|
1990
Python/graminit.c
1990
Python/graminit.c
File diff suppressed because it is too large
Load diff
|
@ -71,9 +71,10 @@ extern time_t PyOS_GetLastModificationTime(char *, FILE *);
|
|||
3020 (added BUILD_SET)
|
||||
3030 (added keyword-only parameters)
|
||||
3040 (added signature annotations)
|
||||
3050 (print becomes a function)
|
||||
.
|
||||
*/
|
||||
#define MAGIC (3040 | ((long)'\r'<<16) | ((long)'\n'<<24))
|
||||
#define MAGIC (3050 | ((long)'\r'<<16) | ((long)'\n'<<24))
|
||||
|
||||
/* Magic word as global; note that _PyImport_Init() can change the
|
||||
value of this global to accommodate for alterations of how the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue