[pypy-svn] r65923 - pypy/branch/pyjitpl5/pypy/jit/tl/spli

fijal at codespeak.net fijal at codespeak.net
Wed Jun 24 18:34:59 CEST 2009


Author: fijal
Date: Wed Jun 24 18:34:58 2009
New Revision: 65923

Modified:
   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/serializer.py
Log:
RPythonize this


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	Wed Jun 24 18:34:58 2009
@@ -1,6 +1,10 @@
 from pypy.tool import stdlib_opcode as opcode
 from pypy.jit.tl.spli.pycode import Code
 from pypy.jit.tl.spli import objects
+from pypy.tool.stdlib_opcode import unrolling_opcode_descs
+from pypy.tool.stdlib_opcode import opcode_method_names
+from pypy.rlib.unroll import unrolling_iterable
+
 import dis
 
 compare_ops = [
@@ -10,12 +14,14 @@
     "cmp_ne",   # "!="
     "cmp_gt",   # ">"
     "cmp_ge",   # ">="
-    "cmp_in",
-    "cmp_not_in",
-    "cmp_is",
-    "cmp_is_not",
-    "cmp_exc_match",
+#    "cmp_in",
+#    "cmp_not_in",
+#    "cmp_is",
+#    "cmp_is_not",
+#    "cmp_exc_match",
 ]
+unrolling_compare_dispatch_table = unrolling_iterable(
+    enumerate(compare_ops))
 
 def spli_run_from_cpython_code(co, args=[]):
     space = objects.DumbObjSpace()
@@ -39,13 +45,15 @@
     def __init__(self, value):
         self.value = value
 
+class MissingOpcode(Exception):
+    pass
 
 class SPLIFrame(object):
 
     def __init__(self, code):
         self.code = code
         self.value_stack = [None] * code.co_stacksize
-        self.locals = [None] * len(code.getvarnames())
+        self.locals = [None] * code.co_nlocals
 
     def run(self):
         self.stack_depth = 0
@@ -67,8 +75,13 @@
                 instr_index += 2
             else:
                 oparg = 0
-            meth = getattr(self, opcode.opcode_method_names[op])
-            instr_index = meth(oparg, instr_index)
+            for opdesc in unrolling_opcode_descs:
+                if op == opdesc.index:
+                    meth = getattr(self, opdesc.methodname)
+                    instr_index = meth(oparg, instr_index)
+                    break
+            else:
+                raise MissingOpcode(op)
 
     def push(self, value):
         self.value_stack[self.stack_depth] = value
@@ -126,5 +139,13 @@
     def COMPARE_OP(self, arg, next_instr):
         right = self.pop()
         left = self.pop()
-        self.push(getattr(left, compare_ops[arg])(right))
+        for num, name in unrolling_compare_dispatch_table:
+            if num == arg:
+                self.push(getattr(left, name)(right))
         return next_instr
+
+items = []
+for item in unrolling_opcode_descs._items:
+    if getattr(SPLIFrame, item.methodname, None) is not None:
+        items.append(item)
+unrolling_opcode_descs = unrolling_iterable(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	Wed Jun 24 18:34:58 2009
@@ -1,9 +1,10 @@
 from pypy.interpreter.baseobjspace import ObjSpace
-
+from pypy.rlib.objectmodel import specialize
 
 class DumbObjSpace(ObjSpace):
     """Implement just enough of the ObjSpace API to satisfy PyCode."""
 
+    @specialize.argtype(1)
     def wrap(self, x):
         if isinstance(x, int):
             return Int(x)
@@ -20,6 +21,11 @@
 class InvalidOperation(Exception):
     pass
 
+class SPLIException(Exception):
+    pass
+
+class W_TypeError(SPLIException):
+    pass
 
 class SPLIObject(object):
 
@@ -29,6 +35,24 @@
     def call(self, args):
         raise InvalidOperation
 
+    def cmp_lt(self, other):
+        raise InvalidOperation
+
+    def cmp_gt(self, other):
+        raise InvalidOperation
+
+    def cmp_eq(self, other):
+        raise InvalidOperation
+
+    def cmp_ne(self, other):
+        raise InvalidOperation
+    
+    def cmp_ge(self, other):
+        raise InvalidOperation
+
+    def cmp_le(self, other):
+        raise InvalidOperation
+
 class Bool(SPLIObject):
 
     def __init__(self, value):
@@ -43,9 +67,13 @@
         self.value = value
 
     def add(self, other):
+        if not isinstance(other, Int):
+            raise W_TypeError
         return Int(self.value + other.value)
 
     def cmp_lt(self, other):
+        if not isinstance(other, Int):
+            raise W_TypeError
         return Bool(self.value < other.value)
 
 class Str(SPLIObject):
@@ -54,6 +82,8 @@
         self.value = value
 
     def add(self, other):
+        if not isinstance(other, Str):
+            raise W_TypeError
         return Str(self.value + other.value)
 
 class SPLINone(SPLIObject):

Modified: pypy/branch/pyjitpl5/pypy/jit/tl/spli/serializer.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/spli/serializer.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/spli/serializer.py	Wed Jun 24 18:34:58 2009
@@ -22,13 +22,15 @@
         raise NotSupportedFormat(str(const))
 
 def unserialize_const(c, start):
+    assert start >= 0
     if c[start] == 'd':
         end = start + int_lgt + 1
-        intval, = runpack('i', c[start + 1:end])
+        intval = runpack('i', c[start + 1:end])
         return Int(intval), end
     elif c[start] == 's':
         end_lgt = start + 1 + int_lgt
-        lgt, = runpack('i', c[start + 1:end_lgt])
+        lgt = runpack('i', c[start + 1:end_lgt])
+        assert lgt >= 0
         end_str = end_lgt + lgt
         return Str(c[end_lgt:end_str]), end_str
     elif c[start] == 'n':
@@ -57,10 +59,11 @@
         space = DumbObjSpace()
     header = coderepr[:header_lgt]
     argcount, nlocals, stacksize, flags, code_len = runpack(FMT, header)
+    assert code_len >= 0
     code = coderepr[header_lgt:(code_len + header_lgt)]
     consts = unserialize_consts(coderepr[code_len + header_lgt:])
     names = []
-    varnames = []
+    varnames = ["a", "b", "cde"] # help annotator, nobody ever reads it
     return Code(space, argcount, nlocals, stacksize, flags, code,
                 consts, names, varnames, 'file', 'code', 0,
                 0, [], [])



More information about the Pypy-commit mailing list