[pypy-svn] r65980 - in pypy/branch/pyjitpl5/pypy/jit/tl/spli: . test

benjamin at codespeak.net benjamin at codespeak.net
Fri Jun 26 01:05:16 CEST 2009


Author: benjamin
Date: Fri Jun 26 01:05:14 2009
New Revision: 65980

Modified:
   pypy/branch/pyjitpl5/pypy/jit/tl/spli/examples.py
   pypy/branch/pyjitpl5/pypy/jit/tl/spli/execution.py
   pypy/branch/pyjitpl5/pypy/jit/tl/spli/interpreter.py
   pypy/branch/pyjitpl5/pypy/jit/tl/spli/objects.py
   pypy/branch/pyjitpl5/pypy/jit/tl/spli/targetspli.py
   pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_interpreter.py
Log:
support basic print

Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/examples.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/examples.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/examples.py	Fri Jun 26 01:05:14 2009
@@ -2,6 +2,8 @@
 def f():
     return 1
 
+print f()
+
 def adder(a, b):
     return a + b
 

Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/execution.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/execution.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/execution.py	Fri Jun 26 01:05:14 2009
@@ -1,12 +1,9 @@
-import dis
-
 from pypy.jit.tl.spli import interpreter, objects, pycode
 
 
 def run_from_cpython_code(co, args=[], locs=None, globs=None):
     space = objects.DumbObjSpace()
     pyco = pycode.Code._from_code(space, co)
-    print dis.dis(co)
     return run(pyco, [space.wrap(arg) for arg in args], locs, globs)
 
 def run(pyco, args, locs=None, globs=None):

Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/interpreter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/interpreter.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/interpreter.py	Fri Jun 26 01:05:14 2009
@@ -1,3 +1,4 @@
+import os
 from pypy.tool import stdlib_opcode as opcode
 from pypy.jit.tl.spli import objects
 from pypy.tool.stdlib_opcode import unrolling_opcode_descs
@@ -192,6 +193,15 @@
         self.push(func.call(args))
         return next_instr
 
+    def PRINT_ITEM(self, _, next_instr, code):
+        value = self.pop().repr().as_str()
+        os.write(1, value)
+        return next_instr
+
+    def PRINT_NEWLINE(self, _, next_instr, code):
+        os.write(1, '\n')
+        return next_instr
+
 
 items = []
 for item in unrolling_opcode_descs._items:

Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/objects.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/objects.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/objects.py	Fri Jun 26 01:05:14 2009
@@ -64,7 +64,7 @@
         raise W_TypeError
 
     def repr(self):
-        raise W_TypeError
+        return Str("<SPLI object>")
 
     def is_true(self):
         raise W_TypeError
@@ -79,7 +79,12 @@
         return self.value
 
     def repr(self):
-        return str(self.value)
+        if self.is_true():
+            name = "True"
+        else:
+            name = "False"
+        return Str(name)
+
 
 class Int(SPLIObject):
 
@@ -96,7 +101,8 @@
         return self.value
 
     def repr(self):
-        return str(self.value)
+        return Str(str(self.value))
+
 
 class Str(SPLIObject):
 
@@ -110,11 +116,13 @@
         return Str(self.value + other.as_str())
 
     def repr(self):
-        return self.value
+        return Str("'" + self.value + "'")
+
 
 class SPLINone(SPLIObject):
+
     def repr(self):
-        return 'None'
+        return Str('None')
 
 spli_None = SPLINone()
 

Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/targetspli.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/targetspli.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/targetspli.py	Fri Jun 26 01:05:14 2009
@@ -23,8 +23,7 @@
     stream = open_file_as_stream(argv[1])
     co = serializer.deserialize(stream.readall())
     w_args = [unwrap_arg(args[i]) for i in range(len(args))]
-    res = execution.run(co, w_args)
-    print res.repr()
+    execution.run(co, w_args)
     return 0
 
 def target(drver, args):

Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_interpreter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_interpreter.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/test/test_interpreter.py	Fri Jun 26 01:05:14 2009
@@ -1,4 +1,5 @@
 import py
+import os
 from pypy.jit.tl.spli import execution, objects
 
 class TestSPLIInterpreter:
@@ -68,3 +69,25 @@
         assert mod_res is objects.spli_None
         assert len(globs) == 3
         assert globs["res"].as_int() == 7
+
+    def test_print(self):
+        def f(thing):
+            print thing
+        things = (
+            ("x", "'x'"),
+            (4, "4"),
+            (True, "True"),
+            (False, "False"),
+        )
+        def mock_os_write(fd, what):
+            assert fd == 1
+            buf.append(what)
+        save = os.write
+        os.write = mock_os_write
+        try:
+            for obj, res in things:
+                buf = []
+                assert self.eval(f, [obj]) is objects.spli_None
+                assert "".join(buf) == res + '\n'
+        finally:
+            os.write = save



More information about the Pypy-commit mailing list