Anonymous avatar Anonymous committed 22f30e5

Complete the conversion to Python 3.0. Update all tests using 2to3
migration script. Change 'print' to a function. Get keyword
arguments working (in order to support 'end' argument to 'print').

Comments (0)

Files changed (19)

Grammar/Actions.nqp

 method defparameter($/) {
     my $past := $( $<parameter> );
     $past.scope('parameter');
+    $past.named($past.name());
 
     ## add the default value for this parameter, if any
     if $<expression> {
     }
 
     if $<keyword_arguments> {
-        for $( $<keyword_arguments> ) {
-        ## XXX should this be: for @( $<keyword_arguments> )??
-            $past.push( $_ );
+        for $<keyword_arguments><keyword_item> {
+            $past.push($($_));
         }
     }
 
     my $past := $( $<expression> );
     my $name := $( $<identifier> );
 
-    ## XXX why doesn't this work??
-    #$past.named( $name.name() );
-    #make PAST::Val.new( :value('100'), :named('x'), :node($/) );
+    $past.named( $name.name() );
     make $past;
 }
 
 }
 
 
-method print_stmt($/) {
-    my $past := PAST::Op.new( :name('printnl'), :node($/) );
-    for $<expression> {
-        $past.push( $($_) );
-    }
-    if $/[0] {
-        $past.name('print');
-    }
-    make $past;
-}
-
-
 method expression($/, $key) {
     ## XXX incomplete.
     if $key eq 'lambda_form' {

Grammar/Grammar.pg

 ## DESCRIPTION
 ##
 ## These are a set of rules for parsing programs written in Python.
-## Many of the rules are derived from the "Python Language Reference
-## Manual", version 2.5 by Guido van Rossum (Fred L. Drake, Jr., Editor).
-## Available online at http://docs.python.org/ref/ and
-## http://docs.python.org/ref/grammar.txt .
+## Many of the rules are derived from "The Python Language Reference",
+## version 3.0.1. Available online at
+## http://docs.python.org/3.0/reference/index.html
 
 grammar Pynie::Grammar is PCT::Grammar;
 
 }
 
 rule positional_arguments {
-    <expression> [ ',' <expression> ]*
+    <expression> <!before '='>[ ',' <expression> <!before '='>]*
     {*}
 }
 
     | <expression_stmt> {*}                      #= expression_stmt
     | <pass_stmt> {*}                            #= pass_stmt
     | <del_stmt> {*}                             #= del_stmt
-    | <print_stmt> {*}                           #= print_stmt
     | <return_stmt> {*}                          #= return_stmt
     | <yield_stmt>
     | <raise_stmt> {*}                           #= raise_stmt
 
 token name { <!reserved> <[a..z]> [ <alpha> | '_' ]* }
 
-rule print_stmt {
-    'print' [ <expression> [ ',' <expression> ]* ( ',' )? ]?
-    {*}
-}
-
 rule pass_stmt {
     'pass' {*}
 }
     [ 'and'   | 'assert' | 'break'  | 'class'  | 'continue' | 'def'
     | 'del'   | 'elif'   | 'else'   | 'except' | 'exec'     | 'finally'
     | 'for'   | 'from'   | 'global' | 'if'     | 'import'   | 'in'
-    | 'is'    | 'lambda' | 'not'    | 'or'     | 'pass'     | 'print'
+    | 'is'    | 'lambda' | 'not'    | 'or'     | 'pass' 
     | 'raise' | 'return' | 'try'    | 'while'  | 'with'     | 'yield' ] >>
 }
 

Lib/test/parrot/builtins.py

 # -*- coding: utf-8 -*-
 
 #len
-print 'test: len'
+print('test: len')
 n = len([1,2,3,4])
-if n == 4: print 'success: len'
-else: print 'failure: len'
+if n == 4: print('success: len')
+else: print('failure: len')
 
 #list
-print 'test: list'
+print('test: list')
 lst1 = [ 1,2,3,4 ]
 lst2 = list(lst1)
 lst1.pop()
 lst1.pop()
 lst1.pop()
 lst1.pop()
-if lst2[2] == 3: print 'success: list'
-else: print 'failure: list'
+if lst2[2] == 3: print('success: list')
+else: print('failure: list')
 
 #range
-print 'test: range'
-lst = range(4)
+print('test: range')
+lst = list(range(4))
 ok = 0
 n = -1
 for i in lst:
     n += 1
     if n == i: ok += 1
-if ok == 4: print 'success: range'
-else: print 'failure: range'
+if ok == 4: print('success: range')
+else: print('failure: range')
 
 #str
-print 'test: str'
-if str(5) == '5': print 'success: str'
-else: print 'failure: str'
+print('test: str')
+if str(5) == '5': print('success: str')
+else: print('failure: str')
 
-print 'test: len/str'
-if len(str(861)) == 3: print 'success: len/str'
-else: print 'failure: len/str'
+print('test: len/str')
+if len(str(861)) == 3: print('success: len/str')
+else: print('failure: len/str')
 
 #cmp
-print 'test: cmp (equal)'
-if cmp(5, 5) == 0: print 'success: cmp (equal)'
-else: print 'failure: cmp (equal)'
+print('test: cmp (equal)')
+if cmp(5, 5) == 0: print('success: cmp (equal)')
+else: print('failure: cmp (equal)')
 
-print 'test: cmp (gt)'
-if cmp(5, 0) > 0: print 'success: cmp (gt)'
-else: print 'failure: cmp (gt)'
+print('test: cmp (gt)')
+if cmp(5, 0) > 0: print('success: cmp (gt)')
+else: print('failure: cmp (gt)')
 
