[pypy-svn] r48210 - pypy/dist/pypy/lang/smalltalk

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Oct 30 19:28:35 CET 2007


Author: cfbolz
Date: Tue Oct 30 19:28:34 2007
New Revision: 48210

Modified:
   pypy/dist/pypy/lang/smalltalk/interpreter.py
   pypy/dist/pypy/lang/smalltalk/primitives.py
Log:
turn the primitives into one big switch as well


Modified: pypy/dist/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/interpreter.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/interpreter.py	Tue Oct 30 19:28:34 2007
@@ -167,19 +167,28 @@
         method = receiverclassshadow.lookup(selector)
         # XXX catch MethodNotFound here and send doesNotUnderstand:
         if method.primitive:
+            # the primitive pushes the result (if any) onto the stack itself
+            code = method.primitive
             if interp.should_trace():
-                print "%sActually calling primitive %d" % (interp._last_indent,method.primitive,)
-            func = primitives.prim_table[method.primitive]
-            try:
-                # note: argcount does not include rcvr
-                w_result = func(interp, argcount)
-            except primitives.PrimitiveFailedError:
-                if interp.should_trace():
-                    print "PRIMITIVE FAILED: %d %s" % (method.primitive, selector,)
-                pass # ignore this error and fall back to the Smalltalk version
+                print "%sActually calling primitive %d" % (interp._last_indent, code,)
+            if objectmodel.we_are_translated():
+                for i, func in primitives.unrolling_prim_table:
+                    if i == code:
+                        try:
+                            func(interp, argcount)
+                            return
+                        except primitives.PrimitiveFailedError:
+                            break
             else:
-                # the primitive pushes the result (if any) onto the stack itself
-                return
+                func = primitives.prim_table[code]
+                try:
+                    # note: argcount does not include rcvr
+                    w_result = func(interp, argcount)
+                    return
+                except primitives.PrimitiveFailedError:
+                    if interp.should_trace():
+                        print "PRIMITIVE FAILED: %d %s" % (method.primitive, selector,)
+                    pass # ignore this error and fall back to the Smalltalk version
         start = len(self.stack) - argcount
         assert start >= 0  # XXX check in the Blue Book what to do in this case
         arguments = self.stack[start:]

Modified: pypy/dist/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/primitives.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/primitives.py	Tue Oct 30 19:28:34 2007
@@ -7,7 +7,7 @@
 from pypy.lang.smalltalk import constants
 from pypy.lang.smalltalk.error import PrimitiveFailedError, \
     PrimitiveNotYetWrittenError
-from pypy.rlib import rarithmetic
+from pypy.rlib import rarithmetic, unroll
 
 
 def assert_bounds(n0, minimum, maximum):
@@ -35,6 +35,7 @@
 # Squeak has primitives all the way up to 575
 # So all optional primitives will default to the bytecode implementation
 prim_table = [make_failing(i) for i in range(576)]
+prim_table_implemented_only = []
 
 # indicates that what is pushed is an index1, but it is unwrapped and
 # converted to an index0 
@@ -104,6 +105,7 @@
                     interp.w_active_context.push(w_result)
         wrapped.func_name = "wrap_prim_" + name
         prim_table[code] = wrapped
+        prim_table_implemented_only.append((code, wrapped))
         return func
     return decorator
 
@@ -737,3 +739,5 @@
     globals()["INST_VAR_AT_%d" % (i-264)] = i
     make_prim(i)
     
+
+unrolling_prim_table = unroll.unrolling_iterable(prim_table_implemented_only)



More information about the Pypy-commit mailing list