[pypy-svn] r30086 - in pypy/dist/pypy: rpython translator/cli translator/cli/test

antocuni at codespeak.net antocuni at codespeak.net
Mon Jul 17 01:05:42 CEST 2006


Author: antocuni
Date: Mon Jul 17 01:05:33 2006
New Revision: 30086

Modified:
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/translator/cli/comparer.py
   pypy/dist/pypy/translator/cli/database.py
   pypy/dist/pypy/translator/cli/test/test_objectmodel.py
Log:
Added support for constant r_dict.



Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Mon Jul 17 01:05:33 2006
@@ -950,6 +950,8 @@
     def interp_func(*args):
         graph_args = self_arg + list(args)
         return llinterpreter.eval_graph(graph, args=graph_args)
+    interp_func.graph = graph
+    interp_func.self_arg = self_arg
     return graph.name, interp_func
 
 

Modified: pypy/dist/pypy/translator/cli/comparer.py
==============================================================================
--- pypy/dist/pypy/translator/cli/comparer.py	(original)
+++ pypy/dist/pypy/translator/cli/comparer.py	Mon Jul 17 01:05:33 2006
@@ -1,3 +1,5 @@
+import types
+from pypy.rpython.ootypesystem import ootype
 from pypy.translator.cli.cts import CTS
 from pypy.translator.cli.node import Node
 
@@ -41,21 +43,26 @@
                                   'final', 'virtual', 'hidebysig', 'newslot',
                                   'instance', 'default')
 
-        fn, obj, method_name = fn_args
-        if method_name.value is None:
-            self._call_function(fn, len(arglist))
+        if type(fn_args) == types.FunctionType:
+            assert len(fn_args.self_arg) <= 1
+            if len(fn_args.self_arg) == 1:
+                assert fn_args.graph.getargs()[0].concretetype is ootype.Void
+            self._call_function(fn_args.graph, len(arglist))
         else:
-            assert False, 'XXX'
+            fn, obj, method_name = fn_args
+            # fn is a HalfConcreteWrapper
+            sm = fn.value.concretize().value
+            if method_name.value is None:
+                self._call_function(sm.graph, len(arglist))
+            else:
+                assert False, 'XXX'
 
         self.ilasm.end_function()
 
-    def _call_function(self, fn, n_args):
-        # fn is a HalfConcreteWrapper
-        sm = fn.value.concretize().value
-        self.db.pending_function(sm.graph)
+    def _call_function(self, graph, n_args):
+        self.db.pending_function(graph)
         for arg in range(1, n_args+1):
             self.ilasm.opcode('ldarg', arg)
-
-        signature = self.cts.graph_to_signature(sm.graph)
+        signature = self.cts.graph_to_signature(graph)
         self.ilasm.call(signature)
         self.ilasm.opcode('ret')

Modified: pypy/dist/pypy/translator/cli/database.py
==============================================================================
--- pypy/dist/pypy/translator/cli/database.py	(original)
+++ pypy/dist/pypy/translator/cli/database.py	Mon Jul 17 01:05:33 2006
@@ -3,6 +3,7 @@
 from pypy.translator.cli.class_ import Class
 from pypy.translator.cli.record import Record
 from pypy.translator.cli.delegate import Delegate
+from pypy.translator.cli.comparer import EqualityComparer
 from pypy.translator.cli.node import Node
 from pypy.rpython.ootypesystem import ootype
 from pypy.rpython.lltypesystem import lltype
@@ -155,7 +156,7 @@
         elif isinstance(value, ootype._class):
             return ClassConst(db, value, count)
         elif isinstance(value, ootype._custom_dict):
-            assert False, 'Unknown constant: %s' % value
+            return CustomDictConst(db, value, count)
         elif isinstance(value, ootype._dict):
             return DictConst(db, value, count)
         else:
@@ -445,6 +446,28 @@
             ilasm.call_method(meth, False)
         ilasm.opcode('pop')
 
+class CustomDictConst(DictConst):
+    def dependencies(self):
+        if not self.value:
+            return
+
+        eq = self.value._dict.key_eq
+        hash = self.value._dict.key_hash
+        self.comparer = EqualityComparer(self.db, self.value._TYPE._KEYTYPE, eq, hash)
+        self.db.pending_node(self.comparer)
+        DictConst.dependencies(self)
+
+    def instantiate(self, ilasm):
+        if not self.value: # it is a null dict
+            ilasm.opcode('ldnull')
+            return
+
+        ilasm.new(self.comparer.get_ctor())
+        class_name = self.get_type()
+        ilasm.new('instance void %s::.ctor(class '
+                  '[mscorlib]System.Collections.Generic.IEqualityComparer`1<!0>)'
+                  % class_name)
+
 
 class InstanceConst(AbstractConst):
     def __init__(self, db, obj, static_type, count):

Modified: pypy/dist/pypy/translator/cli/test/test_objectmodel.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_objectmodel.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_objectmodel.py	Mon Jul 17 01:05:33 2006
@@ -7,5 +7,3 @@
 
 class TestCliObjectModel(CliTest, BaseTestObjectModel):
     test_rtype_r_dict_bm = skip_r_dict
-    test_rtype_constant_r_dicts = skip_r_dict
-    test_rtype_r_dict_singlefrozen_func_pbc = skip_r_dict



More information about the Pypy-commit mailing list