-print 'test: cmp (lt)'
-if cmp(0, 5) < 0: print 'success: cmp (lt)'
-else: print 'failure: cmp (lt)'
+print('test: cmp (lt)')
+if cmp(0, 5) < 0: print('success: cmp (lt)')
+else: print('failure: cmp (lt)')
 
 #max
-print 'test: max (simple)'
-if max(range(5)) == 4: print 'success: max (simple)'
-else: print 'failure: max (simple)'
+print('test: max (simple)')
+if max(range(5)) == 4: print('success: max (simple)')
+else: print('failure: max (simple)')
 
-print 'test: max (mixed)'
-if max([1,98,3,8,32,8]) == 98: print 'success: max (mixed)'
-else: print 'failure: max (mixed)'
+print('test: max (mixed)')
+if max([1,98,3,8,32,8]) == 98: print('success: max (mixed)')
+else: print('failure: max (mixed)')
 
 #min
-print 'test: min (simple)'
-if min(range(5)) == 0: print 'success: min (simple)'
-else: print 'failure: min (simple)'
+print('test: min (simple)')
+if min(range(5)) == 0: print('success: min (simple)')
+else: print('failure: min (simple)')
 
-print 'test: min (mixed)'
-if min([98,1,3,8,32,8]) == 1: print 'success: min (mixed)'
-else: print 'failure: min (mixed)'
+print('test: min (mixed)')
+if min([98,1,3,8,32,8]) == 1: print('success: min (mixed)')
+else: print('failure: min (mixed)')
 
 #ord
-print 'test: ord'
-if ord('a') == 97: print 'success: ord'
-else: print 'failure: ord'
+print('test: ord')
+if ord('a') == 97: print('success: ord')
+else: print('failure: ord')
 
 #pow
-print 'test: pow (2 args)'
-if pow(2,3) == 8: print 'success: pow (2 args)'
-else: print 'failure: pow (2 args)'
+print('test: pow (2 args)')
+if pow(2,3) == 8: print('success: pow (2 args)')
+else: print('failure: pow (2 args)')
 
-print 'test: pow (3 args)'
-if pow(2,3,3) == 2: print 'success: pow (3 args)'
-else: print 'failure: pow (3 args)'
+print('test: pow (3 args)')
+if pow(2,3,3) == 2: print('success: pow (3 args)')
+else: print('failure: pow (3 args)')
 
 #sum
-print 'test: sum'
-if sum(range(5)) == 10: print 'success: sum'
-else: print 'failure: sum'
+print('test: sum')
+if sum(range(5)) == 10: print('success: sum')
+else: print('failure: sum')

Lib/test/parrot/control-flow.py

 
 # if
 
-print 'test: if true'
-if 1: print 'success: if true'
-else: print 'failure: if true'
+print('test: if true')
+if 1: print('success: if true')
+else: print('failure: if true')
 
-print 'test: if false'
-if 0: print 'failure: if false'
-else: print 'success: if false'
+print('test: if false')
+if 0: print('failure: if false')
+else: print('success: if false')
 
-print 'test: elif true'
-if 0: print 'failure: elif true'
-elif 1: print 'success: elif true'
+print('test: elif true')
+if 0: print('failure: elif true')
+elif 1: print('success: elif true')
 
-print 'test: elif false'
-if 0: print 'failure: elif false'
-elif 0: print 'failure: elif false'
-else: print 'success: elif false'
+print('test: elif false')
+if 0: print('failure: elif false')
+elif 0: print('failure: elif false')
+else: print('success: elif false')
 
 # while
 
 i=5
 while i < 7:
-    print 'test:', i
-    print 'success:', i
+    print('test:', i)
+    print('success:', i)
     i=i+1
 
-print 'test: while count'
-if i == 7: print 'success: while count'
-else: print 'failure: while count'
+print('test: while count')
+if i == 7: print('success: while count')
+else: print('failure: while count')
 
-print 'test: while false'
+print('test: while false')
 while 0:
-    print 'failure: while false'
+    print('failure: while false')
 else:
-    print 'success: while false'
+    print('success: while false')
 
 # for
 
-print 'test: for list literal'
+print('test: for list literal')
 n = 0
 compare = 1
 for i in [ 1,2,3,4 ]:
     n += 1
     if i != n: compare = 0
-if compare: print 'success: for list literal'
-else: print 'failure: for list literal'
+if compare: print('success: for list literal')
+else: print('failure: for list literal')
 
-print 'test: for list assign'
+print('test: for list assign')
 lst = [ 1,2,3,4 ]
 n = 0
 compare = 1
 for i in lst:
     n += 1
     if i != n: compare = 0
-if compare: print 'success: for list assign'
-else: print 'failure: for list assign'
+if compare: print('success: for list assign')
+else: print('failure: for list assign')
 
-print 'test: for list bare'
+print('test: for list bare')
 n = 0
 compare = 1
 for i in 1,2,3,4:
     n += 1
     if i != n: compare = 0
-if compare: print 'success: for list bare'
-else: print 'failure: for list bare'
+if compare: print('success: for list bare')
+else: print('failure: for list bare')
 
-print 'test: nested fors'
+print('test: nested fors')
 lst = [ ]
 for i in range(3):
     # XXX ResizablePMCArray has a 'push' method, use list.append
 lst2 = [ 1, 2, 3,  2, 4, 6,  3, 6, 9 ]
 for i in range(9):
     if lst[i] != lst2[i]: compare = 0
-if compare: print 'success: nested fors'
-else: print 'failure: nested fors'
+if compare: print('success: nested fors')
+else: print('failure: nested fors')
 
