thewisenerd / python-on-a-chip

Automatically exported from code.google.com/p/python-on-a-chip
Other
0 stars 0 forks source link

Fix vm so ipm prints strings and None properly #105

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The way ipm does prints does not match with CPython.  Right now, PRINT_EXPR 
which prints an interactive expression, just falls through to PRINT_ITEM.  
These 2 bytecodes could be handled separately so strings and None print like 
they do in CPython's interactive

Original issue reported on code.google.com by dwhall...@gmail.com on 28 Jul 2010 at 7:08

GoogleCodeExporter commented 9 years ago
Background:

>>> dis.disco(compile("s='test'; s", "<main>", "single"))
  1           0 LOAD_CONST               0 ('test')
              3 STORE_NAME               0 (s)
              6 LOAD_NAME                0 (s)
              9 PRINT_EXPR          
             10 LOAD_CONST               1 (None)
             13 RETURN_VALUE        

>>> dis.disco(compile("s='test'; print s", "<main>", "single"))
  1           0 LOAD_CONST               0 ('test')
              3 STORE_NAME               0 (s)
              6 LOAD_NAME                0 (s)
              9 PRINT_ITEM          
             10 PRINT_NEWLINE       
             11 LOAD_CONST               1 (None)
             14 RETURN_VALUE        

>>> n = None
>>> n
>>> print n
None

>>> n = "test"
>>> n
'test'
>>> print n
test

Original comment by dwhall...@gmail.com on 28 Jul 2010 at 8:12

GoogleCodeExporter commented 9 years ago
There are 6 distinct cases among None and string objects.  Here is a table of 
what gets printed in these conditions.  expr = from an interactive expression 
where just the object is given.  print = when the print statement prints an 
object.  nest = when an object is nested inside another object (such as inside 
a Tuple, Dict or List).

======  ======  ======
        None    String
======  ======  ======
expr            'str'
print   None    str
nest    None    'str'
======  ======  ======

Original comment by dwhall...@gmail.com on 5 Aug 2010 at 4:16

GoogleCodeExporter commented 9 years ago
r563
- Fixed argument in call to obj_print in PRINT_ITEM and PRINT_EXPR bytecode in 
interp.c
- Renamed "marshall" argument to "is_escaped" in string print functions for 
clarity.
- Escaped the single quote character in string.c for correctness.
- Added is_nested argument to obj_print to indicate when objects to print are 
nested inside another object.
- Removed single quotes when printing object instances.

There is no way to make a system test to check the output of the print command.
Tested manually on ipm and compared to CPython.
Test suite passes, too.
Mainlined directly.

Original comment by dwhall...@gmail.com on 5 Aug 2010 at 4:23