[pypy-svn] r14569 - in pypy/dist/pypy: annotation interpreter translator

arigo at codespeak.net arigo at codespeak.net
Tue Jul 12 21:51:14 CEST 2005


Author: arigo
Date: Tue Jul 12 21:51:08 2005
New Revision: 14569

Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/annotation/builtin.py
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/interpreter/typedef.py
   pypy/dist/pypy/translator/ann_override.py
Log:
Forgot these changes in the previous check-in.


Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Tue Jul 12 21:51:08 2005
@@ -471,10 +471,14 @@
 class __extend__(pairtype(SomeInstance, SomeInstance)):
 
     def union((ins1, ins2)):
-        basedef = ins1.classdef.commonbase(ins2.classdef)
-        if basedef is None:
-            # print warning?
-            return SomeObject()
+        if ins1.classdef is None or ins2.classdef is None:
+            # special case only
+            basedef = None
+        else:
+            basedef = ins1.classdef.commonbase(ins2.classdef)
+            if basedef is None:
+                # print warning?
+                return SomeObject()
         return SomeInstance(basedef, can_be_None=ins1.can_be_None or ins2.can_be_None)
 
 class __extend__(pairtype(SomeIterator, SomeIterator)):

Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py	(original)
+++ pypy/dist/pypy/annotation/builtin.py	Tue Jul 12 21:51:08 2005
@@ -9,11 +9,13 @@
 from pypy.annotation.model import SomeList, SomeString, SomeTuple, SomeSlice
 from pypy.annotation.model import SomeUnicodeCodePoint
 from pypy.annotation.model import SomeFloat, unionof
+from pypy.annotation.model import SomePBC, SomeInstance
 from pypy.annotation.model import annotation_to_lltype
 from pypy.annotation.model import add_knowntypedata
 from pypy.annotation.bookkeeper import getbookkeeper
 from pypy.objspace.flow.model import Constant
 import pypy.rpython.rarithmetic
+import pypy.rpython.objectmodel
 
 # convenience only!
 def immutablevalue(x):
@@ -226,6 +228,17 @@
 def rarith_intmask(s_obj):
     return SomeInteger()
 
+def robjmodel_instantiate(s_clspbc):
+    assert isinstance(s_clspbc, SomePBC)
+    clsdef = None
+    for cls, v in s_clspbc.prebuiltinstances.items():
+        if not clsdef:
+            clsdef = getbookkeeper().getclassdef(cls)
+        else:
+            clsdef = clsdef.commonbase(getbookkeeper().getclassdef(cls))
+    return SomeInstance(clsdef)
+
+
 ##def rarith_ovfcheck(s_obj):
 ##    if isinstance(s_obj, SomeInteger) and s_obj.unsigned:
 ##        getbookkeeper().warning("ovfcheck on unsigned")
@@ -263,6 +276,7 @@
 ##BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.ovfcheck] = rarith_ovfcheck
 ##BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.ovfcheck_lshift] = rarith_ovfcheck_lshift
 BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.intmask] = rarith_intmask
+BUILTIN_ANALYZERS[pypy.rpython.objectmodel.instantiate] = robjmodel_instantiate
 
 BUILTIN_ANALYZERS[Exception.__init__.im_func] = exception_init
 BUILTIN_ANALYZERS[OSError.__init__.im_func] = exception_init

Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Tue Jul 12 21:51:08 2005
@@ -280,12 +280,16 @@
     "Stands for an instance of a (user-defined) class."
     def __init__(self, classdef, can_be_None=False):
         self.classdef = classdef
-        self.knowntype = classdef.cls
+        if classdef is not None:   # XXX should never really be None
+            self.knowntype = classdef.cls
         self.can_be_None = can_be_None
     def fmt_knowntype(self, kt):
         return None
     def fmt_classdef(self, cd):
-        return cd.cls.__name__
+        if cd is None:
+            return 'object'
+        else:
+            return cd.cls.__name__
 
     def can_be_none(self):
         return self.can_be_None

Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Tue Jul 12 21:51:08 2005
@@ -7,7 +7,7 @@
 from pypy.interpreter.error import OperationError
 from pypy.tool.cache import Cache
 from pypy.tool.sourcetools import compile2
-import new
+from pypy.rpython.objectmodel import instantiate
 
 class TypeDef:
     def __init__(self, __name, __base=None, **rawdict):
@@ -132,14 +132,6 @@
 
     return subcls
 
-def instantiate(cls):
-    "Create an empty instance of 'cls'."
-    if isinstance(cls, type):
-        return object.__new__(cls)
-    else:
-        return new.instance(cls)
-instantiate._annspecialcase_ = "override:instantiate"
-
 def make_descr_typecheck_wrapper(func, extraargs=(), cls=None):
     if func is None:
         return None

Modified: pypy/dist/pypy/translator/ann_override.py
==============================================================================
--- pypy/dist/pypy/translator/ann_override.py	(original)
+++ pypy/dist/pypy/translator/ann_override.py	Tue Jul 12 21:51:08 2005
@@ -8,16 +8,6 @@
 
 class PyPyAnnotatorPolicy(AnnotatorPolicy):
 
-    def override__instantiate(pol, clspbc):
-        assert isinstance(clspbc, annmodel.SomePBC)
-        clsdef = None
-        for cls, v in clspbc.prebuiltinstances.items():
-            if not clsdef:
-                clsdef = getbookkeeper().getclassdef(cls)
-            else:
-                clsdef = clsdef.commonbase(getbookkeeper().getclassdef(cls))
-        return annmodel.SomeInstance(clsdef)
-
     def override__wrap_exception_cls(pol, space, x):
         import pypy.objspace.std.typeobject as typeobject
         clsdef = getbookkeeper().getclassdef(typeobject.W_TypeObject)



More information about the Pypy-commit mailing list