-print 'test: multiple iterators'
+print('test: multiple iterators')
 #compare = 0
 #for i, j in ( (0, 0), (1, 2), (2, 4) ):
 #    if j == i * 2: compare += 1
 #if compare == 3: print 'success: multiple iterators'
 #else: print 'failure: multiple iterators'
-print 'xfail: multiple iterators ['
-print 'multiple iterators not implemented yet'
-print ']'
+print('xfail: multiple iterators [')
+print('multiple iterators not implemented yet')
+print(']')
 
-print 'test: nested scopes'
+print('test: nested scopes')
 i = 4
 if 0:
     if 0: pass
     i = 2
-if i == 2: print 'failure: nested scopes'
-else: print 'success: nested scopes'
+if i == 2: print('failure: nested scopes')
+else: print('success: nested scopes')

Lib/test/parrot/exceptions.py

 #!./parrot pynie.pbc
 
-print 'test: catch exception'
+print('test: catch exception')
 try:
     x = 1
     raise Exception
 except:
     x = 2
-if x == 2: print 'success: catch exception'
-else: print 'failure: catch exception'
+if x == 2: print('success: catch exception')
+else: print('failure: catch exception')
 
-print 'test: no exception'
+print('test: no exception')
 try:
     x = 1
 except:
     x = 2
-if x == 1: print 'success: no exception'
-else: print 'failure: no exception'
+if x == 1: print('success: no exception')
+else: print('failure: no exception')
 
 # make sure asserts are on
 # XXX in real Python, you can't set __debug__
 
 __debug__ = 1
 
-print 'test: assert false'
+print('test: assert false')
 try:
     x = 1
     assert 0
 except:
     x = 2
-if x == 2: print 'success: assert false'
-else: print 'failure: assert false'
+if x == 2: print('success: assert false')
+else: print('failure: assert false')
 
-print 'test: assert true'
+print('test: assert true')
 try:
     x = 1
     assert 1
 except:
     x = 2
-if x == 1: print 'success: assert true'
-else: print 'failure: assert true'
+if x == 1: print('success: assert true')
+else: print('failure: assert true')
 
-print 'test: assert false, no debug'
+print('test: assert false, no debug')
 __debug__ = 0
 try:
     x = 1
     assert 0
 except:
     x = 2
-if x == 1: print 'success: assert false, no debug'
-else: print 'failure: assert false, no debug'
+if x == 1: print('success: assert false, no debug')
+else: print('failure: assert false, no debug')

Lib/test/parrot/functions.py

 #!./parrot pynie.pbc
 
-print 'test: define and call a function'
-
+print('test: define and call a function')
 def x():
- print "success: define and call a function"
+ print("success: define and call a function")
 
 x()
 
-print 'test: a function with arguments'
-
+print('test: a function with arguments')
 def y(a,b,c):
  pass
 
 y(1,2,3)
+print('success: a function with arguments')
 
-print 'success: a function with arguments'
+print('test: a function with keyword arguments')
+y(1,2,c=3)
+print('success: a function with keyword arguments')

Lib/test/parrot/grammar.py

 #!./parrot pynie.pbc
 
-print 'test: backslash for line continuation'
+print('test: backslash for line continuation')
 x = 1 \
 + 1
 if x != 2:
-    print 'failure: backslash for line continuation ['
-    print "test_grammar.py:9:FAIL test expected 2, not",
-    print x
-    print "]"
-else: print 'success: backslash for line continuation'
+    print('failure: backslash for line continuation [')
+    print("test_grammar.py:9:FAIL test expected 2, not", end=' ')
+    print(x)
+    print("]")
+else: print('success: backslash for line continuation')
 
-print 'test: backslash ending comment'
+print('test: backslash ending comment')
 # Backslash in comments :\
 x = 0
 if x != 0:
-    print 'failure: backslash ending comment ['
-    print "test_grammar.py:16:FAIL test expected 0, not",
-    print x
-    print "]"
-else: print 'success: backslash ending comment'
+    print('failure: backslash ending comment [')
+    print("test_grammar.py:16:FAIL test expected 0, not", end=' ')
+    print(x)
+    print("]")
+else: print('success: backslash ending comment')
 
 
-print 'test: backslash ending comment after space'
+print('test: backslash ending comment after space')
 # Backslash in comments \
 x = 2
 if x != 2:
-    print 'failure: backslash ending comment after space ['
-    print "test_grammar.py:27:FAIL test expected 2, not",
-    print x
-    print "]"
-else: print 'success: backslash ending comment after space'
+    print('failure: backslash ending comment after space [')
+    print("test_grammar.py:27:FAIL test expected 2, not", end=' ')
+    print(x)
+    print("]")
+else: print('success: backslash ending comment after space')
 
 
-print 'test: hex int'
+print('test: hex int')
 if 0xff != 255:
-    print 'failure: hex int ['
-    print "test_grammar.py:36:FAIL test expected 255, not",
-    print 0xff
-    print "]"
-else: print 'success: hex int'
+    print('failure: hex int [')
+    print("test_grammar.py:36:FAIL test expected 255, not", end=' ')
+    print(0xff)
+    print("]")
+else: print('success: hex int')
 
-print 'test: octal int'
+print('test: octal int')
 if 0o377 != 255:
-    print 'failure: octal int ['
-    print "test_grammar.py:44:FAIL test expected 255, not",
-    print 0o377
-    print "]"
-else: print 'success: octal int'
+    print('failure: octal int [')
+    print("test_grammar.py:44:FAIL test expected 255, not", end=' ')
+    print(0o377)
+    print("]")
+else: print('success: octal int')

Lib/test/parrot/lists.py

 #!./parrot
 
 
