[pypy-svn] r36724 - in pypy/dist/pypy/rpython: . ootypesystem ootypesystem/test

fijal at codespeak.net fijal at codespeak.net
Sun Jan 14 12:27:38 CET 2007


Author: fijal
Date: Sun Jan 14 12:27:37 2007
New Revision: 36724

Modified:
   pypy/dist/pypy/rpython/ootypesystem/bltregistry.py
   pypy/dist/pypy/rpython/ootypesystem/extdesc.py
   pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py
   pypy/dist/pypy/rpython/rexternalobj.py
   pypy/dist/pypy/rpython/rgeneric.py
Log:
A bit more wacking here and there. Some tests still does not pass :-(


Modified: pypy/dist/pypy/rpython/ootypesystem/bltregistry.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/bltregistry.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/bltregistry.py	Sun Jan 14 12:27:37 2007
@@ -97,7 +97,7 @@
     def __call__(self, *args):
         args = args[1:]
         assert len(self.s_args) == len(args)
-        for arg, expected in zip(args, self.s_args):
+        for num, (arg, expected) in enumerate(zip(args, self.s_args)):
             res = unionof(arg, expected)
             assert expected.contains(res)
         return self.s_retval
@@ -128,9 +128,10 @@
         self._fields = {}
         for i, val in _methods.iteritems():
             #s_retval =
+            val.check_update()
             retval = annotation(val.retval._type)
             values = [arg._type for arg in val.args]
-            s_args = [annotation(j) for j in values]
+            s_args = [j for j in values]
             _signs[i] = MethodDesc(tuple(s_args), retval)
             next = annmodel.SomeBuiltin(Analyzer(i, val, retval, s_args), s_self = annmodel.SomeExternalBuiltin(self), methodname = i)
             next.const = True

Modified: pypy/dist/pypy/rpython/ootypesystem/extdesc.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/extdesc.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/extdesc.py	Sun Jan 14 12:27:37 2007
@@ -2,6 +2,8 @@
 """ extdesc - some descriptions for external entries
 """
 
+from pypy.annotation.signature import annotation
+
 class ArgDesc(object):
     """ Description of argument, given as name + example value
     (used to deduce type)
@@ -13,6 +15,9 @@
     def __repr__(self):
         return "<ArgDesc %s: %s>" % (self.name, self._type)
 
+    def update(self):
+        return ArgDesc(self.name, annotation(self._type))
+
 class MethodDesc(object):
     """ Description of method to be external,
     args are taken from examples given as keyword arguments or as args,
@@ -23,6 +28,7 @@
         self.args = [self.convert_val(arg) for arg in args]
         self.retval = self.convert_val(retval)
         self.example = self
+        self.updated = False
     
     def convert_val(self, val):
         if isinstance(val, ArgDesc) or isinstance(val, MethodDesc):
@@ -32,6 +38,12 @@
         else:
             self.num += 1
             return ArgDesc('v%d' % (self.num-1), val)
+
+    def check_update(self):
+        if not self.updated:
+            self.args = [i.update() for i in self.args]
+            self.retval = self.retval.update()
+            self.updated = True
     
     def __repr__(self):
         return "<MethodDesc (%r)>" % (self.args,)

Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py	Sun Jan 14 12:27:37 2007
@@ -39,7 +39,9 @@
     assert s.knowntype is int
 
 class AA(BasicExternal):
-    pass
+    _fields = {
+        'b':int
+        }
 
 def test_bltn_set_attr():
     def add_attr():
@@ -63,7 +65,7 @@
 def test_bltn_method():
     def access_meth():
         a = B()
-        return a.m()
+        return a.m(3)
     
     a = RPythonAnnotator()
     s = a.build_types(access_meth, [])
@@ -137,4 +139,4 @@
     a = RPythonAnnotator()
     s = a.build_types(callback_field, [])
     assert isinstance(s, annmodel.SomeGenericCallable)
-    assert aa.translator._graphof(callback)
+    assert a.translator._graphof(callback)

Modified: pypy/dist/pypy/rpython/rexternalobj.py
==============================================================================
--- pypy/dist/pypy/rpython/rexternalobj.py	(original)
+++ pypy/dist/pypy/rpython/rexternalobj.py	Sun Jan 14 12:27:37 2007
@@ -60,12 +60,22 @@
         # have overwritten _fields. This will do no harm, but may hide some
         # errors
         r = hop.rtyper.getrepr(annotation(obj, bookkeeper))
+        r.setup()
         v = hop.inputarg(r, arg=2)
         vlist.append(v)
         return hop.genop('oosetfield', vlist)
     
     def call_method(self, name, hop):
-        vlist = hop.inputargs(self, *(hop.args_r[1:]))
+        bookkeeper = hop.rtyper.annotator.bookkeeper
+        args_r = []
+        for num, arg_desc in enumerate(self.knowntype._class_._methods[name].args):
+            s_v = arg_desc._type
+#            if isinstance(s_v, annmodel.SomeGenericCallable):
+#                import pdb;pdb.set_trace()
+            r = hop.rtyper.getrepr(s_v)
+            r.setup()
+            args_r.append(r)
+        vlist = hop.inputargs(self, *args_r)
         c_name = hop.inputconst(ootype.Void, name)
         hop.exception_is_here()
         return hop.genop('oosend', [c_name] + vlist, resulttype=hop.r_result)

Modified: pypy/dist/pypy/rpython/rgeneric.py
==============================================================================
--- pypy/dist/pypy/rpython/rgeneric.py	(original)
+++ pypy/dist/pypy/rpython/rgeneric.py	Sun Jan 14 12:27:37 2007
@@ -32,14 +32,25 @@
         r_func = self.rtyper.getrepr(bookkeeper.immutablevalue(value))
         return r_func.get_unique_llfn().value
 
+    def _setup_repr(self):
+        for r in self.args_r:
+            r.setup()
+        self.r_result.setup()
+
 class __extend__(annmodel.SomeGenericCallable):
     def rtyper_makerepr(self, rtyper):
         return rtyper.type_system.rgeneric.GenericCallableRepr(rtyper, self)
 
+    def rtyper_makekey(self):
+        return self.__class__, tuple([i.rtyper_makekey() for i in self.args_s]),\
+              self.s_result.rtyper_makekey(), tuple(self.descriptions.keys())
+
 class __extend__(pairtype(AbstractFunctionsPBCRepr, AbstractGenericCallableRepr)):
     def convert_from_to((pbcrepr, gencallrepr), v, llops):
         if pbcrepr.lowleveltype is lltype.Void:
-            return gencallrepr.convert_const(pbcrepr.s_pbc.const)
+            r = gencallrepr.convert_const(pbcrepr.s_pbc.const)
+            r.setup()
+            return r
         if pbcrepr.lowleveltype == gencallrepr.lowleveltype:
             return v
         return NotImplemented



More information about the Pypy-commit mailing list