[pypy-svn] r63079 - in pypy/branch/spy-graphic/pypy: lang/smalltalk translator/goal

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Mar 19 16:02:12 CET 2009


Author: cfbolz
Date: Thu Mar 19 16:02:12 2009
New Revision: 63079

Modified:
   pypy/branch/spy-graphic/pypy/lang/smalltalk/interpreter.py
   pypy/branch/spy-graphic/pypy/translator/goal/targetimageloadingsmalltalk.py
Log:
shuffle stuff around a bit


Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/interpreter.py	(original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/interpreter.py	Thu Mar 19 16:02:12 2009
@@ -38,8 +38,7 @@
 
     def interpret(self):
         try:
-            while True:
-                self.step()
+            self.loop()
         except ReturnFromTopLevel, e:
             return e.object
 
@@ -51,38 +50,44 @@
         return option.prim_trace
 
     def step(self):
+        """NOT_RPYTHON: only for testing"""
         s_active_context = self.s_active_context()
         next = s_active_context.getNextBytecode()
-        # we_are_translated returns false on top of CPython and true when
-        # translating the interpreter
-        if not objectmodel.we_are_translated():
-            bytecodeimpl = BYTECODE_TABLE[next]
+        bytecodeimpl = BYTECODE_TABLE[next]
 
-            if self.should_trace():
-                if self._w_last_active_context != self.w_active_context():
-                    cnt = 0
-                    p = self.w_active_context()
-                    # AK make method
-                    while not p.is_same_object(self.space.w_nil):
-                        cnt += 1
-                                                  # Do not update the context
-                                                  # for this action.
-                        p = p.as_context_get_shadow(self.space).w_sender()
-                    self._last_indent = "  " * cnt
-                    self._w_last_active_context = self.w_active_context()
-
-                print "%sStack=%s" % (
-                    self._last_indent,
-                    repr(s_active_context.stack()),)
-                print "%sBytecode at %d (%d:%s):" % (
-                    self._last_indent,
-                    s_active_context.pc(),
-                    next, bytecodeimpl.__name__,)
+        if self.should_trace():
+            if self._w_last_active_context != self.w_active_context():
+                cnt = 0
+                p = self.w_active_context()
+                # AK make method
+                while not p.is_same_object(self.space.w_nil):
+                    cnt += 1
+                                              # Do not update the context
+                                              # for this action.
+                    p = p.as_context_get_shadow(self.space).w_sender()
+                self._last_indent = "  " * cnt
+                self._w_last_active_context = self.w_active_context()
+
+            print "%sStack=%s" % (
+                self._last_indent,
+                repr(s_active_context.stack()),)
+            print "%sBytecode at %d (%d:%s):" % (
+                self._last_indent,
+                s_active_context.pc(),
+                next, bytecodeimpl.__name__,)
 
-            bytecodeimpl(s_active_context, self)
+        bytecodeimpl(s_active_context, self)
 
+    def loop(self):
+        # we_are_translated returns false on top of CPython and true when
+        # translating the interpreter
+        if not objectmodel.we_are_translated():
+            while True:
+                self.step()
         else:
-            bytecode_dispatch_translated(self, s_active_context, next)
+            s_active_context = self.s_active_context()
+            next = s_active_context.getNextBytecode()
+            bytecode_loop_translated(self, s_active_context, next)
 
         
 class ReturnFromTopLevel(Exception):
@@ -550,7 +555,8 @@
     # interpreter, the bytecode dispatching is not implemented as a
     # list lookup and an indirect call but as a switch.
 
-    code = ["def bytecode_dispatch_translated(self, context, bytecode):"]
+    code = ["def bytecode_loop_translated(self, context, bytecode):"]
+    code.append("    while 1:")
     prefix = ""
     for entry in BYTECODE_RANGES:
         if len(entry) == 2:
@@ -559,14 +565,16 @@
             numbers = range(entry[0], entry[1]+1)
         cond = " or ".join(["bytecode == %s" % (i, )
                                 for i in numbers])
-        code.append("    %sif %s:" % (prefix, cond, ))
-        code.append("        context.%s(self)" % (entry[-1], ))
+        code.append("        %sif %s:" % (prefix, cond, ))
+        code.append("            context.%s(self)" % (entry[-1], ))
+        code.append("            context = self.s_active_context()")
+        code.append("            bytecode = context.getNextBytecode()")
         prefix = "el"
-    code.append("bytecode_dispatch_translated._always_inline_ = True")
+    code.append("bytecode_loop_translated._always_inline_ = True")
     source = py.code.Source("\n".join(code))
     print source
     miniglob = {}
     exec source.compile() in miniglob
-    return miniglob["bytecode_dispatch_translated"]
+    return miniglob["bytecode_loop_translated"]
     
-bytecode_dispatch_translated = make_bytecode_dispatch_translated()
+bytecode_loop_translated = make_bytecode_dispatch_translated()

Modified: pypy/branch/spy-graphic/pypy/translator/goal/targetimageloadingsmalltalk.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/translator/goal/targetimageloadingsmalltalk.py	(original)
+++ pypy/branch/spy-graphic/pypy/translator/goal/targetimageloadingsmalltalk.py	Thu Mar 19 16:02:12 2009
@@ -28,18 +28,14 @@
 def run_benchmarks(interp):
     counter = 0
     try:
-        while True:
-            counter += 1
-            interp.step()
-            if counter == 100000:
-                counter = 0
-                os.write(2, '#')
+        interp.loop()
     except interpreter.ReturnFromTopLevel, e:
         w_result = e.object
 
-    assert isinstance(w_result, model.W_BytesObject)
-    print w_result.as_string()
-    return 0
+        assert isinstance(w_result, model.W_BytesObject)
+        print w_result.as_string()
+        return 0
+    return -1
 
 from pypy.lang.smalltalk import objspace
 space = objspace.ObjSpace()



More information about the Pypy-commit mailing list