-print 'test: one element list'
+print('test: one element list')
 a = ["parrot"]
-if a: print 'success: one element list'
-else: print 'failure: one element list'
+if a: print('success: one element list')
+else: print('failure: one element list')
 
-print 'test: two element list'
+print('test: two element list')
 b = ["success: two element list", ["success: subelement"]]
-print b[0]
-print 'test: subelement'
-print b[1][0]
+print(b[0])
+print('test: subelement')
+print(b[1][0])
 
-print 'test: single item in parens'
+print('test: single item in parens')
 c = ("success: single item in parens")
-print c
+print(c)
 
-print 'test: single item with comma'
+print('test: single item with comma')
 d = ("success: single item with comma",)
-print d[0]
+print(d[0])

Lib/test/parrot/literals.py

 
 # check literals
 
-print 'test: integer literals'
+print('test: integer literals')
 0
 1
 12
 
 #123l
 #1234L
-print 'success: integer literals'
+print('success: integer literals')
 
 
 
-print 'test: octal literals'
+print('test: octal literals')
 0o1
 0o2
 0o3
 0o5
 0o6
 0o7
-print 'success: octal literals'
+print('success: octal literals')
 
 
-print 'test: hex literals'
+print('test: hex literals')
 0x1
 0x2
 0x3
 0xf
 0xF
 0xdeadbeef
-print 'success: hex literals'
+print('success: hex literals')
 
-print 'test: floating point literals'
+print('test: floating point literals')
 #3.14
 #10.
 #.001
 #0e0
 #0E0
 #
-print 'success: floating point literals'
+print('success: floating point literals')
 
 
-print 'test:',
-print 4
-print 'success:',
-print 4
+print('test:', end=' ')
+print(4)
+print('success:', end=' ')
+print(4)
 
 
-print 'test: imaginary literals'
+print('test: imaginary literals')
 #3.14j
 #10.j
 #10j
 #1e100j
 #3.14e-10j
 #1J
-print 'success: imaginary literals'
+print('success: imaginary literals')

Lib/test/parrot/op-assign.py

 
 # check augmented assignment ops
 
-print 'test: plus assign'
+print('test: plus assign')
 i = 0
 i += 10
-if i == 10: print 'success: plus assign'
-else: print 'failure: plus assign'
+if i == 10: print('success: plus assign')
+else: print('failure: plus assign')
 
-print 'test: minus assign'
+print('test: minus assign')
 i = 10
 i -= 5
-if i == 5: print 'success: minus assign'
-else: print 'failure: minus assign'
+if i == 5: print('success: minus assign')
+else: print('failure: minus assign')
 
-print 'test: multiply assign'
+print('test: multiply assign')
 i = -5
 i *= 2
-if i == -10: print 'success: multiply assign'
-else: print 'failure: multiply assign'
+if i == -10: print('success: multiply assign')
+else: print('failure: multiply assign')
 
-print 'test: divide assign'
+print('test: divide assign')
 i = 10
 i /= 2
-if i == 5: print 'success: divide assign'
-else: print 'failure: divide assign'
+if i == 5: print('success: divide assign')
+else: print('failure: divide assign')
 
-print 'test: modulus assign'
+print('test: modulus assign')
 i = 10
 i %= 4
-if i == 2: print 'success: modulus assign'
-else: print 'failure: modulus assign'
+if i == 2: print('success: modulus assign')
+else: print('failure: modulus assign')
 
-print 'test: exponent assign'
+print('test: exponent assign')
 #i = 3
 #i **= 3
 #if i == 27: print 'success: exponent assign'
 #else: print 'failure exponent assign'
-print 'xfail: exponent assign ['
-print 'implement **='
-print ']'
+print('xfail: exponent assign [')
+print('implement **=')
+print(']')
 
-print 'test: right shift assign'
+print('test: right shift assign')
 i = 128
 i >>= 2
-if i == 32: print 'success: right shift assign'
-else: print 'failure: right shift assign'
+if i == 32: print('success: right shift assign')
+else: print('failure: right shift assign')
 
-print 'test: left shift assign'
+print('test: left shift assign')
 i = 1
 i <<= 10
-if i == 1024: print 'success: left shift assign'
-else: print 'failure: left shift assign'
+if i == 1024: print('success: left shift assign')
+else: print('failure: left shift assign')
 
-print 'test: bitwise AND assign'
+print('test: bitwise AND assign')
 i = 0x55
 i &= 0x1f
-if i == 0x15: print 'success: bitwise AND assign'
-else: print 'failure: bitwise AND assign'
+if i == 0x15: print('success: bitwise AND assign')
+else: print('failure: bitwise AND assign')
 
-print 'test: bitwise XOR assign'
+print('test: bitwise XOR assign')
 i = 0x55
 i ^= 0x1f
-if i == 0x4a: print 'success: bitwise XOR assign'
-else: print 'failure: bitwise XOR assign'
+if i == 0x4a: print('success: bitwise XOR assign')
+else: print('failure: bitwise XOR assign')
 
-print 'test: bitwise OR assign'
+print('test: bitwise OR assign')
 i = 0x55
 i |= 0x1f
-if i == 0x5f: print 'success: bitwise OR assign'
-else: print 'failure: bitwise OR assign'
+if i == 0x5f: print('success: bitwise OR assign')
+else: print('failure: bitwise OR assign')

Lib/test/parrot/op-bitwise.py

 
 # &
 
-print 'test: 1'
-print 'success:', (0 & 0) + 1
-print 'test: 2'
-print 'success:', (1 & 0) + 2
-print 'test: 3'
-print 'success:', (0 & 1) + 3
-print 'test: 4'
-print 'success:', (1 & 1) + 3
+print('test: 1')
+print('success:', (0 & 0) + 1)
+print('test: 2')
+print('success:', (1 & 0) + 2)
+print('test: 3')
+print('success:', (0 & 1) + 3)
+print('test: 4')
+print('success:', (1 & 1) + 3)
 
 # |
 
-print 'test: 5'
-print 'success:', (0 | 0) + 5
-print 'test: 6'
-print 'success:', (1 | 0) + 5
-print 'test: 7'
-print 'success:', (0 | 1) + 6
-print 'test: 8'
-print 'success:', (1 | 1) + 7
+print('test: 5')
+print('success:', (0 | 0) + 5)
+print('test: 6')
+print('success:', (1 | 0) + 5)
+print('test: 7')
+print('success:', (0 | 1) + 6)
+print('test: 8')
+print('success:', (1 | 1) + 7)
 
 # ^
 
-print 'test: 9'
-print 'success:', (0 ^ 0) + 9
-print 'test: 10'
-print 'success:', (1 ^ 0) + 9
-print 'test: 11'
-print 'success:', (0 ^ 1) + 10
-print 'test: 12'
-print 'success:', (1 ^ 1) + 12
+print('test: 9')
+print('success:', (0 ^ 0) + 9)
+print('test: 10')
+print('success:', (1 ^ 0) + 9)
+print('test: 11')
+print('success:', (0 ^ 1) + 10)
+print('test: 12')
+print('success:', (1 ^ 1) + 12)
 
 

Lib/test/parrot/op-boolean.py

 #!./parrot pynie.pbc
 
-print 'test: logical AND true'
+print('test: logical AND true')
 if 1 and 2 and 3:
-    print 'success: logical AND true'
+    print('success: logical AND true')
 else:
-    print 'failure: logical AND true'
+    print('failure: logical AND true')
 
-print 'test: logical AND false'
+print('test: logical AND false')
 if 0 and 1 and 2:
-    print 'failure: logical AND false'
+    print('failure: logical AND false')
 else:
-    print 'success: logical AND false'
+    print('success: logical AND false')
 
-print 'test: logical OR true'
+print('test: logical OR true')
 if 0 or 1 or 2:
-    print 'success: logical OR true'
+    print('success: logical OR true')
 else:
-    print 'failure: logical OR true'
+    print('failure: logical OR true')
 
-print 'test: logical OR false'
+print('test: logical OR false')
 if 0 or 0 or 0:
-    print 'failure: logical OR false'
+    print('failure: logical OR false')
 else:
-    print 'success: logical OR false'
+    print('success: logical OR false')
 
-print 'test: logical NOT true'
+print('test: logical NOT true')
 if not 0:
-    print 'success: logical NOT true'
+    print('success: logical NOT true')
 else:
-    print 'failure: logical NOT true'
+    print('failure: logical NOT true')
 
-print 'test: logical NOT false'
+print('test: logical NOT false')
 if not 1:
-    print 'failure: logical NOT false'
+    print('failure: logical NOT false')
 else:
-    print 'success: logical NOT false'
+    print('success: logical NOT false')
 
-print 'test: logical OR/AND precedence'
+print('test: logical OR/AND precedence')
 if 1 or 0 and 0:   # and should be tighter than or
-    print 'success: logical OR/AND precedence'
+    print('success: logical OR/AND precedence')
 else:
-    print 'failure: logical OR/AND precedence'
+    print('failure: logical OR/AND precedence')
 
-print 'test: logical ops parentheses'
+print('test: logical ops parentheses')
 if (1 or 0) and 0:   # test parentheses
-    print 'failure: logical ops parentheses'
+    print('failure: logical ops parentheses')
 else:
-    print 'success: logical ops parentheses'
+    print('success: logical ops parentheses')
 
-print 'test: double NOT'
+print('test: double NOT')
 #if not not 1:
 #   print 'success: double NOT'
 #else:
 #   print 'failure: double NOT'
-print 'xfail: double NOT ['
-print 'fix double nots'
-print ']'
+print('xfail: double NOT [')
+print('fix double nots')
+print(']')

Lib/test/parrot/op-cmp.py

 #!./parrot pynie.pbc
 
-print 'test: 0 less than 1'
-if 0 < 1: print 'success: 0 less than 1'
+print('test: 0 less than 1')
+if 0 < 1: print('success: 0 less than 1')
 
-print 'test: 1 greater than 0'
-if 1 > 0: print 'success: 1 greater than 0'
+print('test: 1 greater than 0')
+if 1 > 0: print('success: 1 greater than 0')
 
-print 'test: 0 less than/equal 1'
-if 0 <= 1: print 'success: 0 less than/equal 1'
+print('test: 0 less than/equal 1')
+if 0 <= 1: print('success: 0 less than/equal 1')
 
-print 'test: 0 less than/equal itself'
-if 0 <= 0: print 'success: 0 less than/equal itself'
+print('test: 0 less than/equal itself')
+if 0 <= 0: print('success: 0 less than/equal itself')
 
-print 'test: 1 greater than/equal 0'
-if 1 >= 0: print 'success: 1 greater than/equal 0'
+print('test: 1 greater than/equal 0')
+if 1 >= 0: print('success: 1 greater than/equal 0')
 
-print 'test: 0 greater than/equal itself'
-if 0 >= 0: print 'success: 0 greater than/equal itself'
+print('test: 0 greater than/equal itself')
+if 0 >= 0: print('success: 0 greater than/equal itself')
 
-print 'test: 0 less than 1, less than 2'
-if 0 < 1 < 2: print 'success: 0 less than 1, less than 2'
+print('test: 0 less than 1, less than 2')
+if 0 < 1 < 2: print('success: 0 less than 1, less than 2')
 
