[pypy-svn] r10997 - pypy/dist/pypy/translator/test

tismer at codespeak.net tismer at codespeak.net
Thu Apr 21 21:06:54 CEST 2005


Author: tismer
Date: Thu Apr 21 21:06:54 2005
New Revision: 10997

Modified:
   pypy/dist/pypy/translator/test/rpystone.py
   pypy/dist/pypy/translator/test/test_rpystone.py
Log:
small fixes.
Found the way to use sys in rpystone:
Import it into local functions and almost all is fine.
Printing is still a problem, because some interp2app
instances are badly involved.
print sys.stderr.write works fine.

Modified: pypy/dist/pypy/translator/test/rpystone.py
==============================================================================
--- pypy/dist/pypy/translator/test/rpystone.py	(original)
+++ pypy/dist/pypy/translator/test/rpystone.py	Thu Apr 21 21:06:54 2005
@@ -67,13 +67,10 @@
 
 def main(loops=LOOPS):
     benchtime, stones = pystones(abs(loops))
-    #print "Pystone(%s) time for %d passes = %g" % \
-    #      (__version__, loops, benchtime)
     if loops >= 0:
         import sys
         sys.stdout.write("Pystone(%s) time for %d passes = %g\n" % \
               (__version__, loops, benchtime) )
-        #print "This machine benchmarks at %g pystones/second" % stones
         sys.stdout.write("This machine benchmarks at %g pystones/second\n" % stones)
 
 
@@ -263,60 +260,27 @@
     if EnumLoc == Ident3: return TRUE
     return FALSE
 
-# XXX the following creates bad code
-# sys.argv is seen as a constant.
-# also, in entrypoint(), the try..except is
-# removed, which is a bug.
-# XXX repair this, write a test
-
-"""
 def error(msg):
-    #print >>sys.stderr, msg,
+    import sys
     sys.stderr.write(msg+" ")
-    #print >>sys.stderr, "usage: %s [number_of_loops]" % sys.argv[0]
     sys.stderr.write("usage: %s [number_of_loops]\n" % sys.argv[0])
     sys.exit(100)
 
-def entrypoint():
-    loops = LOOPS  # initialize early, for slow space
-    nargs = len(sys.argv) - 1
-    if nargs > 1:
-        error("%d arguments are too many;" % nargs)
-    elif nargs == 1:
-        try: loops = int(sys.argv[1])
-        except ValueError:
-            error("Invalid argument %r;" % sys.argv[1])
-    else:
-        if hasattr(sys, 'pypy_objspaceclass'):
-            loops = LOOPS / 2000 # XXX rough estimate, adjust
-        #else:
-        #    loops = LOOPS
-    main(loops)
-"""
-
-if __name__ == '__main__':
-    # the following should be replaced by
-    # entrypoint()
-    # for now, we use main in the test.
-    
-    def error(msg):
-        import sys
-        #print >>sys.stderr, msg,
-        sys.stderr.write(msg+" ")
-        #print >>sys.stderr, "usage: %s [number_of_loops]" % sys.argv[0]
-        sys.stderr.write("usage: %s [number_of_loops]\n" % sys.argv[0])
-        sys.exit(100)
-    nargs = len(sys.argv) - 1
-    if nargs > 1:
-        error("%d arguments are too many;" % nargs)
-    elif nargs == 1:
-        try: loops = int(sys.argv[1])
-        except ValueError:
-            error("Invalid argument %r;" % sys.argv[1])
-    else:
-        if hasattr(sys, 'pypy_objspaceclass'):
-            loops = LOOPS / 2000 # XXX rough estimate, adjust
+def entrypoint(loops=None):
+    import sys
+    if loops is None:
+        loops = LOOPS  # initialize early, for slow space
+        nargs = len(sys.argv) - 1
+        if nargs > 1:
+            error("%d arguments are too many;" % nargs)
+        elif nargs == 1:
+            try: loops = int(sys.argv[1])
+            except ValueError:
+                error("Invalid argument %r;" % sys.argv[1])
         else:
-            loops = LOOPS
+            if hasattr(sys, 'pypy_objspaceclass'):
+                loops = LOOPS / 2000 # XXX rough estimate, adjust
     main(loops)
 
+if __name__ == '__main__':
+    entrypoint()

Modified: pypy/dist/pypy/translator/test/test_rpystone.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_rpystone.py	(original)
+++ pypy/dist/pypy/translator/test/test_rpystone.py	Thu Apr 21 21:06:54 2005
@@ -3,16 +3,14 @@
 import os
 fname = os.path.join(os.path.dirname(__), "test", "rpystone.py")
 src = file(fname).read()
-init, ign = translate_as_module(src)
+init, ign = translate_as_module(src)#, tmpname="/tmp/look.py")
 
 LOOPS = 25
 
 def test_rpystone():
     space = Space()
     modic = init(space)
-    # entry = space.getitem(modic, space.wrap("entrypoint"))
-    # XXX wecan't use stuff like sys.argv, yet
-    entry = space.getitem(modic, space.wrap("main"))
+    entry = space.getitem(modic, space.wrap("entrypoint"))
     # warm-up,to get everything translated
     space.call(entry, space.newtuple([space.wrap(-1)]))
     # now this is the real one



More information about the Pypy-commit mailing list