[pypy-commit] pypy default: Split SomeBuiltinMethod from SomeBuiltin
rlamy
noreply at buildbot.pypy.org
Tue May 20 04:46:28 CEST 2014
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch:
Changeset: r71598:d11d5d0dc890
Date: 2014-05-20 02:28 +0100
http://bitbucket.org/pypy/pypy/changeset/d11d5d0dc890/
Log: Split SomeBuiltinMethod from SomeBuiltin
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -9,7 +9,7 @@
SomeObject, SomeInteger, SomeBool, s_Bool, SomeString, SomeChar, SomeList,
SomeDict, SomeOrderedDict, SomeUnicodeCodePoint, SomeUnicodeString,
SomeTuple, SomeImpossibleValue, s_ImpossibleValue, SomeInstance,
- SomeBuiltin, SomeIterator, SomePBC, SomeFloat, s_None, SomeByteArray,
+ SomeBuiltinMethod, SomeIterator, SomePBC, SomeFloat, s_None, SomeByteArray,
SomeWeakRef, SomeSingleFloat,
SomeLongFloat, SomeType, SomeConstantType, unionof, UnionError,
read_can_only_throw, add_knowntypedata,
@@ -730,15 +730,14 @@
return SomeIterator(s_cont, *iter1.variant)
-class __extend__(pairtype(SomeBuiltin, SomeBuiltin)):
-
+class __extend__(pairtype(SomeBuiltinMethod, SomeBuiltinMethod)):
def union((bltn1, bltn2)):
if (bltn1.analyser != bltn2.analyser or
- bltn1.methodname != bltn2.methodname or
- bltn1.s_self is None or bltn2.s_self is None):
+ bltn1.methodname != bltn2.methodname):
raise UnionError(bltn1, bltn2)
s_self = unionof(bltn1.s_self, bltn2.s_self)
- return SomeBuiltin(bltn1.analyser, s_self, methodname=bltn1.methodname)
+ return SomeBuiltinMethod(bltn1.analyser, s_self,
+ methodname=bltn1.methodname)
class __extend__(pairtype(SomePBC, SomePBC)):
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -533,6 +533,20 @@
return False
+class SomeBuiltinMethod(SomeBuiltin):
+ """ Stands for a built-in method which has got special meaning
+ """
+ def __init__(self, analyser, s_self, methodname):
+ if isinstance(analyser, MethodType):
+ analyser = descriptor.InstanceMethod(
+ analyser.im_func,
+ analyser.im_self,
+ analyser.im_class)
+ self.analyser = analyser
+ self.s_self = s_self
+ self.methodname = methodname
+
+
class SomeImpossibleValue(SomeObject):
"""The empty set. Instances are placeholders for objects that
will never show up at run-time, e.g. elements of an empty list."""
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -7,8 +7,8 @@
from rpython.flowspace.operation import op
from rpython.annotator.model import (SomeObject, SomeInteger, SomeBool,
SomeString, SomeChar, SomeList, SomeDict, SomeTuple, SomeImpossibleValue,
- SomeUnicodeCodePoint, SomeInstance, SomeBuiltin, SomeFloat, SomeIterator,
- SomePBC, SomeType, s_ImpossibleValue,
+ SomeUnicodeCodePoint, SomeInstance, SomeBuiltin, SomeBuiltinMethod,
+ SomeFloat, SomeIterator, SomePBC, SomeType, s_ImpossibleValue,
s_Bool, s_None, unionof, add_knowntypedata,
HarmlesslyBlocked, SomeWeakRef, SomeUnicodeString, SomeByteArray)
from rpython.annotator.bookkeeper import getbookkeeper, immutablevalue
@@ -108,7 +108,7 @@
except AttributeError:
return None
else:
- return SomeBuiltin(analyser, self, name)
+ return SomeBuiltinMethod(analyser, self, name)
def getattr(self, s_attr):
# get a SomeBuiltin if the SomeObject has
diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -11,37 +11,32 @@
class __extend__(annmodel.SomeBuiltin):
def rtyper_makerepr(self, rtyper):
- if self.s_self is None:
- # built-in function case
- if not self.is_constant():
- raise TyperError("non-constant built-in function!")
- return BuiltinFunctionRepr(self.const)
- else:
- # built-in method case
- assert self.methodname is not None
- result = BuiltinMethodRepr(rtyper, self.s_self, self.methodname)
- return result
+ if not self.is_constant():
+ raise TyperError("non-constant built-in function!")
+ return BuiltinFunctionRepr(self.const)
+
def rtyper_makekey(self):
- if self.s_self is None:
- # built-in function case
+ const = getattr(self, 'const', None)
+ if extregistry.is_registered(const):
+ const = extregistry.lookup(const)
+ return self.__class__, const
- const = getattr(self, 'const', None)
+class __extend__(annmodel.SomeBuiltinMethod):
+ def rtyper_makerepr(self, rtyper):
+ assert self.methodname is not None
+ result = BuiltinMethodRepr(rtyper, self.s_self, self.methodname)
+ return result
- if extregistry.is_registered(const):
- const = extregistry.lookup(const)
-
- return self.__class__, const
- else:
- # built-in method case
- # NOTE: we hash by id of self.s_self here. This appears to be
- # necessary because it ends up in hop.args_s[0] in the method call,
- # and there is no telling what information the called
- # rtype_method_xxx() will read from that hop.args_s[0].
- # See test_method_join in test_rbuiltin.
- # There is no problem with self.s_self being garbage-collected and
- # its id reused, because the BuiltinMethodRepr keeps a reference
- # to it.
- return (self.__class__, self.methodname, id(self.s_self))
+ def rtyper_makekey(self):
+ # NOTE: we hash by id of self.s_self here. This appears to be
+ # necessary because it ends up in hop.args_s[0] in the method call,
+ # and there is no telling what information the called
+ # rtype_method_xxx() will read from that hop.args_s[0].
+ # See test_method_join in test_rbuiltin.
+ # There is no problem with self.s_self being garbage-collected and
+ # its id reused, because the BuiltinMethodRepr keeps a reference
+ # to it.
+ return (self.__class__, self.methodname, id(self.s_self))
def call_args_expand(hop, takes_kwds = True):
hop = hop.copy()
More information about the pypy-commit
mailing list