-print 'test: 2 greater than 1, greater than 0'
-if 2 > 1 > 0: print 'success: 2 greater than 1, greater than 0'
+print('test: 2 greater than 1, greater than 0')
+if 2 > 1 > 0: print('success: 2 greater than 1, greater than 0')

Lib/test/parrot/op-logic-compare.py

 
 # &
 
-print 'test: boolean logic 0 AND 0'
+print('test: boolean logic 0 AND 0')
 x = 0 & 0
-if x == 0: print 'success: boolean logic 0 AND 0'
+if x == 0: print('success: boolean logic 0 AND 0')
 else:
-    print 'failure: boolean logic 0 AND 0 ['
-    print '03-op-logic.py:6:FAIL test expected 0, not',
-    print x
-    print ']'
+    print('failure: boolean logic 0 AND 0 [')
+    print('03-op-logic.py:6:FAIL test expected 0, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: boolean logic 0 AND 1'
+print('test: boolean logic 0 AND 1')
 x = 0 & 1
-if x == 0: print 'success: boolean logic 0 AND 1'
+if x == 0: print('success: boolean logic 0 AND 1')
 else:
-    print 'failure: boolean logic 0 AND 1 ['
-    print '03-op-logic.py:15:FAIL test expected 0, not',
-    print x
-    print ']'
+    print('failure: boolean logic 0 AND 1 [')
+    print('03-op-logic.py:15:FAIL test expected 0, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: boolean logic 1 AND 0'
+print('test: boolean logic 1 AND 0')
 x = 1 & 0
-if x == 0: print 'success: boolean logic 1 AND 0'
+if x == 0: print('success: boolean logic 1 AND 0')
 else:
-    print 'failure: boolean logic 1 AND 0 ['
-    print '03-op-logic.py:24:FAIL test expected 0, not',
-    print x
-    print ']'
+    print('failure: boolean logic 1 AND 0 [')
+    print('03-op-logic.py:24:FAIL test expected 0, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: boolean logic 1 AND 1'
+print('test: boolean logic 1 AND 1')
 x = 1 & 1
-if x == 1: print 'success: boolean logic 1 AND 1'
+if x == 1: print('success: boolean logic 1 AND 1')
 else:
-    print 'failure: boolean logic 1 AND 1 ['
-    print '03-op-logic.py:33:FAIL test expected 1, not',
-    print x
-    print ']'
+    print('failure: boolean logic 1 AND 1 [')
+    print('03-op-logic.py:33:FAIL test expected 1, not', end=' ')
+    print(x)
+    print(']')
 
 # |
 
-print 'test: boolean logic 0 OR 0'
+print('test: boolean logic 0 OR 0')
 x = 0 | 0
-if x == 0: print 'success: boolean logic 0 OR 0'
+if x == 0: print('success: boolean logic 0 OR 0')
 else:
-    print 'failure: boolean logic 0 OR 0 ['
-    print '03-op-logic.py:6:FAIL test expected 0, not',
-    print x
-    print ']'
+    print('failure: boolean logic 0 OR 0 [')
+    print('03-op-logic.py:6:FAIL test expected 0, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: boolean logic 0 OR 1'
+print('test: boolean logic 0 OR 1')
 x = 0 | 1
-if x == 1: print 'success: boolean logic 0 OR 1'
+if x == 1: print('success: boolean logic 0 OR 1')
 else:
-    print 'failure: boolean logic 0 OR 1 ['
-    print '03-op-logic.py:15:FAIL test expected 1, not',
-    print x
-    print ']'
+    print('failure: boolean logic 0 OR 1 [')
+    print('03-op-logic.py:15:FAIL test expected 1, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: boolean logic 1 OR 0'
+print('test: boolean logic 1 OR 0')
 x = 1 | 0
-if x == 1: print 'success: boolean logic 1 OR 0'
+if x == 1: print('success: boolean logic 1 OR 0')
 else:
-    print 'failure: boolean logic 1 OR 0 ['
-    print '03-op-logic.py:24:FAIL test expected 1, not',
-    print x
-    print ']'
+    print('failure: boolean logic 1 OR 0 [')
+    print('03-op-logic.py:24:FAIL test expected 1, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: boolean logic 1 OR 1'
+print('test: boolean logic 1 OR 1')
 x = 1 | 1
-if x == 1: print 'success: boolean logic 1 OR 1'
+if x == 1: print('success: boolean logic 1 OR 1')
 else:
-    print 'failure: boolean logic 1 OR 1 ['
-    print '03-op-logic.py:33:FAIL test expected 1, not',
-    print x
-    print ']'
+    print('failure: boolean logic 1 OR 1 [')
+    print('03-op-logic.py:33:FAIL test expected 1, not', end=' ')
+    print(x)
+    print(']')

Lib/test/parrot/op-math-compare.py

 
 # unary operators
 
-print 'test: prefix +'
+print('test: prefix +')
 x = +7
-if x == 7: print 'success: prefix +'
+if x == 7: print('success: prefix +')
 else:
-    print 'failure: prefix + ['
-    print "op-math-compare.py:92:FAIL test expected 7, not",
-    print x
-    print "]"
+    print('failure: prefix + [')
+    print("op-math-compare.py:92:FAIL test expected 7, not", end=' ')
+    print(x)
+    print("]")
 
-print 'test: prefix -'
+print('test: prefix -')
 x = -8
-if x == -8: print 'success: prefix -'
+if x == -8: print('success: prefix -')
 else:
-    print 'failure: prefix - ['
-    print "op-math-compare.py:92:FAIL test expected -8, not",
-    print x
-    print "]"
+    print('failure: prefix - [')
+    print("op-math-compare.py:92:FAIL test expected -8, not", end=' ')
+    print(x)
+    print("]")
 
 # basic math operators
 
-print 'test: addition'
+print('test: addition')
 x = 1 + 1
-if x == 2: print 'success: addition'
+if x == 2: print('success: addition')
 else:
-    print 'failure: addition ['
-    print '02-op-math.py:7:FAIL test expected 2, not',
-    print x
-    print ']'
+    print('failure: addition [')
+    print('02-op-math.py:7:FAIL test expected 2, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: addition with zero'
+print('test: addition with zero')
 x = 0 + 1
-if x == 1: print 'success: addition with zero'
+if x == 1: print('success: addition with zero')
 else:
-    print 'failure: addition with zero ['
-    print '02-op-math.py:16:FAIL test expected 1, not',
-    print x
-    print ']'
+    print('failure: addition with zero [')
+    print('02-op-math.py:16:FAIL test expected 1, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: subtraction'
+print('test: subtraction')
 x = 4 - 1
-if x == 3: print 'success: subtraction'
+if x == 3: print('success: subtraction')
 else:
-    print 'failure: subtraction ['
-    print '02-op-math.py:24:FAIL test expected 3, not',
-    print x
-    print ']'
+    print('failure: subtraction [')
+    print('02-op-math.py:24:FAIL test expected 3, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: multiplication'
+print('test: multiplication')
 x = 2 * 2
-if x == 4: print 'success: multiplication'
+if x == 4: print('success: multiplication')
 else:
-    print 'failure: multiplication ['
-    print '02-op-math.py:33:FAIL test expected 4, not',
-    print x
-    print ']'
+    print('failure: multiplication [')
+    print('02-op-math.py:33:FAIL test expected 4, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: division'
+print('test: division')
 x = 10 / 5
-if x == 2: print 'success: division'
+if x == 2: print('success: division')
 else:
-    print 'failure: division ['
-    print '02-op-math.py:42:FAIL test expected 2, not',
-    print x
-    print ']'
+    print('failure: division [')
+    print('02-op-math.py:42:FAIL test expected 2, not', end=' ')
+    print(x)
+    print(']')
 
 # //, << and >>  operators
 
-print 'test: floor division'
+print('test: floor division')
 x = 10 // 2
-if x == 5: print 'success: floor division'
+if x == 5: print('success: floor division')
 else:
-    print 'failure: floor division ['
-    print '02-op-math.py:53:FAIL test expected 5, not',
-    print x
-    print ']'
+    print('failure: floor division [')
+    print('02-op-math.py:53:FAIL test expected 5, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: floor division and addition'
+print('test: floor division and addition')
 x = 0 // 1 + 8
-if x == 8: print 'success: floor division and addition'
+if x == 8: print('success: floor division and addition')
 else:
-    print 'failure: floor division and addition ['
-    print '02-op-math.py:62:FAIL test expected 8, not',
-    print x
-    print ']'
+    print('failure: floor division and addition [')
+    print('02-op-math.py:62:FAIL test expected 8, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: left shift'
+print('test: left shift')
 x = 3 << 1
-if x == 6: print 'success: left shift'
+if x == 6: print('success: left shift')
 else:
-    print 'failure: left shift ['
-    print '02-op-math.py:71:FAIL test expected 6, not',
-    print x
-    print ']'
+    print('failure: left shift [')
+    print('02-op-math.py:71:FAIL test expected 6, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: right shift'
+print('test: right shift')
 x = 14 >> 1
-if x == 7: print 'success: right shift'
+if x == 7: print('success: right shift')
 else:
-    print 'failure: right shift ['
-    print '02-op-math.py:80:FAIL test expected 7, not',
-    print x
-    print ']'
+    print('failure: right shift [')
+    print('02-op-math.py:80:FAIL test expected 7, not', end=' ')
+    print(x)
+    print(']')
 
 # ** operator
 
-print 'test: power'
+print('test: power')
 x = 3 ** 2
-if x == 9: print 'success: power'
+if x == 9: print('success: power')
 else:
-    print 'failure: power ['
-    print '02-op-math.py:91:FAIL test expected 9, not',
-    print x
-    print ']'
+    print('failure: power [')
+    print('02-op-math.py:91:FAIL test expected 9, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: 0 to the power of 0'
+print('test: 0 to the power of 0')
 x = 0 ** 0
-if x == 1: print 'success: 0 to the power of 0'
+if x == 1: print('success: 0 to the power of 0')
 else:
-    print 'failure: 0 to the power of 0 ['
-    print '02-op-math.py:104:FAIL test expected 1, not',
-    print x
-    print ']'
+    print('failure: 0 to the power of 0 [')
+    print('02-op-math.py:104:FAIL test expected 1, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: 0 to the power of 1'
+print('test: 0 to the power of 1')
 x = 0 ** 1
-if x == 0: print 'success: 0 to the power of 1'
+if x == 0: print('success: 0 to the power of 1')
 else:
-    print 'failure: 0 to the power of 1 ['
-    print '02-op-math.py:109:FAIL test expected 0, not',
-    print x
-    print ']'
+    print('failure: 0 to the power of 1 [')
+    print('02-op-math.py:109:FAIL test expected 0, not', end=' ')
+    print(x)
+    print(']')
 
-print 'test: 1 to the power of 0'
+print('test: 1 to the power of 0')
 x = 1 ** 0
-if x == 1: print 'success: 1 to the power of 0'
+if x == 1: print('success: 1 to the power of 0')
 else:
-    print 'failure: 1 to the power of 0 ['
-    print '02-op-math.py:118:FAIL test expected 1, not',
-    print x
-    print ']'
+    print('failure: 1 to the power of 0 [')
+    print('02-op-math.py:118:FAIL test expected 1, not', end=' ')
+    print(x)
+    print(']')
 
 # unary + and -
-print 'test: unary plus'
+print('test: unary plus')
 x = +13
-if x == 13: print 'success: unary plus'
+if x == 13: print('success: unary plus')
 else:
-    print 'failure: unary plus ['
-    print '02-op-math.py:128:FAIL test expected 13, not',
-    print x
-    print ']'
+    print('failure: unary plus [')
+    print('02-op-math.py:128:FAIL test expected 13, not', end=' ')
+    print(x)
+    print(']')
 
 # unary + and -
-print 'test: unary minus'
+print('test: unary minus')
 x = -10 + 24
-if x == 14: print 'success: unary minus'
+if x == 14: print('success: unary minus')
 else:
-    print 'failure: unary minus ['
-    print '02-op-math.py:128:FAIL test expected 14, not',
-    print x
-    print ']'
+    print('failure: unary minus [')
+    print('02-op-math.py:128:FAIL test expected 14, not', end=' ')
+    print(x)
+    print(']')

Lib/test/parrot/op-math.py

 
 # basic math operators
 
-print 'test: 1'
-print 'success:', 0 + 1
-print 'test: 2'
-print 'success:', 1 + 1
-print 'test: 3'
-print 'success:', 4 - 1
-print 'test: 4'
-print 'success:', 2 * 2
+print('test: 1')
+print('success:', 0 + 1)
+print('test: 2')
+print('success:', 1 + 1)
+print('test: 3')
+print('success:', 4 - 1)
+print('test: 4')
+print('success:', 2 * 2)
 
 # //, << and >>  operators
-print 'test: 5'
-print 'success:', 10 // 2
-print 'test: 6'
-print 'success:', 3<<1
-print 'test: 7'
-print 'success:', 14>>1
-print 'test: 8'
-print 'success:', 0 // 1 + 8
+print('test: 5')
+print('success:', 10 // 2)
+print('test: 6')
+print('success:', 3<<1)
+print('test: 7')
+print('success:', 14>>1)
+print('test: 8')
+print('success:', 0 // 1 + 8)
 
 # ** operator
-print 'test: 9'
-print 'success:', 3**2
-print 'test: 10'
-print 'success:', 0**0+9
-print 'test: 11'
-print 'success:', 0**1+11
-print 'test: 12'
-print 'success:', 1**0+11
+print('test: 9')
+print('success:', 3**2)
+print('test: 10')
+print('success:', 0**0+9)
+print('test: 11')
+print('success:', 0**1+11)
+print('test: 12')
+print('success:', 1**0+11)
 
 # unary + and -
-print 'test: 13'
-print 'success:', +13
-print 'test: 14'
-print 'success:', -10 + 24
-print 'test: -15'
-print 'success:', -15
+print('test: 13')
+print('success:', +13)
+print('test: 14')
+print('success:', -10 + 24)
+print('test: -15')
+print('success:', -15)

Lib/test/parrot/simplest.py

 #!./parrot pynie.pbc
 
-print 'test: able to print'
-print 'success: able to print'
+print('test: able to print')
+print('success: able to print')

Lib/test/parrot/variables.py

 #!./parrot pynie.pbc
 
-print 'test: 1'
+print('test: 1')
 i=1
-print 'success:', i
+print('success:', i)
 
-print 'test: 2'
+print('test: 2')
 i=i+1
-print 'success:', i
+print('success:', i)
 
-print 'test: 3'
+print('test: 3')
 s='3'
-print 'success:', s
+print('success:', s)
 
-print 'test: string 4'
+print('test: string 4')
 s='string 4'
-print 'success:', s
+print('success:', s)

src/builtins/io.pir

 
 .include 'cclass.pasm'
 
-.sub 'onload' :load :init
-    $P0 = new 'Integer'
-    $P0 = 1
-    set_global '$isbol', $P0
-    .return ()
-.end
+.sub 'print'
+    .param pmc    args    :slurpy
+    .param string end     :named('end') :optional
+    .param int    got_end :opt_flag
 
-
-.sub 'print'
-    .param pmc args            :slurpy
-
-    .local pmc isbol
-    isbol = get_global '$isbol'
     .local pmc iter
+    .local string full_string, space
+    full_string = ''
+    space = ''
     iter = new 'Iterator', args
   iter_loop:
     unless iter goto iter_end
     $S0 = shift iter
-    if isbol goto skip_space
-    print " "
-  skip_space:
-    print $S0
-    $I0 = is_cclass .CCLASS_NEWLINE, $S0, -1
-    isbol = $I0
+    full_string .= space
+    full_string .= $S0
+    space = ' '
     goto iter_loop
   iter_end:
-    .return ()
-.end
 
+    unless got_end goto add_newline
+    full_string .= end
+    goto no_newline
+  add_newline:
+    full_string .= "\n"
+  no_newline:
 
-.sub 'printnl'
-    .param pmc args            :slurpy
-    'print'(args :flat)
-    print "\n"
-    .local pmc isbol
-    isbol = get_global '$isbol'
-    isbol = 1
+    print full_string
     .return ()
 .end
 
 =back
 
-=head1 AUTHOR
-
-Patrick Michaud <pmichaud@pobox.com> is the current author and
-maintainer.  Patches and suggestions can be sent to
-<parrot-dev@lists.parrot.org> or <perl-compiler@perl.org> .
-
 =cut
 
 # Local Variables:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.