[pypy-svn] r32313 - in pypy/dist/pypy: annotation translator/js/test

fijal at codespeak.net fijal at codespeak.net
Thu Sep 14 16:12:58 CEST 2006


Author: fijal
Date: Thu Sep 14 16:12:56 2006
New Revision: 32313

Modified:
   pypy/dist/pypy/annotation/bookkeeper.py
   pypy/dist/pypy/translator/js/test/test_basicexternal.py
Log:
Fixed listdefs/dictdefs for annotation_from_example


Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/dist/pypy/annotation/bookkeeper.py	Thu Sep 14 16:12:56 2006
@@ -455,22 +455,32 @@
         elif tp is float:
             result = SomeFloat()
         elif tp is list:
-            result = SomeList(ListDef(self, s_ImpossibleValue))
-            for e in x:
-                result.listdef.generalize(self.annotation_from_example(e))
+            # try to get listdef
+            try:
+                listdef = self.listdefs[self.position_key]
+            except KeyError:
+                listdef = ListDef(self, s_ImpossibleValue)
+                for e in x:
+                    listdef.generalize(self.annotation_from_example(e))
+                self.listdefs[self.position_key] = listdef
+            result = SomeList(listdef)
         elif tp is dict or tp is r_dict:
-            result = SomeDict(DictDef(self, 
-                s_ImpossibleValue,
-                s_ImpossibleValue,
-                is_r_dict = tp is r_dict))
-            if tp is r_dict:
-                s_eqfn = self.immutablevalue(x.key_eq)
-                s_hashfn = self.immutablevalue(x.key_hash)
-                result.dictdef.dictkey.update_rdict_annotations(s_eqfn,
+            try:
+                dictdef = self.dictdefs[self.position_key]
+            except KeyError:
+                dictdef = DictDef(self, 
+                    s_ImpossibleValue,
+                    s_ImpossibleValue,
+                    is_r_dict = tp is r_dict)
+                if tp is r_dict:
+                    s_eqfn = self.immutablevalue(x.key_eq)
+                    s_hashfn = self.immutablevalue(x.key_hash)
+                    dictdef.dictkey.update_rdict_annotations(s_eqfn,
                                                                 s_hashfn)
-            for ek, ev in x.iteritems():
-                result.dictdef.generalize_key(self.annotation_from_example(ek))
-                result.dictdef.generalize_value(self.annotation_from_example(ev))
+                for ek, ev in x.iteritems():
+                    dictdef.generalize_key(self.annotation_from_example(ek))
+                    dictdef.generalize_value(self.annotation_from_example(ev))
+            result = SomeDict(dictdef)
         elif ishashable(x) and x in BUILTIN_ANALYZERS:
             _module = getattr(x,"__module__","unknown")
             result = SomeBuiltin(BUILTIN_ANALYZERS[x], methodname="%s.%s" % (_module, x.__name__))

Modified: pypy/dist/pypy/translator/js/test/test_basicexternal.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_basicexternal.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_basicexternal.py	Thu Sep 14 16:12:56 2006
@@ -63,3 +63,22 @@
     fun = compile_function(raising_method_call, [])
     assert len(C._methods) == 1
     assert 'f' in C._methods
+
+class D(BasicExternal):
+    _fields = {
+        'a': {"aa":"aa"},
+        'b': ["aa"],
+    }
+
+d = D()
+
+def test_basicexternal_list():
+    def return_dict():
+        return d.a
+
+    def return_list():
+        return d.b
+
+    fun1 = compile_function(return_dict, [])
+    fun2 = compile_function(return_list, [])
+



More information about the Pypy-commit mailing list