Author: Tim Felgentreff <[email protected]>
Branch: 
Changeset: r538:5165739fe96b
Date: 2013-12-18 13:59 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/5165739fe96b/

Log:    allow just running literal code, as opposed to fair (using
        processes) benchmarking

diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -61,7 +61,7 @@
     except error.Exit, e:
         print e.msg
 
-def _run_code(interp, code):
+def _run_code(interp, code, as_benchmark=False):
     import time
     selector = "codeTest%d" % int(time.time())
     try:
@@ -78,7 +78,24 @@
     except error.Exit, e:
         print e.msg
         return 1
-    return _run_benchmark(interp, 0, selector, "")
+
+    if not as_benchmark:
+        try:
+            w_result = interp.perform(space.wrap_int(0), selector)
+        except interpreter.ReturnFromTopLevel, e:
+            print e.object
+            return 1
+        except error.Exit, e:
+            print e.msg
+            return 1
+        if w_result:
+            if isinstance(w_result, model.W_BytesObject):
+                print w_result.as_string().replace('\r', '\n')
+            else:
+                print w_result.as_repr_string().replace('\r', '\n')
+        return 0
+    else:
+        return _run_benchmark(interp, 0, selector, "")
 
 
 space = objspace.ObjSpace()
@@ -105,7 +122,8 @@
           -n|--number [smallint, default: 0]
           -m|--method [benchmark on smallint]
           -a|--arg [string argument to #method]
-          -r|--run [shell escaped code string]
+          -r|--run [code string]
+          -b|--benchmark [code string]
           [image path, default: Squeak.image]
     """ % argv[0]
 
@@ -123,6 +141,7 @@
     trace = False
     stringarg = ""
     code = None
+    as_benchmark = False
 
     while idx < len(argv):
         arg = argv[idx]
@@ -151,6 +170,12 @@
         elif arg in ["-r", "--run"]:
             _arg_missing(argv, idx, arg)
             code = argv[idx + 1]
+            as_benchmark = False
+            idx += 1
+        elif arg in ["-b", "--benchmark"]:
+            _arg_missing(argv, idx, arg)
+            code = argv[idx + 1]
+            as_benchmark = True
             idx += 1
         elif path is None:
             path = argv[idx]
@@ -180,7 +205,7 @@
     if benchmark is not None:
         return _run_benchmark(interp, number, benchmark, stringarg)
     elif code is not None:
-        return _run_code(interp, code)
+        return _run_code(interp, code, as_benchmark=as_benchmark)
     else:
         _run_image(interp)
         return 0
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to