[pypy-svn] r55645 - in pypy/dist/pypy/rpython: lltypesystem test

arigo at codespeak.net arigo at codespeak.net
Sat Jun 7 11:43:27 CEST 2008


Author: arigo
Date: Sat Jun  7 11:43:25 2008
New Revision: 55645

Modified:
   pypy/dist/pypy/rpython/lltypesystem/rpbc.py
   pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
issue374 resolved

Implement the last missing case for conversion between PBCs
of functions involving SmallFunctionSetPBCRepr.


Modified: pypy/dist/pypy/rpython/lltypesystem/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rpbc.py	Sat Jun  7 11:43:25 2008
@@ -16,6 +16,8 @@
      SingleFrozenPBCRepr, none_frozen_pbc_repr, get_concrete_calltable
 from pypy.rpython.lltypesystem import rclass, llmemory
 from pypy.tool.sourcetools import has_varargs
+from pypy.rlib.unroll import unrolling_iterable
+from pypy.rlib.debug import ll_assert
 
 from pypy.rpython import callparse
 
@@ -132,6 +134,7 @@
         self.lowleveltype = Char
         self.pointer_repr = FunctionsPBCRepr(rtyper, s_pbc)
         self._conversion_tables = {}
+        self._compression_function = None
         self._dispatch_cache = {}
 
     def _setup_repr(self):
@@ -269,11 +272,31 @@
             return llops.genop('getarrayitem', [r_set.c_pointer_table, v_int],
                                resulttype=r_ptr.lowleveltype)
 
+def compression_function(r_set):
+    if r_set._compression_function is None:
+        table = []
+        for i, p in enumerate(r_set.c_pointer_table.value):
+            table.append((chr(i), p))
+        last_c, last_p = table[-1]
+        unroll_table = unrolling_iterable(table[:-1])
+        def ll_compress(fnptr):
+            for c, p in unroll_table:
+                if fnptr == p:
+                    return c
+            else:
+                ll_assert(fnptr == last_p, "unexpected function pointer")
+                return last_c
+        r_set._compression_function = ll_compress
+    return r_set._compression_function
+
 class __extend__(pairtype(FunctionsPBCRepr, SmallFunctionSetPBCRepr)):
     def convert_from_to((r_ptr, r_set), v, llops):
-        assert r_ptr.lowleveltype is Void
-        desc, = r_ptr.s_pbc.descriptions
-        return inputconst(Char, r_set.convert_desc(desc))
+        if r_ptr.lowleveltype is Void:
+            desc, = r_ptr.s_pbc.descriptions
+            return inputconst(Char, r_set.convert_desc(desc))
+        else:
+            ll_compress = compression_function(r_set)
+            return llops.gendirectcall(ll_compress, v)
 
 def conversion_table(r_from, r_to):
     if r_to in r_from._conversion_tables:

Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py	Sat Jun  7 11:43:25 2008
@@ -1927,10 +1927,6 @@
         kwds['config'] = self.config
         return TestLLtype.interpret(self, fn, args, **kwds)
 
-    def test_shrink_pbc_set(self):
-        # fails with config.translation.withsmallfuncsets == 3
-        py.test.skip("XXX not implemented")
-
 def test_smallfuncsets_basic():
     from pypy.translator.translator import TranslationContext, graphof
     from pypy.config.pypyoption import get_pypy_config



More information about the Pypy-commit mailing list