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

fijal at codespeak.net fijal at codespeak.net
Tue Jun 13 22:59:34 CEST 2006


Author: fijal
Date: Tue Jun 13 22:59:32 2006
New Revision: 28760

Modified:
   pypy/dist/pypy/rpython/ootypesystem/bltregistry.py
   pypy/dist/pypy/rpython/rexternalobj.py
Log:
Many different fixes and hacks. Mostly cleanup.


Modified: pypy/dist/pypy/rpython/ootypesystem/bltregistry.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/bltregistry.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/bltregistry.py	Tue Jun 13 22:59:32 2006
@@ -19,6 +19,7 @@
 
 class BasicExternal(object):
     __metaclass__ = BasicMetaExternal
+    __self__ = None
     
     _fields = {}
     _methods = {}
@@ -38,11 +39,10 @@
             return None
         return getbookkeeper().valueoftype(self.retval)
 
-class ExternalType(ootype.Instance):
+class ExternalType(ootype.OOType):
     class_dict = {}
     __name__ = "ExternalType"
-    _TYPE = BasicMetaExternal
-    
+
     def __init__(self, _class):
         # FIXME: We want to support inheritance at some point
         self._class_ = _class
@@ -61,6 +61,11 @@
         for i, val in _fields.iteritems():
             self._fields[i] = getbookkeeper().valueoftype(val)
     
+    def _is_compatible(type2):
+        return type(type2) is ExternalType
+    
+    _is_compatible = staticmethod(_is_compatible)
+    
     def update_methods(self, _methods):
         _signs = {}
         for i, val in _methods.iteritems():
@@ -104,8 +109,20 @@
     
     def __repr__(self):
         return "%s %s" % (self.__name__, self._name)
-    
+        
+##    def _defl(self):
+##        raise AttributeError()
+##        return self._null
+##
+##    def _example(self):
+##        raise AttributeError()return new(self)
+##    
     get = staticmethod(get)
+    
+class _external_type(object):
+    
+    def __init__(self, et):
+        self._TYPE = et
 
 class Entry_basicexternalmeta(ExtRegistryEntry):
     _metatype_ = BasicMetaExternal

Modified: pypy/dist/pypy/rpython/rexternalobj.py
==============================================================================
--- pypy/dist/pypy/rpython/rexternalobj.py	(original)
+++ pypy/dist/pypy/rpython/rexternalobj.py	Tue Jun 13 22:59:32 2006
@@ -34,47 +34,65 @@
         self.lowleveltype = knowntype
     
     def convert_const(self, value):
-        from pypy.rpython.ootypesystem.bltregistry import ExternalType
+        from pypy.rpython.ootypesystem.bltregistry import ExternalType,_external_type
         if value is None:
             return lltype.Void
-        return ExternalType.get(value)
+        return _external_type(self.knowntype)
     
     def rtype_getattr(self, hop):
-        s_attr = hop.args_s[1]
-        if s_attr.is_constant() and isinstance(s_attr.const, str):
-            field = self.knowntype.get_field(s_attr.const)
-            if isinstance(field, annmodel.SomeBuiltin):
-                # we need to type it as static method
-                return hop.args_v[0]
-                #return hop.genop('oogetfield', hop.args_v, concretetype=self.lowleveltype)
-            ll_type = field.rtyper_makerepr(hop.rtyper).lowleveltype
-            return hop.genop('oogetfield', hop.args_v, ll_type)
-        else:
-            raise TyperError("getattr() with a non-constant attribute name")
-    
+##        s_attr = hop.args_s[1]
+##        if s_attr.is_constant() and isinstance(s_attr.const, str):
+##            field = self.knowntype.get_field(s_attr.const)
+##            if isinstance(field, annmodel.SomeBuiltin):
+##                # we need to type it as static method
+##                return hop.args_v[0]
+##                #return hop.genop('oogetfield', hop.args_v, concretetype=self.lowleveltype)
+##            ll_type = field.rtyper_makerepr(hop.rtyper).lowleveltype
+##            return hop.genop('oogetfield', hop.args_v, ll_type)
+##        else:
+##            raise TyperError("getattr() with a non-constant attribute name")
+        attr = hop.args_s[1].const
+        s_inst = hop.args_s[0]
+        if self.knowntype._methods.has_key(attr):
+            # just return instance - will be handled by simple_call
+            return hop.inputarg(hop.args_r[0], arg=0)
+        vlist = hop.inputargs(self, ootype.Void)
+        return hop.genop("oogetfield", vlist,
+                         resulttype = hop.r_result.lowleveltype)
+
     def rtype_setattr(self, hop):
+        if self.lowleveltype is ootype.Void:
+            return
+        attr = hop.args_s[1].const
+        #self.lowleveltype._check_field(attr)
+        vlist = hop.inputargs(self, ootype.Void, hop.args_r[2])
         s_attr = hop.args_s[1]
-        if s_attr.is_constant() and isinstance(s_attr.const, str):
-            field = self.knowntype.get_field(s_attr.const)
-            if isinstance(hop.args_v[2], Constant):
-                hop.args_v[2] = hop.inputconst(field.rtyper_makerepr(hop.rtyper), hop.args_v[2].value)
-            return hop.genop('oosetfield', hop.args_v, ootype.Void)
-        else:
-            raise TyperError("setattr() with a non-constant attribute name")
+        return hop.genop('oosetfield', vlist)
+##        if s_attr.is_constant() and isinstance(s_attr.const, str):
+##            #field = self.knowntype.get_field(s_attr.const)
+##            #if isinstance(hop.args_v[2], Constant):
+##            #    hop.args_v[2] = hop.inputconst(field.rtyper_makerepr(hop.rtyper), hop.args_v[2].value)
+##            return hop.genop('oosetfield', hop.args_v, ootype.Void)
+##        else:
+##            raise TyperError("setattr() with a non-constant attribute name")
     
     def call_method(self, name, hop):
-        args, retval = self.knowntype._methods[name]
-        ll_args = [i.rtyper_makerepr(hop.rtyper) for i in args]
-        if retval is None:
-            ll_retval = ootype.Void
-        else:
-            ll_retval = retval.rtyper_makerepr(hop.rtyper)
-        ar = hop.args_v[:]
-        for i in xrange(1, len(ar)):
-            if isinstance(ar[i], Constant):
-                ar[i] = hop.inputconst(ll_args[i-1], ar[i].value)
-                ar[i].concretetype = ll_args[i-1].lowleveltype
-        return hop.genop('oosend', [Constant(name)] + ar, resulttype=hop.r_result)
+        #args, retval = self.knowntype._methods[name]
+        #ll_args = [i.rtyper_makerepr(hop.rtyper) for i in args]
+        #if retval is None:
+        #    ll_retval = ootype.Void
+        #else:
+        #    ll_retval = retval.rtyper_makerepr(hop.rtyper)
+        #ar = hop.args_v[:]
+        #for i in xrange(1, len(ar)):
+        #    if isinstance(ar[i], Constant):
+        #        ar[i] = hop.inputconst(ll_args[i-1], ar[i].value)
+        #        ar[i].concretetype = ll_args[i-1].lowleveltype
+##        args = hop.inputargs(*hop.args_v)
+##        import pdb; pdb.set_trace()
+        #attr = hop.args_s[1].const
+        vlist = hop.inputargs(self, *(hop.args_r[1:]))
+        return hop.genop('oosend', [Constant(name)] + vlist, resulttype=hop.r_result)
     
     def __getattr__(self, attr):
         if attr.startswith("rtype_method_"):



More information about the Pypy-commit mailing list