Commit 24838a85 authored by Georg Brandl's avatar Georg Brandl

* 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.
parent 45a4fb79
...@@ -353,27 +353,6 @@ removed from the stack and printed. In non-interactive mode, an ...@@ -353,27 +353,6 @@ removed from the stack and printed. In non-interactive mode, an
expression statement is terminated with \code{POP_STACK}. expression statement is terminated with \code{POP_STACK}.
\end{opcodedesc} \end{opcodedesc}
\begin{opcodedesc}{PRINT_ITEM}{}
Prints TOS to the file-like object bound to \code{sys.stdout}. There
is one such instruction for each item in the \keyword{print} statement.
\end{opcodedesc}
\begin{opcodedesc}{PRINT_ITEM_TO}{}
Like \code{PRINT_ITEM}, but prints the item second from TOS to the
file-like object at TOS. This is used by the extended print statement.
\end{opcodedesc}
\begin{opcodedesc}{PRINT_NEWLINE}{}
Prints a new line on \code{sys.stdout}. This is generated as the
last operation of a \keyword{print} statement, unless the statement
ends with a comma.
\end{opcodedesc}
\begin{opcodedesc}{PRINT_NEWLINE_TO}{}
Like \code{PRINT_NEWLINE}, but prints the new line on the file-like
object on the TOS. This is used by the extended print statement.
\end{opcodedesc}
\begin{opcodedesc}{BREAK_LOOP}{} \begin{opcodedesc}{BREAK_LOOP}{}
Terminates a loop due to a \keyword{break} statement. Terminates a loop due to a \keyword{break} statement.
\end{opcodedesc} \end{opcodedesc}
......
...@@ -12,7 +12,6 @@ by semicolons. The syntax for simple statements is: ...@@ -12,7 +12,6 @@ by semicolons. The syntax for simple statements is:
\productioncont{| \token{augmented_assignment_stmt}} \productioncont{| \token{augmented_assignment_stmt}}
\productioncont{| \token{pass_stmt}} \productioncont{| \token{pass_stmt}}
\productioncont{| \token{del_stmt}} \productioncont{| \token{del_stmt}}
\productioncont{| \token{print_stmt}}
\productioncont{| \token{return_stmt}} \productioncont{| \token{return_stmt}}
\productioncont{| \token{yield_stmt}} \productioncont{| \token{yield_stmt}}
\productioncont{| \token{raise_stmt}} \productioncont{| \token{raise_stmt}}
...@@ -370,60 +369,6 @@ right type (but even this is determined by the sliced object). ...@@ -370,60 +369,6 @@ right type (but even this is determined by the sliced object).
\indexii{attribute}{deletion} \indexii{attribute}{deletion}
\section{The \keyword{print} statement \label{print}}
\stindex{print}
\begin{productionlist}
\production{print_stmt}
{"print" ( \optional{\token{expression} ("," \token{expression})* \optional{","}}}
\productioncont{| ">>" \token{expression}
\optional{("," \token{expression})+ \optional{","}} )}
\end{productionlist}
\keyword{print} evaluates each expression in turn and writes the
resulting object to standard output (see below). If an object is not
a string, it is first converted to a string using the rules for string
conversions. The (resulting or original) string is then written. A
space is written before each object is (converted and) written, unless
the output system believes it is positioned at the beginning of a
line. This is the case (1) when no characters have yet been written
to standard output, (2) when the last character written to standard
output is \character{\e n}, or (3) when the last write operation on
standard output was not a \keyword{print} statement. (In some cases
it may be functional to write an empty string to standard output for
this reason.) \note{Objects which act like file objects but which are
not the built-in file objects often do not properly emulate this
aspect of the file object's behavior, so it is best not to rely on
this.}
\index{output}
\indexii{writing}{values}
A \character{\e n} character is written at the end, unless the
\keyword{print} statement ends with a comma. This is the only action
if the statement contains just the keyword \keyword{print}.
\indexii{trailing}{comma}
\indexii{newline}{suppression}
Standard output is defined as the file object named \code{stdout}
in the built-in module \module{sys}. If no such object exists, or if
it does not have a \method{write()} method, a \exception{RuntimeError}
exception is raised.
\indexii{standard}{output}
\refbimodindex{sys}
\withsubitem{(in module sys)}{\ttindex{stdout}}
\exindex{RuntimeError}
\keyword{print} also has an extended\index{extended print statement}
form, defined by the second portion of the syntax described above.
This form is sometimes referred to as ``\keyword{print} chevron.''
In this form, the first expression after the \code{>>} must
evaluate to a ``file-like'' object, specifically an object that has a
\method{write()} method as described above. With this extended form,
the subsequent expressions are printed to this file object. If the
first expression evaluates to \code{None}, then \code{sys.stdout} is
used as the file for output.
\section{The \keyword{return} statement \label{return}} \section{The \keyword{return} statement \label{return}}
\stindex{return} \stindex{return}
......
...@@ -62,12 +62,11 @@ struct _mod { ...@@ -62,12 +62,11 @@ struct _mod {
}; };
enum _stmt_kind {FunctionDef_kind=1, ClassDef_kind=2, Return_kind=3, enum _stmt_kind {FunctionDef_kind=1, ClassDef_kind=2, Return_kind=3,
Delete_kind=4, Assign_kind=5, AugAssign_kind=6, Print_kind=7, Delete_kind=4, Assign_kind=5, AugAssign_kind=6, For_kind=7,
For_kind=8, While_kind=9, If_kind=10, With_kind=11, While_kind=8, If_kind=9, With_kind=10, Raise_kind=11,
Raise_kind=12, TryExcept_kind=13, TryFinally_kind=14, TryExcept_kind=12, TryFinally_kind=13, Assert_kind=14,
Assert_kind=15, Import_kind=16, ImportFrom_kind=17, Import_kind=15, ImportFrom_kind=16, Global_kind=17,
Global_kind=18, Expr_kind=19, Pass_kind=20, Break_kind=21, Expr_kind=18, Pass_kind=19, Break_kind=20, Continue_kind=21};
Continue_kind=22};
struct _stmt { struct _stmt {
enum _stmt_kind kind; enum _stmt_kind kind;
union { union {
...@@ -104,12 +103,6 @@ struct _stmt { ...@@ -104,12 +103,6 @@ struct _stmt {
expr_ty value; expr_ty value;
} AugAssign; } AugAssign;
struct {
expr_ty dest;
asdl_seq *values;
bool nl;
} Print;
struct { struct {
expr_ty target; expr_ty target;
expr_ty iter; expr_ty iter;
...@@ -392,9 +385,6 @@ stmt_ty _Py_Assign(asdl_seq * targets, expr_ty value, int lineno, int ...@@ -392,9 +385,6 @@ stmt_ty _Py_Assign(asdl_seq * targets, expr_ty value, int lineno, int
#define AugAssign(a0, a1, a2, a3, a4, a5) _Py_AugAssign(a0, a1, a2, a3, a4, a5) #define AugAssign(a0, a1, a2, a3, a4, a5) _Py_AugAssign(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_AugAssign(expr_ty target, operator_ty op, expr_ty value, int stmt_ty _Py_AugAssign(expr_ty target, operator_ty op, expr_ty value, int
lineno, int col_offset, PyArena *arena); lineno, int col_offset, PyArena *arena);
#define Print(a0, a1, a2, a3, a4, a5) _Py_Print(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int
col_offset, PyArena *arena);
#define For(a0, a1, a2, a3, a4, a5, a6) _Py_For(a0, a1, a2, a3, a4, a5, a6) #define For(a0, a1, a2, a3, a4, a5, a6) _Py_For(a0, a1, a2, a3, a4, a5, a6)
stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq *
orelse, int lineno, int col_offset, PyArena *arena); orelse, int lineno, int col_offset, PyArena *arena);
......
...@@ -61,10 +61,7 @@ extern "C" { ...@@ -61,10 +61,7 @@ extern "C" {
#define GET_ITER 68 #define GET_ITER 68
#define PRINT_EXPR 70 #define PRINT_EXPR 70
#define PRINT_ITEM 71
#define PRINT_NEWLINE 72
#define PRINT_ITEM_TO 73
#define PRINT_NEWLINE_TO 74
#define INPLACE_LSHIFT 75 #define INPLACE_LSHIFT 75
#define INPLACE_RSHIFT 76 #define INPLACE_RSHIFT 76
#define INPLACE_AND 77 #define INPLACE_AND 77
......
...@@ -998,50 +998,6 @@ class Power(Node): ...@@ -998,50 +998,6 @@ class Power(Node):
def __repr__(self): def __repr__(self):
return "Power((%s, %s))" % (repr(self.left), repr(self.right)) return "Power((%s, %s))" % (repr(self.left), repr(self.right))
class Print(Node):
def __init__(self, nodes, dest, lineno=None):
self.nodes = nodes
self.dest = dest
self.lineno = lineno
def getChildren(self):
children = []
children.extend(flatten(self.nodes))
children.append(self.dest)
return tuple(children)
def getChildNodes(self):
nodelist = []
nodelist.extend(flatten_nodes(self.nodes))
if self.dest is not None:
nodelist.append(self.dest)
return tuple(nodelist)
def __repr__(self):
return "Print(%s, %s)" % (repr(self.nodes), repr(self.dest))
class Printnl(Node):
def __init__(self, nodes, dest, lineno=None):
self.nodes = nodes
self.dest = dest
self.lineno = lineno
def getChildren(self):
children = []
children.extend(flatten(self.nodes))
children.append(self.dest)
return tuple(children)
def getChildNodes(self):
nodelist = []
nodelist.extend(flatten_nodes(self.nodes))
if self.dest is not None:
nodelist.append(self.dest)
return tuple(nodelist)
def __repr__(self):
return "Printnl(%s, %s)" % (repr(self.nodes), repr(self.dest))
class Raise(Node): class Raise(Node):
def __init__(self, expr1, expr2, expr3, lineno=None): def __init__(self, expr1, expr2, expr3, lineno=None):
self.expr1 = expr1 self.expr1 = expr1
......
...@@ -783,8 +783,7 @@ class StackDepthTracker: ...@@ -783,8 +783,7 @@ class StackDepthTracker:
'DELETE_SLICE+3': -3, 'DELETE_SLICE+3': -3,
'STORE_SUBSCR': -3, 'STORE_SUBSCR': -3,
'DELETE_SUBSCR': -2, 'DELETE_SUBSCR': -2,
# PRINT_EXPR? 'PRINT_EXPR': -1,
'PRINT_ITEM': -1,
'RETURN_VALUE': -1, 'RETURN_VALUE': -1,
'YIELD_VALUE': -1, 'YIELD_VALUE': -1,
'BUILD_CLASS': -2, 'BUILD_CLASS': -2,
......
...@@ -1130,29 +1130,6 @@ class CodeGenerator: ...@@ -1130,29 +1130,6 @@ class CodeGenerator:
opcode = callfunc_opcode_info[have_star, have_dstar] opcode = callfunc_opcode_info[have_star, have_dstar]
self.emit(opcode, kw << 8 | pos) self.emit(opcode, kw << 8 | pos)
def visitPrint(self, node, newline=0):
self.set_lineno(node)
if node.dest:
self.visit(node.dest)
for child in node.nodes:
if node.dest:
self.emit('DUP_TOP')
self.visit(child)
if node.dest:
self.emit('ROT_TWO')
self.emit('PRINT_ITEM_TO')
else:
self.emit('PRINT_ITEM')
if node.dest and not newline:
self.emit('POP_TOP')
def visitPrintnl(self, node):
self.visitPrint(node, newline=1)
if node.dest:
self.emit('PRINT_NEWLINE_TO')
else:
self.emit('PRINT_NEWLINE')
def visitReturn(self, node): def visitReturn(self, node):
self.set_lineno(node) self.set_lineno(node)
self.visit(node.value) self.visit(node.value)
......
...@@ -387,26 +387,6 @@ class Transformer: ...@@ -387,26 +387,6 @@ class Transformer:
return AugAssign(lval, op[1], exprNode, lineno=op[2]) return AugAssign(lval, op[1], exprNode, lineno=op[2])
raise WalkerError, "can't get here" raise WalkerError, "can't get here"
def print_stmt(self, nodelist):
# print ([ test (',' test)* [','] ] | '>>' test [ (',' test)+ [','] ])
items = []
if len(nodelist) == 1:
start = 1
dest = None
elif nodelist[1][0] == token.RIGHTSHIFT:
assert len(nodelist) == 3 \
or nodelist[3][0] == token.COMMA
dest = self.com_node(nodelist[2])
start = 4
else:
dest = None
start = 1
for i in range(start, len(nodelist), 2):
items.append(self.com_node(nodelist[i]))
if nodelist[-1][0] == token.COMMA:
return Print(items, dest, lineno=nodelist[0][2])
return Printnl(items, dest, lineno=nodelist[0][2])
def del_stmt(self, nodelist): def del_stmt(self, nodelist):
return self.com_assign(nodelist[1], OP_DELETE) return self.com_assign(nodelist[1], OP_DELETE)
...@@ -1480,7 +1460,6 @@ _legal_node_types = [ ...@@ -1480,7 +1460,6 @@ _legal_node_types = [
symbol.simple_stmt, symbol.simple_stmt,
symbol.compound_stmt, symbol.compound_stmt,
symbol.expr_stmt, symbol.expr_stmt,
symbol.print_stmt,
symbol.del_stmt, symbol.del_stmt,
symbol.pass_stmt, symbol.pass_stmt,
symbol.break_stmt, symbol.break_stmt,
......
...@@ -100,10 +100,7 @@ def_op('INPLACE_POWER', 67) ...@@ -100,10 +100,7 @@ def_op('INPLACE_POWER', 67)
def_op('GET_ITER', 68) def_op('GET_ITER', 68)
def_op('PRINT_EXPR', 70) def_op('PRINT_EXPR', 70)
def_op('PRINT_ITEM', 71)
def_op('PRINT_NEWLINE', 72)
def_op('PRINT_ITEM_TO', 73)
def_op('PRINT_NEWLINE_TO', 74)
def_op('INPLACE_LSHIFT', 75) def_op('INPLACE_LSHIFT', 75)
def_op('INPLACE_RSHIFT', 76) def_op('INPLACE_RSHIFT', 76)
def_op('INPLACE_AND', 77) def_op('INPLACE_AND', 77)
......
...@@ -30,74 +30,73 @@ simple_stmt = 272 ...@@ -30,74 +30,73 @@ simple_stmt = 272
small_stmt = 273 small_stmt = 273
expr_stmt = 274 expr_stmt = 274
augassign = 275 augassign = 275
print_stmt = 276 del_stmt = 276
del_stmt = 277 pass_stmt = 277
pass_stmt = 278 flow_stmt = 278
flow_stmt = 279 break_stmt = 279
break_stmt = 280 continue_stmt = 280
continue_stmt = 281 return_stmt = 281
return_stmt = 282 yield_stmt = 282
yield_stmt = 283 raise_stmt = 283
raise_stmt = 284 import_stmt = 284
import_stmt = 285 import_name = 285
import_name = 286 import_from = 286
import_from = 287 import_as_name = 287
import_as_name = 288 dotted_as_name = 288
dotted_as_name = 289 import_as_names = 289
import_as_names = 290 dotted_as_names = 290
dotted_as_names = 291 dotted_name = 291
dotted_name = 292 global_stmt = 292
global_stmt = 293 assert_stmt = 293
assert_stmt = 294 compound_stmt = 294
compound_stmt = 295 if_stmt = 295
if_stmt = 296 while_stmt = 296
while_stmt = 297 for_stmt = 297
for_stmt = 298 try_stmt = 298
try_stmt = 299 with_stmt = 299
with_stmt = 300 with_var = 300
with_var = 301 except_clause = 301
except_clause = 302 suite = 302
suite = 303 testlist_safe = 303
testlist_safe = 304 old_test = 304
old_test = 305 old_lambdef = 305
old_lambdef = 306 test = 306
test = 307 or_test = 307
or_test = 308 and_test = 308
and_test = 309 not_test = 309
not_test = 310 comparison = 310
comparison = 311 comp_op = 311
comp_op = 312 expr = 312
expr = 313 xor_expr = 313
xor_expr = 314 and_expr = 314
and_expr = 315 shift_expr = 315
shift_expr = 316 arith_expr = 316
arith_expr = 317 term = 317
term = 318 factor = 318
factor = 319 power = 319
power = 320 atom = 320
atom = 321 listmaker = 321
listmaker = 322 testlist_gexp = 322
testlist_gexp = 323 lambdef = 323
lambdef = 324 trailer = 324
trailer = 325 subscriptlist = 325
subscriptlist = 326 subscript = 326
subscript = 327 sliceop = 327
sliceop = 328 exprlist = 328
exprlist = 329 testlist = 329
testlist = 330 dictsetmaker = 330
dictsetmaker = 331 classdef = 331
classdef = 332 arglist = 332
arglist = 333 argument = 333
argument = 334 list_iter = 334
list_iter = 335 list_for = 335
list_for = 336 list_if = 336
list_if = 337 gen_iter = 337
gen_iter = 338 gen_for = 338
gen_for = 339 gen_if = 339
gen_if = 340 testlist1 = 340
testlist1 = 341 encoding_decl = 341
encoding_decl = 342 yield_expr = 342
yield_expr = 343
#--end constants-- #--end constants--
sym_name = {} sym_name = {}
......
...@@ -30,8 +30,6 @@ exec_tests = [ ...@@ -30,8 +30,6 @@ exec_tests = [
"v = 1", "v = 1",
# AugAssign # AugAssign
"v += 1", "v += 1",
# Print
"print >>f, 1, ",
# For # For
"for v in v:pass", "for v in v:pass",
# While # While
...@@ -157,7 +155,6 @@ exec_results = [ ...@@ -157,7 +155,6 @@ exec_results = [
('Module', [('Delete', (1, 0), [('Name', (1, 4), 'v', ('Del',))])]), ('Module', [('Delete', (1, 0), [('Name', (1, 4), 'v', ('Del',))])]),
('Module', [('Assign', (1, 0), [('Name', (1, 0), 'v', ('Store',))], ('Num', (1, 4), 1))]), ('Module', [('Assign', (1, 0), [('Name', (1, 0), 'v', ('Store',))], ('Num', (1, 4), 1))]),
('Module', [('AugAssign', (1, 0), ('Name', (1, 0), 'v', ('Store',)), ('Add',), ('Num', (1, 5), 1))]), ('Module', [('AugAssign', (1, 0), ('Name', (1, 0), 'v', ('Store',)), ('Add',), ('Num', (1, 5), 1))]),
('Module', [('Print', (1, 0), ('Name', (1, 8), 'f', ('Load',)), [('Num', (1, 11), 1)], False)]),
('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Pass', (1, 11))], [])]), ('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Pass', (1, 11))], [])]),
('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8))], [])]), ('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8))], [])]),
('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]), ('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]),
......
...@@ -127,7 +127,7 @@ class AllTests: ...@@ -127,7 +127,7 @@ class AllTests:
method_template = """\ method_template = """\
def __%(method)s__(self, *args): def __%(method)s__(self, *args):
print "__%(method)s__:", args print("__%(method)s__:", args)
""" """
d = {} d = {}
......
...@@ -58,7 +58,7 @@ consts: ('None',) ...@@ -58,7 +58,7 @@ consts: ('None',)
name: attrs name: attrs
argcount: 1 argcount: 1
kwonlyargcount: 0 kwonlyargcount: 0
names: ('attr1', 'attr2', 'attr3') names: ('print', 'attr1', 'attr2', 'attr3')
varnames: ('obj',) varnames: ('obj',)
cellvars: () cellvars: ()
freevars: () freevars: ()
......
...@@ -36,28 +36,28 @@ test_1 = """ ...@@ -36,28 +36,28 @@ test_1 = """
Here's the new type at work: Here's the new type at work:
>>> print(defaultdict) # show our type >>> print(defaultdict) # show our type
<class 'test.test_descrtut.defaultdict'> <class 'test.test_descrtut.defaultdict'>
>>> print(type(defaultdict)) # its metatype >>> print(type(defaultdict)) # its metatype
<type 'type'> <type 'type'>
>>> a = defaultdict(default=0.0) # create an instance >>> a = defaultdict(default=0.0) # create an instance
>>> print(a) # show the instance >>> print(a) # show the instance
{} {}
>>> print(type(a)) # show its type >>> print(type(a)) # show its type
<class 'test.test_descrtut.defaultdict'> <class 'test.test_descrtut.defaultdict'>
>>> print(a.__class__) # show its class >>> print(a.__class__) # show its class
<class 'test.test_descrtut.defaultdict'> <class 'test.test_descrtut.defaultdict'>
>>> print(type(a) is a.__class__) # its type is its class >>> print(type(a) is a.__class__) # its type is its class
True True
>>> a[1] = 3.25 # modify the instance >>> a[1] = 3.25 # modify the instance
>>> print(a) # show the new value >>> print(a) # show the new value
{1: 3.25} {1: 3.25}
>>> print(a[1]) # show the new item >>> print(a[1]) # show the new item
3.25 3.25
>>> print(a[0]) # a non-existant item >>> print(a[0]) # a non-existant item
0.0 0.0
>>> a.merge({1:100, 2:200}) # use a dict method >>> a.merge({1:100, 2:200}) # use a dict method
>>> print(sortdict(a)) # show the result >>> print(sortdict(a)) # show the result
{1: 3.25, 2: 200} {1: 3.25, 2: 200}
>>> >>>
...@@ -67,10 +67,11 @@ statement or the built-in function eval(): ...@@ -67,10 +67,11 @@ statement or the built-in function eval():
>>> print(sorted(a.keys())) >>> print(sorted(a.keys()))
[1, 2] [1, 2]
>>> exec("x = 3; print x", a) >>> a['print'] = print # need the print function here
>>> exec("x = 3; print(x)", a)
3 3
>>> print(sorted(a.keys(), key=lambda x: (str(type(x)), x))) >>> print(sorted(a.keys(), key=lambda x: (str(type(x)), x)))
[1, 2, '__builtins__', 'x'] [1, 2, '__builtins__', 'print', 'x']
>>> print(a['x']) >>> print(a['x'])
3 3
>>> >>>
......
...@@ -12,12 +12,13 @@ def _f(a): ...@@ -12,12 +12,13 @@ def _f(a):
return 1 return 1
dis_f = """\ dis_f = """\
%-4d 0 LOAD_FAST 0 (a) %-4d 0 LOAD_GLOBAL 0 (print)
3 PRINT_ITEM 3 LOAD_FAST 0 (a)
4 PRINT_NEWLINE 6 CALL_FUNCTION 1
9 POP_TOP
%-4d 5 LOAD_CONST 1 (1) %-4d 10 LOAD_CONST 1 (1)
8 RETURN_VALUE 13 RETURN_VALUE
"""%(_f.func_code.co_firstlineno + 1, """%(_f.func_code.co_firstlineno + 1,
_f.func_code.co_firstlineno + 2) _f.func_code.co_firstlineno + 2)
......
...@@ -260,8 +260,8 @@ for args in ['', 'a', 'ab']: ...@@ -260,8 +260,8 @@ for args in ['', 'a', 'ab']:
lambda x: '%s="%s"' % (x, x), defargs) lambda x: '%s="%s"' % (x, x), defargs)
if vararg: arglist.append('*' + vararg) if vararg: arglist.append('*' + vararg)
if kwarg: arglist.append('**' + kwarg) if kwarg: arglist.append('**' + kwarg)
decl = (('def %s(%s): print "ok %s", a, b, d, e, v, ' + decl = (('def %s(%s): print("ok %s", a, b, d, e, v, ' +
'type(k) is type ("") and k or sortdict(k)') 'type(k) is type ("") and k or sortdict(k))')
% (name, ', '.join(arglist), name)) % (name, ', '.join(arglist), name))
exec(decl) exec(decl)
func = eval(name) func = eval(name)
......
...@@ -85,14 +85,6 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase): ...@@ -85,14 +85,6 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
self.check_expr("(x for x in range(10))") self.check_expr("(x for x in range(10))")
self.check_expr("foo(x for x in range(10))") self.check_expr("foo(x for x in range(10))")
def test_print(self):
self.check_suite("print")
self.check_suite("print 1")
self.check_suite("print 1,")
self.check_suite("print >>fp")
self.check_suite("print >>fp, 1")
self.check_suite("print >>fp, 1,")
def test_simple_expression(self): def test_simple_expression(self):
# expr_stmt # expr_stmt
self.check_suite("a") self.check_suite("a")
...@@ -359,29 +351,6 @@ class IllegalSyntaxTestCase(unittest.TestCase): ...@@ -359,29 +351,6 @@ class IllegalSyntaxTestCase(unittest.TestCase):
(0, '')))) (0, ''))))
self.check_bad_tree(tree, "def f():\n return 1\n yield 1") self.check_bad_tree(tree, "def f():\n return 1\n yield 1")
def test_print_chevron_comma(self):
# Illegal input: print >>fp,
tree = \
(257,
(264,
(265,
(266,
(268,
(1, 'print'),
(35, '>>'),
(290,
(291,
(292,
(293,
(295,
(296,
(297,
(298, (299, (300, (301, (302, (303, (1, 'fp')))))))))))))),
(12, ','))),
(4, ''))),
(0, ''))
self.check_bad_tree(tree, "print >>fp,")
def test_a_comma_comma_c(self): def test_a_comma_comma_c(self):
# Illegal input: a,,c # Illegal input: a,,c
tree = \ tree = \
......
...@@ -81,122 +81,122 @@ tests = [ ...@@ -81,122 +81,122 @@ tests = [
("t2", [ ("t2", [
("t2", None), ("t2", None),
("t2 __init__"+os.extsep+"py", "'doc for t2'; print __name__, 'loading'"), ("t2 __init__"+os.extsep+"py", "'doc for t2'; print(__name__, 'loading')"),
("t2 sub", None), ("t2 sub", None),
("t2 sub __init__"+os.extsep+"py", ""), ("t2 sub __init__"+os.extsep+"py", ""),
("t2 sub subsub", None), ("t2 sub subsub", None),
("t2 sub subsub __init__"+os.extsep+"py", "print __name__, 'loading'; spam = 1"), ("t2 sub subsub __init__"+os.extsep+"py", "print(__name__, 'loading'); spam = 1"),
], ],
""" """
import t2 import t2
print t2.__doc__ print(t2.__doc__)
import t2.sub import t2.sub
import t2.sub.subsub import t2.sub.subsub
print t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__ print(t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__)
import t2 import t2
from t2 import * from t2 import *
print dir() print(dir())
from t2 import sub from t2 import sub
from t2.sub import subsub from t2.sub import subsub
from t2.sub.subsub import spam from t2.sub.subsub import spam
print sub.__name__, subsub.__name__ print(sub.__name__, subsub.__name__)
print sub.subsub.__name__ print(sub.subsub.__name__)
print dir() print(dir())
import t2.sub import t2.sub
import t2.sub.subsub import t2.sub.subsub
print t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__ print(t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__)
from t2 import * from t2 import *
print dir() print(dir())
"""), """),
("t3", [ ("t3", [
("t3", None), ("t3", None),
("t3 __init__"+os.extsep+"py", "print __name__, 'loading'"), ("t3 __init__"+os.extsep+"py", "print(__name__, 'loading')"),
("t3 sub", None), ("t3 sub", None),
("t3 sub __init__"+os.extsep+"py", ""), ("t3 sub __init__"+os.extsep+"py", ""),
("t3 sub subsub", None), ("t3 sub subsub", None),
("t3 sub subsub __init__"+os.extsep+"py", "print __name__, 'loading'; spam = 1"), ("t3 sub subsub __init__"+os.extsep+"py", "print(__name__, 'loading'); spam = 1"),
], ],
""" """
import t3.sub.subsub import t3.sub.subsub
print t3.__name__, t3.sub.__name__, t3.sub.subsub.__name__ print(t3.__name__, t3.sub.__name__, t3.sub.subsub.__name__)
reload(t3) reload(t3)
reload(t3.sub) reload(t3.sub)
reload(t3.sub.subsub) reload(t3.sub.subsub)
"""), """),
("t4", [ ("t4", [
("t4"+os.extsep+"py", "print 'THIS SHOULD NOT BE PRINTED (t4"+os.extsep+"py)'"), ("t4"+os.extsep+"py", "print('THIS SHOULD NOT BE PRINTED (t4"+os.extsep+"py)')"),
("t4", None), ("t4", None),
("t4 __init__"+os.extsep+"py", "print __name__, 'loading'"), ("t4 __init__"+os.extsep+"py", "print(__name__, 'loading')"),
("t4 sub"+os.extsep+"py", "print 'THIS SHOULD NOT BE PRINTED (sub"+os.extsep+"py)'"), ("t4 sub"+os.extsep+"py", "print('THIS SHOULD NOT BE PRINTED (sub"+os.extsep+"py)')"),
("t4 sub", None), ("t4 sub", None),
("t4 sub __init__"+os.extsep+"py", ""), ("t4 sub __init__"+os.extsep+"py", ""),
("t4 sub subsub"+os.extsep+"py", "print 'THIS SHOULD NOT BE PRINTED (subsub"+os.extsep+"py)'"), ("t4 sub subsub"+os.extsep+"py", "print('THIS SHOULD NOT BE PRINTED (subsub"+os.extsep+"py)')"),
("t4 sub subsub", None), ("t4 sub subsub", None),
("t4 sub subsub __init__"+os.extsep+"py", "print __name__, 'loading'; spam = 1"), ("t4 sub subsub __init__"+os.extsep+"py", "print(__name__, 'loading'); spam = 1"),
], ],
""" """
from t4.sub.subsub import * from t4.sub.subsub import *
print "t4.sub.subsub.spam =", spam print("t4.sub.subsub.spam =", spam)
"""), """),
("t5", [ ("t5", [
("t5", None), ("t5", None),
("t5 __init__"+os.extsep+"py", "import t5.foo"), ("t5 __init__"+os.extsep+"py", "import t5.foo"),
("t5 string"+os.extsep+"py", "print __name__, 'loading'; spam = 1"), ("t5 string"+os.extsep+"py", "print(__name__, 'loading'); spam = 1"),
("t5 foo"+os.extsep+"py", ("t5 foo"+os.extsep+"py",
"print __name__, 'loading'; from . import string; print string.spam"), "print(__name__, 'loading'); from . import string; print(string.spam)"),
], ],
""" """
import t5 import t5
from t5 import * from t5 import *
print dir() print(dir())
import t5 import t5
print fixdir(dir(t5)) print(fixdir(dir(t5)))
print fixdir(dir(t5.foo)) print(fixdir(dir(t5.foo)))
print fixdir(dir(t5.string)) print(fixdir(dir(t5.string)))
"""), """),
("t6", [ ("t6", [
("t6", None), ("t6", None),
("t6 __init__"+os.extsep+"py", "__all__ = ['spam', 'ham', 'eggs']"), ("t6 __init__"+os.extsep+"py", "__all__ = ['spam', 'ham', 'eggs']"),
("t6 spam"+os.extsep+"py", "print __name__, 'loading'"), ("t6 spam"+os.extsep+"py", "print(__name__, 'loading')"),
("t6 ham"+os.extsep+"py", "print __name__, 'loading'"), ("t6 ham"+os.extsep+"py", "print(__name__, 'loading')"),
("t6 eggs"+os.extsep+"py", "print __name__, 'loading'"), ("t6 eggs"+os.extsep+"py", "print(__name__, 'loading')"),
], ],
""" """
import t6 import t6
print fixdir(dir(t6)) print(fixdir(dir(t6)))
from t6 import * from t6 import *
print fixdir(dir(t6)) print(fixdir(dir(t6)))
print dir() print(dir())
"""), """),
("t7", [ ("t7", [
("t7"+os.extsep+"py", "print 'Importing t7"+os.extsep+"py'"), ("t7"+os.extsep+"py", "print('Importing t7"+os.extsep+"py')"),
("t7", None), ("t7", None),
("t7 __init__"+os.extsep+"py", "print __name__, 'loading'"), ("t7 __init__"+os.extsep+"py", "print(__name__, 'loading')"),
("t7 sub"+os.extsep+"py", "print 'THIS SHOULD NOT BE PRINTED (sub"+os.extsep+"py)'"), ("t7 sub"+os.extsep+"py", "print('THIS SHOULD NOT BE PRINTED (sub"+os.extsep+"py)')"),
("t7 sub", None), ("t7 sub", None),
("t7 sub __init__"+os.extsep+"py", ""), ("t7 sub __init__"+os.extsep+"py", ""),
("t7 sub subsub"+os.extsep+"py", "print 'THIS SHOULD NOT BE PRINTED (subsub"+os.extsep+"py)'"), ("t7 sub subsub"+os.extsep+"py", "print('THIS SHOULD NOT BE PRINTED (subsub"+os.extsep+"py)')"),
("t7 sub subsub", None), ("t7 sub subsub", None),
("t7 sub subsub __init__"+os.extsep+"py", "print __name__, 'loading'; spam = 1"), ("t7 sub subsub __init__"+os.extsep+"py", "print(__name__, 'loading'); spam = 1"),
], ],
""" """
t7, sub, subsub = None, None, None t7, sub, subsub = None, None, None
import t7 as tas import t7 as tas
print fixdir(dir(tas)) print(fixdir(dir(tas)))
verify(not t7) verify(not t7)
from t7 import sub as subpar from t7 import sub as subpar
print fixdir(dir(subpar)) print(fixdir(dir(subpar)))
verify(not t7 and not sub) verify(not t7 and not sub)
from t7.sub import subsub as subsubsub from t7.sub import subsub as subsubsub
print fixdir(dir(subsubsub)) print(fixdir(dir(subsubsub)))
verify(not t7 and not sub and not subsub) verify(not t7 and not sub and not subsub)
from t7.sub.subsub import spam as ham from t7.sub.subsub import spam as ham
print "t7.sub.subsub.spam =", ham print("t7.sub.subsub.spam =", ham)
verify(not t7 and not sub and not subsub) verify(not t7 and not sub and not subsub)
"""), """),
......
...@@ -19,7 +19,7 @@ if ' ' in python: ...@@ -19,7 +19,7 @@ if ' ' in python:
class PopenTest(unittest.TestCase): class PopenTest(unittest.TestCase):
def _do_test_commandline(self, cmdline, expected): def _do_test_commandline(self, cmdline, expected):
cmd = '%s -c "import sys;print sys.argv" %s' % (python, cmdline) cmd = '%s -c "import sys; print(sys.argv)" %s' % (python, cmdline)
data = os.popen(cmd).read() data = os.popen(cmd).read()
got = eval(data)[1:] # strip off argv[0] got = eval(data)[1:] # strip off argv[0]
self.assertEqual(got, expected) self.assertEqual(got, expected)
......
...@@ -84,7 +84,7 @@ class ProcessTestCase(unittest.TestCase): ...@@ -84,7 +84,7 @@ class ProcessTestCase(unittest.TestCase):
def test_stdin_none(self): def test_stdin_none(self):
# .stdin is None when not redirected # .stdin is None when not redirected
p = subprocess.Popen([sys.executable, "-c", 'print "banana"'], p = subprocess.Popen([sys.executable, "-c", 'print("banana")'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait() p.wait()
self.assertEqual(p.stdin, None) self.assertEqual(p.stdin, None)
...@@ -92,16 +92,16 @@ class ProcessTestCase(unittest.TestCase): ...@@ -92,16 +92,16 @@ class ProcessTestCase(unittest.TestCase):
def test_stdout_none(self): def test_stdout_none(self):
# .stdout is None when not redirected # .stdout is None when not redirected
p = subprocess.Popen([sys.executable, "-c", p = subprocess.Popen([sys.executable, "-c",
'print " this bit of output is from a ' 'print(" this bit of output is from a '
'test of stdout in a different ' 'test of stdout in a different '
'process ..."'], 'process ...")'],
stdin=subprocess.PIPE, stderr=subprocess.PIPE) stdin=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait() p.wait()
self.assertEqual(p.stdout, None) self.assertEqual(p.stdout, None)
def test_stderr_none(self): def test_stderr_none(self):
# .stderr is None when not redirected # .stderr is None when not redirected
p = subprocess.Popen([sys.executable, "-c", 'print "banana"'], p = subprocess.Popen([sys.executable, "-c", 'print("banana")'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE) stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.wait() p.wait()
self.assertEqual(p.stderr, None) self.assertEqual(p.stderr, None)
......
...@@ -423,7 +423,7 @@ class SyntaxTestCase(unittest.TestCase): ...@@ -423,7 +423,7 @@ class SyntaxTestCase(unittest.TestCase):
source = re.sub('(?m)^ *:', '', """\ source = re.sub('(?m)^ *:', '', """\
:def foo(x): :def foo(x):
: def bar(): : def bar():
: print x : print(x)
: del x : del x
:""") :""")
self._check_error(source, "nested scope") self._check_error(source, "nested scope")
......
...@@ -43,9 +43,9 @@ regenerate the original program text from the tokens. ...@@ -43,9 +43,9 @@ regenerate the original program text from the tokens.
There are some standard formatting practices that are easy to get right. There are some standard formatting practices that are easy to get right.
>>> roundtrip("if x == 1:\\n" >>> roundtrip("if x == 1:\\n"
... " print x\\n") ... " print(x)\\n")
if x == 1: if x == 1:
print x print(x)
Some people use different formatting conventions, which makes Some people use different formatting conventions, which makes
untokenize a little trickier. Note that this test involves trailing untokenize a little trickier. Note that this test involves trailing
...@@ -53,29 +53,29 @@ whitespace after the colon. Note that we use hex escapes to make the ...@@ -53,29 +53,29 @@ whitespace after the colon. Note that we use hex escapes to make the
two trailing blanks apparent in the expected output. two trailing blanks apparent in the expected output.
>>> roundtrip("if x == 1 : \\n" >>> roundtrip("if x == 1 : \\n"
... " print x\\n") ... " print(x)\\n")
if x == 1 :\x20\x20 if x == 1 :\x20\x20
print x print(x)
Comments need to go in the right place. Comments need to go in the right place.
>>> roundtrip("if x == 1:\\n" >>> roundtrip("if x == 1:\\n"
... " # A comment by itself.\\n" ... " # A comment by itself.\\n"
... " print x # Comment here, too.\\n" ... " print(x) # Comment here, too.\\n"
... " # Another comment.\\n" ... " # Another comment.\\n"
... "after_if = True\\n") ... "after_if = True\\n")
if x == 1: if x == 1:
# A comment by itself. # A comment by itself.
print x # Comment here, too. print(x) # Comment here, too.
# Another comment. # Another comment.
after_if = True after_if = True
>>> roundtrip("if (x # The comments need to go in the right place\\n" >>> roundtrip("if (x # The comments need to go in the right place\\n"
... " == 1):\\n" ... " == 1):\\n"
... " print 'x == 1'\\n") ... " print('x == 1')\\n")
if (x # The comments need to go in the right place if (x # The comments need to go in the right place
== 1): == 1):
print 'x == 1' print('x == 1')
""" """
...@@ -130,9 +130,9 @@ def decistmt(s): ...@@ -130,9 +130,9 @@ def decistmt(s):
"""Substitute Decimals for floats in a string of statements. """Substitute Decimals for floats in a string of statements.
>>> from decimal import Decimal >>> from decimal import Decimal
>>> s = 'print +21.3e-5*-.1234/81.7' >>> s = 'print(+21.3e-5*-.1234/81.7)'
>>> decistmt(s) >>> decistmt(s)
"print +Decimal ('21.3e-5')*-Decimal ('.1234')/Decimal ('81.7')" "print (+Decimal ('21.3e-5')*-Decimal ('.1234')/Decimal ('81.7'))"
The format of the exponent is inherited from the platform C library. The format of the exponent is inherited from the platform C library.
Known cases are "e-007" (Windows) and "e-07" (not Windows). Since Known cases are "e-007" (Windows) and "e-07" (not Windows). Since
......
...@@ -25,7 +25,7 @@ class TracebackCases(unittest.TestCase): ...@@ -25,7 +25,7 @@ class TracebackCases(unittest.TestCase):
import test.badsyntax_nocaret import test.badsyntax_nocaret
def syntax_error_bad_indentation(self): def syntax_error_bad_indentation(self):
compile("def spam():\n print 1\n print 2", "?", "exec") compile("def spam():\n print(1)\n print(2)", "?", "exec")
def test_caret(self): def test_caret(self):
err = self.get_exception_format(self.syntax_error_with_caret, err = self.get_exception_format(self.syntax_error_with_caret,
...@@ -48,9 +48,9 @@ class TracebackCases(unittest.TestCase): ...@@ -48,9 +48,9 @@ class TracebackCases(unittest.TestCase):
err = self.get_exception_format(self.syntax_error_bad_indentation, err = self.get_exception_format(self.syntax_error_bad_indentation,
IndentationError) IndentationError)
self.assert_(len(err) == 4) self.assert_(len(err) == 4)
self.assert_(err[1].strip() == "print 2") self.assert_(err[1].strip() == "print(2)")
self.assert_("^" in err[2]) self.assert_("^" in err[2])
self.assert_(err[1].find("2") == err[2].find("^")) self.assert_(err[1].find(")") == err[2].find("^"))
def test_bug737473(self): def test_bug737473(self):
import sys, os, tempfile, time import sys, os, tempfile, time
......
...@@ -18,9 +18,6 @@ module Python version "$Revision$" ...@@ -18,9 +18,6 @@ module Python version "$Revision$"
| Assign(expr* targets, expr value) | Assign(expr* targets, expr value)
| AugAssign(expr target, operator op, expr value) | AugAssign(expr target, operator op, expr value)
-- not sure if bool is allowed, can always use int
| Print(expr? dest, expr* values, bool nl)
-- use 'orelse' because else is a keyword in target languages -- use 'orelse' because else is a keyword in target languages
| For(expr target, expr iter, stmt* body, stmt* orelse) | For(expr target, expr iter, stmt* body, stmt* orelse)
| While(expr test, stmt* body, stmt* orelse) | While(expr test, stmt* body, stmt* orelse)
......
...@@ -61,12 +61,6 @@ static char *AugAssign_fields[]={ ...@@ -61,12 +61,6 @@ static char *AugAssign_fields[]={
"op", "op",
"value", "value",
}; };
static PyTypeObject *Print_type;
static char *Print_fields[]={
"dest",
"values",
"nl",
};
static PyTypeObject *For_type; static PyTypeObject *For_type;
static char *For_fields[]={ static char *For_fields[]={
"target", "target",
...@@ -480,8 +474,6 @@ static int init_types(void) ...@@ -480,8 +474,6 @@ static int init_types(void)
if (!Assign_type) return 0; if (!Assign_type) return 0;
AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
if (!AugAssign_type) return 0; 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); For_type = make_type("For", stmt_type, For_fields, 4);
if (!For_type) return 0; if (!For_type) return 0;
While_type = make_type("While", stmt_type, While_fields, 3); While_type = make_type("While", stmt_type, While_fields, 3);
...@@ -948,25 +940,6 @@ AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int ...@@ -948,25 +940,6 @@ AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
return p; return p;
} }
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 stmt_ty
For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
lineno, int col_offset, PyArena *arena) lineno, int col_offset, PyArena *arena)
...@@ -2118,25 +2091,6 @@ ast2obj_stmt(void* _o) ...@@ -2118,25 +2091,6 @@ ast2obj_stmt(void* _o)
goto failed; goto failed;
Py_DECREF(value); Py_DECREF(value);
break; 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: case For_kind:
result = PyType_GenericNew(For_type, NULL, NULL); result = PyType_GenericNew(For_type, NULL, NULL);
if (!result) goto failed; if (!result) goto failed;
...@@ -3149,7 +3103,6 @@ init_ast(void) ...@@ -3149,7 +3103,6 @@ init_ast(void)
return; return;
if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
0) return; 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, "For", (PyObject*)For_type) < 0) return;
if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
......
...@@ -1398,7 +1398,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds) ...@@ -1398,7 +1398,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
if (dummy_args == NULL) if (dummy_args == NULL)
return NULL; return NULL;
if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:Print", if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:print",
kwlist, &sep, &end, &file)) kwlist, &sep, &end, &file))
return NULL; return NULL;
if (file == NULL || file == Py_None) if (file == NULL || file == Py_None)
......
...@@ -524,7 +524,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) ...@@ -524,7 +524,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
register PyObject *w; register PyObject *w;
register PyObject *u; register PyObject *u;
register PyObject *t; register PyObject *t;
register PyObject *stream = NULL; /* for PRINT opcodes */
register PyObject **fastlocals, **freevars; register PyObject **fastlocals, **freevars;
PyObject *retval = NULL; /* Return value */ PyObject *retval = NULL; /* Return value */
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = PyThreadState_GET();
...@@ -1508,81 +1507,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) ...@@ -1508,81 +1507,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
Py_XDECREF(x); Py_XDECREF(x);
break; 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 #ifdef CASE_TOO_BIG
default: switch (opcode) { default: switch (opcode) {
#endif #endif
......
...@@ -734,14 +734,6 @@ opcode_stack_effect(int opcode, int oparg) ...@@ -734,14 +734,6 @@ opcode_stack_effect(int opcode, int oparg)
case PRINT_EXPR: case PRINT_EXPR:
return -1; 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_LSHIFT:
case INPLACE_RSHIFT: case INPLACE_RSHIFT:
case INPLACE_AND: case INPLACE_AND:
...@@ -1625,43 +1617,6 @@ compiler_lambda(struct compiler *c, expr_ty e) ...@@ -1625,43 +1617,6 @@ compiler_lambda(struct compiler *c, expr_ty e)
return 1; return 1;
} }
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 static int
compiler_if(struct compiler *c, stmt_ty s) compiler_if(struct compiler *c, stmt_ty s)
{ {
...@@ -2236,8 +2191,6 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s) ...@@ -2236,8 +2191,6 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
break; break;
case AugAssign_kind: case AugAssign_kind:
return compiler_augassign(c, s); return compiler_augassign(c, s);
case Print_kind:
return compiler_print(c, s);
case For_kind: case For_kind:
return compiler_for(c, s); return compiler_for(c, s);
case While_kind: case While_kind:
......
...@@ -990,11 +990,6 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) ...@@ -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.target);
VISIT(st, expr, s->v.AugAssign.value); VISIT(st, expr, s->v.AugAssign.value);
break; 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: case For_kind:
VISIT(st, expr, s->v.For.target); VISIT(st, expr, s->v.For.target);
VISIT(st, expr, s->v.For.iter); VISIT(st, expr, s->v.For.iter);
......
...@@ -904,7 +904,7 @@ exitfunc -- if sys.exitfunc exists, this routine is called when Python exits\n\ ...@@ -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\ Assigning to sys.exitfunc is deprecated; use the atexit module instead.\n\
\n\ \n\
stdin -- standard input file object; used by raw_input() and input()\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\ stderr -- standard error object; used for error messages\n\
By assigning other file objects (or objects that behave like files)\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\ to these, it is possible to redirect all of the interpreter's I/O.\n\
......
...@@ -34,8 +34,6 @@ TryExcept: body, handlers!, else_& ...@@ -34,8 +34,6 @@ TryExcept: body, handlers!, else_&
Return: value Return: value
Yield: value Yield: value
Const: value* Const: value*
Print: nodes!, dest&
Printnl: nodes!, dest&
Discard: expr Discard: expr
AugAssign: node, op*, expr AugAssign: node, op*, expr
Assign: nodes!, expr Assign: nodes!, expr
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment