[pypy-svn] r28713 - pypy/dist/pypy/annotation

fijal at codespeak.net fijal at codespeak.net
Mon Jun 12 17:54:02 CEST 2006


Author: fijal
Date: Mon Jun 12 17:53:56 2006
New Revision: 28713

Modified:
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/annotation/unaryop.py
Log:
Annotation level of External Builtin Objects.


Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Mon Jun 12 17:53:56 2006
@@ -403,6 +403,10 @@
     def can_be_none(self):
         return False
 
+class SomeBuiltinMethod(SomeBuiltin):
+    """ Stands for a built-in method which has got special meaning
+    """
+    knowntype = MethodType
 
 class SomeExternalObject(SomeObject):
     """Stands for an object of 'external' type.  External types have a Repr
@@ -416,6 +420,13 @@
     def can_be_none(self):
         return True
 
+class SomeExternalBuiltin(SomeExternalObject):
+    """Stands for an object of 'external' type, but with custom access to
+    attributes as well as methods
+    """
+    def can_be_none(self):
+        return False
+
 class SomeCTypesObject(SomeExternalObject):
     """Stands for an object of the ctypes module."""
 

Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/dist/pypy/annotation/unaryop.py	Mon Jun 12 17:53:56 2006
@@ -584,7 +584,7 @@
 
 
 # annotation of low-level types
-from pypy.annotation.model import SomePtr, SomeLLADTMeth 
+from pypy.annotation.model import SomePtr, SomeLLADTMeth, SomeExternalBuiltin
 from pypy.annotation.model import SomeOOInstance, SomeOOBoundMeth, SomeOOStaticMeth
 from pypy.annotation.model import ll_to_annotation, lltype_to_annotation, annotation_to_lltype
 
@@ -615,6 +615,29 @@
     def is_true(p):
         return SomeBool()
 
+class __extend__(SomeExternalBuiltin):
+    def getattr(p, s_attr):
+        if s_attr.is_constant() and isinstance(s_attr.const, str):
+            attr = s_attr.const
+            entry = extregistry.lookup_type(p.knowntype._class_)
+            s_value = entry.get_field_annotation(p.knowntype, attr)
+            return s_value
+        else:
+            return SomeObject()
+    getattr.can_only_throw = []
+    
+    def setattr(p, s_attr, s_value):
+        assert s_attr.is_constant()
+        attr = s_attr.const
+        entry = extregistry.lookup_type(p.knowntype._class_)
+        entry.set_field_annotation(p.knowntype, attr, s_value)
+    
+    def find_method(obj, name):
+        return obj.knowntype.get_field(name)
+    
+    def is_true(p):
+        return SomeBool()
+
 class __extend__(SomeLLADTMeth):
 
     def call(adtmeth, args):



More information about the Pypy-commit mailing list