[pypy-commit] pypy default: (ronan) remove happy nonsense that meaning was abandonded eons ago
fijal
noreply at buildbot.pypy.org
Fri Mar 22 05:49:48 CET 2013
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r62637:92a9a93262ed
Date: 2013-03-21 21:49 -0700
http://bitbucket.org/pypy/pypy/changeset/92a9a93262ed/
Log: (ronan) remove happy nonsense that meaning was abandonded eons ago
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -11,14 +11,13 @@
from rpython.annotator.model import SomeTuple, SomeImpossibleValue, s_ImpossibleValue
from rpython.annotator.model import SomeInstance, SomeBuiltin, SomeIterator
from rpython.annotator.model import SomePBC, SomeFloat, s_None, SomeByteArray
-from rpython.annotator.model import SomeExternalObject, SomeWeakRef
+from rpython.annotator.model import SomeWeakRef
from rpython.annotator.model import SomeAddress, SomeTypedAddressAccess
from rpython.annotator.model import SomeSingleFloat, SomeLongFloat, SomeType
from rpython.annotator.model import unionof, UnionError, missing_operation
from rpython.annotator.model import TLS
from rpython.annotator.model import read_can_only_throw
from rpython.annotator.model import add_knowntypedata, merge_knowntypedata
-from rpython.annotator.model import SomeGenericCallable
from rpython.annotator.bookkeeper import getbookkeeper
from rpython.flowspace.model import Variable, Constant
from rpython.rlib import rarithmetic
@@ -131,7 +130,7 @@
def is_((obj1, obj2)):
r = SomeBool()
if obj2.is_constant():
- if obj1.is_constant():
+ if obj1.is_constant():
r.const = obj1.const is obj2.const
if obj2.const is None and not obj1.can_be_none():
r.const = False
@@ -149,7 +148,7 @@
def bind(src_obj, tgt_obj, tgt_arg):
if hasattr(tgt_obj, 'is_type_of') and src_obj.is_constant():
- add_knowntypedata(knowntypedata, True, tgt_obj.is_type_of,
+ add_knowntypedata(knowntypedata, True, tgt_obj.is_type_of,
bk.valueoftype(src_obj.const))
assert annotator.binding(op.args[tgt_arg]) == tgt_obj
@@ -175,7 +174,7 @@
getbookkeeper().count("coerce", obj1, obj2)
return pair(obj1, obj2).union() # reasonable enough
- # approximation of an annotation intersection, the result should be the annotation obj or
+ # approximation of an annotation intersection, the result should be the annotation obj or
# the intersection of obj and improvement
def improve((obj, improvement)):
if not improvement.contains(obj) and obj.contains(improvement):
@@ -322,7 +321,7 @@
return int0.knowntype
if int1.nonneg and isinstance(op.args[1], Variable):
case = opname in ('lt', 'le', 'eq')
-
+
add_knowntypedata(knowntypedata, case, [op.args[1]],
SomeInteger(nonneg=True, knowntype=tointtype(int2)))
if int2.nonneg and isinstance(op.args[0], Variable):
@@ -333,7 +332,7 @@
# a special case for 'x < 0' or 'x >= 0',
# where 0 is a flow graph Constant
# (in this case we are sure that it cannot become a r_uint later)
- if (isinstance(op.args[1], Constant) and
+ if (isinstance(op.args[1], Constant) and
type(op.args[1].value) is int and # filter out Symbolics
op.args[1].value == 0):
if int1.nonneg:
@@ -354,14 +353,14 @@
class __extend__(pairtype(SomeBool, SomeBool)):
def union((boo1, boo2)):
- s = SomeBool()
- if getattr(boo1, 'const', -1) == getattr(boo2, 'const', -2):
- s.const = boo1.const
+ s = SomeBool()
+ if getattr(boo1, 'const', -1) == getattr(boo2, 'const', -2):
+ s.const = boo1.const
if hasattr(boo1, 'knowntypedata') and \
hasattr(boo2, 'knowntypedata'):
ktd = merge_knowntypedata(boo1.knowntypedata, boo2.knowntypedata)
s.set_knowntypedata(ktd)
- return s
+ return s
def and_((boo1, boo2)):
s = SomeBool()
@@ -386,13 +385,13 @@
if boo2.const:
s.const = True
return s
-
+
def xor((boo1, boo2)):
s = SomeBool()
if boo1.is_constant() and boo2.is_constant():
s.const = boo1.const ^ boo2.const
return s
-
+
class __extend__(pairtype(SomeString, SomeString)):
def union((str1, str2)):
@@ -495,7 +494,7 @@
return s_string.__class__()
class __extend__(pairtype(SomeFloat, SomeFloat)):
-
+
def union((flt1, flt2)):
return SomeFloat()
@@ -512,13 +511,13 @@
class __extend__(pairtype(SomeSingleFloat, SomeSingleFloat)):
-
+
def union((flt1, flt2)):
return SomeSingleFloat()
class __extend__(pairtype(SomeLongFloat, SomeLongFloat)):
-
+
def union((flt1, flt2)):
return SomeLongFloat()
@@ -610,7 +609,7 @@
class __extend__(pairtype(SomeTuple, SomeInteger)):
-
+
def getitem((tup1, int2)):
if int2.is_immutable_constant():
try:
@@ -624,7 +623,7 @@
class __extend__(pairtype(SomeList, SomeInteger)):
-
+
def mul((lst1, int2)):
return lst1.listdef.offspring()
@@ -643,27 +642,27 @@
getitem_idx_key = getitem_idx
def setitem((lst1, int2), s_value):
- getbookkeeper().count("list_setitem", int2)
+ getbookkeeper().count("list_setitem", int2)
lst1.listdef.mutate()
lst1.listdef.generalize(s_value)
setitem.can_only_throw = [IndexError]
def delitem((lst1, int2)):
- getbookkeeper().count("list_delitem", int2)
+ getbookkeeper().count("list_delitem", int2)
lst1.listdef.resize()
delitem.can_only_throw = [IndexError]
class __extend__(pairtype(SomeString, SomeInteger)):
def getitem((str1, int2)):
- getbookkeeper().count("str_getitem", int2)
+ getbookkeeper().count("str_getitem", int2)
return SomeChar(no_nul=str1.no_nul)
getitem.can_only_throw = []
getitem_key = getitem
def getitem_idx((str1, int2)):
- getbookkeeper().count("str_getitem", int2)
+ getbookkeeper().count("str_getitem", int2)
return SomeChar(no_nul=str1.no_nul)
getitem_idx.can_only_throw = [IndexError]
@@ -675,14 +674,14 @@
class __extend__(pairtype(SomeUnicodeString, SomeInteger)):
def getitem((str1, int2)):
- getbookkeeper().count("str_getitem", int2)
+ getbookkeeper().count("str_getitem", int2)
return SomeUnicodeCodePoint()
getitem.can_only_throw = []
getitem_key = getitem
def getitem_idx((str1, int2)):
- getbookkeeper().count("str_getitem", int2)
+ getbookkeeper().count("str_getitem", int2)
return SomeUnicodeCodePoint()
getitem_idx.can_only_throw = [IndexError]
@@ -694,7 +693,7 @@
class __extend__(pairtype(SomeInteger, SomeString),
pairtype(SomeInteger, SomeUnicodeString)):
-
+
def mul((int1, str2)): # xxx do we want to support this
getbookkeeper().count("str_mul", str2, int1)
return str2.basestringclass()
@@ -714,7 +713,7 @@
return result
class __extend__(pairtype(SomeInteger, SomeList)):
-
+
def mul((int1, lst2)):
return lst2.listdef.offspring()
@@ -787,7 +786,7 @@
class __extend__(pairtype(SomePBC, SomePBC)):
- def union((pbc1, pbc2)):
+ def union((pbc1, pbc2)):
d = pbc1.descriptions.copy()
d.update(pbc2.descriptions)
return SomePBC(d, can_be_None = pbc1.can_be_None or pbc2.can_be_None)
@@ -804,20 +803,6 @@
s.const = False # no common desc in the two sets
return s
-class __extend__(pairtype(SomeGenericCallable, SomePBC)):
- def union((gencall, pbc)):
- for desc in pbc.descriptions:
- unique_key = desc
- bk = desc.bookkeeper
- s_result = bk.emulate_pbc_call(unique_key, pbc, gencall.args_s)
- s_result = unionof(s_result, gencall.s_result)
- assert gencall.s_result.contains(s_result)
- return gencall
-
-class __extend__(pairtype(SomePBC, SomeGenericCallable)):
- def union((pbc, gencall)):
- return pair(gencall, pbc).union()
-
class __extend__(pairtype(SomeImpossibleValue, SomeObject)):
def union((imp1, obj2)):
return obj2
@@ -854,7 +839,6 @@
_make_none_union('SomeUnicodeString', 'can_be_None=True')
_make_none_union('SomeList', 'obj.listdef')
_make_none_union('SomeDict', 'obj.dictdef')
-_make_none_union('SomeExternalObject', 'obj.knowntype')
_make_none_union('SomeWeakRef', 'obj.classdef')
# getitem on SomePBCs, in particular None fails
@@ -881,12 +865,6 @@
raise AnnotatorError('add on %r' % pbc)
return s_ImpossibleValue
-class __extend__(pairtype(SomeExternalObject, SomeExternalObject)):
- def union((ext1, ext2)):
- if ext1.knowntype == ext2.knowntype:
- return SomeExternalObject(ext1.knowntype)
- return SomeObject()
-
# ____________________________________________________________
# annotation of low-level types
from rpython.annotator.model import SomePtr, SomeOOInstance, SomeOOClass
diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -426,8 +426,8 @@
elif ishashable(x) and x in BUILTIN_ANALYZERS:
_module = getattr(x,"__module__","unknown")
result = SomeBuiltin(BUILTIN_ANALYZERS[x], methodname="%s.%s" % (_module, x.__name__))
- elif extregistry.is_registered(x, self.policy):
- entry = extregistry.lookup(x, self.policy)
+ elif extregistry.is_registered(x):
+ entry = extregistry.lookup(x)
result = entry.compute_annotation_bk(self)
elif isinstance(x, lltype._ptr):
result = SomePtr(lltype.typeOf(x))
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -83,7 +83,7 @@
def fmt_knowntype(self, t):
return t.__name__
-
+
def contains(self, other):
if self == other:
return True
@@ -452,16 +452,6 @@
else:
return kt.__name__
-class SomeGenericCallable(SomeObject):
- """ Stands for external callable with known signature
- """
- def __init__(self, args, result):
- self.args_s = args
- self.s_result = result
-
- def can_be_None(self):
- return True
-
class SomeBuiltin(SomeObject):
"Stands for a built-in function or method with special-cased analysis."
knowntype = BuiltinFunctionType # == BuiltinMethodType
@@ -485,16 +475,6 @@
"""
knowntype = MethodType
-class SomeExternalObject(SomeObject):
- """Stands for an object of 'external' type. External types have a Repr
- controlled by rpython.rtyper.extregistry."""
-
- def __init__(self, knowntype):
- self.knowntype = knowntype
-
- def can_be_none(self):
- return True
-
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."""
@@ -571,7 +551,7 @@
immutable = True
def __init__(self, ll_ptrtype, func):
self.ll_ptrtype = ll_ptrtype
- self.func = func
+ self.func = func
def can_be_none(self):
return False
@@ -681,7 +661,7 @@
T = lltype.InteriorPtr(lltype.typeOf(ob), v._T, v._offsets)
return SomeInteriorPtr(T)
return lltype_to_annotation(lltype.typeOf(v))
-
+
# ____________________________________________________________
class UnionError(Exception):
@@ -732,14 +712,14 @@
def commonbase(cls1, cls2): # XXX single inheritance only XXX hum
l1 = inspect.getmro(cls1)
- l2 = inspect.getmro(cls2)
- if l1[-1] != object:
- l1 = l1 + (object,)
- if l2[-1] != object:
- l2 = l2 + (object,)
- for x in l1:
- if x in l2:
- return x
+ l2 = inspect.getmro(cls2)
+ if l1[-1] != object:
+ l1 = l1 + (object,)
+ if l2[-1] != object:
+ l2 = l2 + (object,)
+ for x in l1:
+ if x in l2:
+ return x
assert 0, "couldn't get to commonbase of %r and %r" % (cls1, cls2)
def missing_operation(cls, name):
diff --git a/rpython/annotator/signature.py b/rpython/annotator/signature.py
--- a/rpython/annotator/signature.py
+++ b/rpython/annotator/signature.py
@@ -82,8 +82,8 @@
return SomeUnicodeString()
elif t is types.NoneType:
return s_None
- elif bookkeeper and extregistry.is_registered_type(t, bookkeeper.policy):
- entry = extregistry.lookup_type(t, bookkeeper.policy)
+ elif bookkeeper and extregistry.is_registered_type(t):
+ entry = extregistry.lookup_type(t)
return entry.compute_annotation_bk(bookkeeper)
elif t is type:
return SomeType()
@@ -97,7 +97,7 @@
def __init__(self, *argtypes):
self.argtypes = argtypes
-
+
def __call__(self, funcdesc, inputcells):
from rpython.rtyper.lltypesystem import lltype
args_s = []
diff --git a/rpython/annotator/test/test_annrpython.py b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -3033,33 +3033,6 @@
s = a.build_types(fun, [])
assert s.const == 0
- def test_some_generic_function_call(self):
- def h(x):
- return int(x)
-
- def c(x):
- return int(x)
-
- def g(a, x):
- if x == -1:
- a = None
- if x < 0:
- if x == -1:
- a = h
- else:
- a = c
- x = x + .01
- return a(x)
-
- #def fun(x):
-
- a = self.RPythonAnnotator(policy=policy.AnnotatorPolicy())
- s = a.build_types(g, [annmodel.SomeGenericCallable(
- args=[annmodel.SomeFloat()], result=annmodel.SomeInteger()),
- annmodel.SomeFloat()])
- assert isinstance(s, annmodel.SomeInteger)
- assert not hasattr(s, 'const')
-
def test_compare_int_bool(self):
def fun(x):
return 50 < x
diff --git a/rpython/annotator/test/test_signature.py b/rpython/annotator/test/test_signature.py
--- a/rpython/annotator/test/test_signature.py
+++ b/rpython/annotator/test/test_signature.py
@@ -6,10 +6,3 @@
assert _annotation_key({str:(str, [str])}) == ('dict', (str, (str, ('list', str))))
for i in ([[str]], [str], (int, int, {str: [str]})):
assert hash(_annotation_key(i))
-
-def test_genericcallable():
- py.test.skip("this two annotations should be equal - fix!")
- from rpython.rtyper.extfunc import genericcallable
- s1 = annotation([genericcallable([str], int)])
- s2 = annotation([genericcallable([str], int)])
- assert s1 == s2
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -9,10 +9,10 @@
SomeObject, SomeInteger, SomeBool, SomeString, SomeChar, SomeList, \
SomeDict, SomeTuple, SomeImpossibleValue, SomeUnicodeCodePoint, \
SomeInstance, SomeBuiltin, SomeFloat, SomeIterator, SomePBC, \
- SomeExternalObject, SomeTypedAddressAccess, SomeAddress, SomeType, \
+ SomeTypedAddressAccess, SomeAddress, SomeType, \
s_ImpossibleValue, s_Bool, s_None, \
unionof, missing_operation, add_knowntypedata, HarmlesslyBlocked, \
- SomeGenericCallable, SomeWeakRef, SomeUnicodeString
+ SomeWeakRef, SomeUnicodeString
from rpython.annotator.bookkeeper import getbookkeeper
from rpython.annotator import builtin
from rpython.annotator.binaryop import _clone ## XXX where to put this?
@@ -358,7 +358,7 @@
s_value = dct.dictdef.read_value()
return (isinstance(s_key, SomeImpossibleValue) or
isinstance(s_value, SomeImpossibleValue))
-
+
def len(dct):
if dct._is_empty():
return immutablevalue(0)
@@ -751,34 +751,6 @@
else:
return SomeObject() # len() on a pbc? no chance
-class __extend__(SomeGenericCallable):
- def call(self, args):
- bookkeeper = getbookkeeper()
- for arg, expected in zip(args.unpack()[0], self.args_s):
- assert expected.contains(arg)
-
- return self.s_result
-
-class __extend__(SomeExternalObject):
- 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)
- 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)
- entry.set_field_annotation(p.knowntype, attr, s_value)
-
- def is_true(p):
- return s_Bool
-
# annotation of low-level types
from rpython.annotator.model import SomePtr, SomeLLADTMeth
from rpython.annotator.model import SomeOOInstance, SomeOOBoundMeth, SomeOOStaticMeth
@@ -845,7 +817,7 @@
return SomeOOBoundMeth(r.ootype, s_attr.const)
return ll_to_annotation(v)
- def setattr(r, s_attr, s_value):
+ def setattr(r, s_attr, s_value):
assert s_attr.is_constant(), "setattr on ref %r with non-constant field-name" % r.ootype
v = annotation_to_lltype(s_value)
example = r.ootype._example()
diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py
--- a/rpython/rtyper/extfunc.py
+++ b/rpython/rtyper/extfunc.py
@@ -125,23 +125,6 @@
def _freeze_(self):
return True
-class genericcallable(object):
- """ A way to specify the callable annotation, but deferred until
- we have bookkeeper
- """
- def __init__(self, args, result=None):
- self.args = args
- self.result = result
-
-class _ext_callable(ExtRegistryEntry):
- _type_ = genericcallable
- # we defer a bit annotation here
-
- def compute_result_annotation(self):
- return annmodel.SomeGenericCallable([annotation(i, self.bookkeeper)
- for i in self.instance.args],
- annotation(self.instance.result, self.bookkeeper))
-
class ExtFuncEntry(ExtRegistryEntry):
safe_not_sandboxed = False
@@ -249,7 +232,7 @@
llfakeimpl, oofakeimpl: optional; if provided, they are called by the llinterpreter
sandboxsafe: use True if the function performs no I/O (safe for --sandbox)
"""
-
+
if export_name is None:
export_name = function.__name__
diff --git a/rpython/rtyper/extregistry.py b/rpython/rtyper/extregistry.py
--- a/rpython/rtyper/extregistry.py
+++ b/rpython/rtyper/extregistry.py
@@ -22,17 +22,9 @@
for k in key:
selfcls._register(dict, k)
else:
- for basecls in selfcls.__mro__:
- if '_condition_' in basecls.__dict__:
- cond = basecls.__dict__['_condition_']
- break
- else:
- cond = None
- try:
- family = dict[key]
- except KeyError:
- family = dict[key] = ClassFamily()
- family.add(selfcls, cond)
+ if key in dict:
+ raise ValueError("duplicate extregistry entry %r" % (selfcls,))
+ dict[key] = selfcls
def _register_value(selfcls, key):
selfcls._register(EXT_REGISTRY_BY_VALUE, key)
@@ -43,32 +35,6 @@
def _register_metatype(selfcls, key):
selfcls._register(EXT_REGISTRY_BY_METATYPE, key)
-class ClassFamily(object):
-
- def __init__(self):
- self.default = None
- self.conditionals = []
-
- def add(self, cls, cond=None):
- if cond is None:
- assert self.default is None, (
- "duplicate extregistry entry %r" % (cls,))
- self.default = cls
- else:
- self.conditionals.append((cls, cond))
-
- def match(self, config):
- if config is not None:
- matches = [cls for cls, cond in self.conditionals
- if cond(config)]
- if matches:
- assert len(matches) == 1, (
- "multiple extregistry matches: %r" % (matches,))
- return matches[0]
- if self.default:
- return self.default
- raise KeyError("no default extregistry entry")
-
class ExtRegistryEntry(object):
__metaclass__ = AutoRegisteringType
@@ -159,36 +125,36 @@
# ____________________________________________________________
# Public interface to access the registry
-def _lookup_type_cls(tp, config):
+def _lookup_type_cls(tp):
try:
- return EXT_REGISTRY_BY_TYPE[tp].match(config)
+ return EXT_REGISTRY_BY_TYPE[tp]
except (KeyError, TypeError):
- return EXT_REGISTRY_BY_METATYPE[type(tp)].match(config)
+ return EXT_REGISTRY_BY_METATYPE[type(tp)]
-def lookup_type(tp, config=None):
- Entry = _lookup_type_cls(tp, config)
+def lookup_type(tp):
+ Entry = _lookup_type_cls(tp)
return Entry(tp)
-def is_registered_type(tp, config=None):
+def is_registered_type(tp):
try:
- _lookup_type_cls(tp, config)
+ _lookup_type_cls(tp)
except KeyError:
return False
return True
-def _lookup_cls(instance, config):
+def _lookup_cls(instance):
try:
- return EXT_REGISTRY_BY_VALUE[instance].match(config)
+ return EXT_REGISTRY_BY_VALUE[instance]
except (KeyError, TypeError):
- return _lookup_type_cls(type(instance), config)
+ return _lookup_type_cls(type(instance))
-def lookup(instance, config=None):
- Entry = _lookup_cls(instance, config)
+def lookup(instance):
+ Entry = _lookup_cls(instance)
return Entry(type(instance), instance)
-def is_registered(instance, config=None):
+def is_registered(instance):
try:
- _lookup_cls(instance, config)
+ _lookup_cls(instance)
except KeyError:
return False
return True
diff --git a/rpython/rtyper/lltypesystem/rgeneric.py b/rpython/rtyper/lltypesystem/rgeneric.py
deleted file mode 100644
--- a/rpython/rtyper/lltypesystem/rgeneric.py
+++ /dev/null
@@ -1,9 +0,0 @@
-
-from rpython.rtyper.rgeneric import AbstractGenericCallableRepr
-from rpython.rtyper.lltypesystem.lltype import Ptr, FuncType
-
-class GenericCallableRepr(AbstractGenericCallableRepr):
- def create_low_leveltype(self):
- l_args = [r_arg.lowleveltype for r_arg in self.args_r]
- l_retval = self.r_result.lowleveltype
- return Ptr(FuncType(l_args, l_retval))
diff --git a/rpython/rtyper/ootypesystem/rgeneric.py b/rpython/rtyper/ootypesystem/rgeneric.py
deleted file mode 100644
--- a/rpython/rtyper/ootypesystem/rgeneric.py
+++ /dev/null
@@ -1,9 +0,0 @@
-
-from rpython.rtyper.rgeneric import AbstractGenericCallableRepr
-from rpython.rtyper.ootypesystem import ootype
-
-class GenericCallableRepr(AbstractGenericCallableRepr):
- def create_low_leveltype(self):
- l_args = [r_arg.lowleveltype for r_arg in self.args_r]
- l_retval = self.r_result.lowleveltype
- return ootype.StaticMethod(l_args, l_retval)
diff --git a/rpython/rtyper/rexternalobj.py b/rpython/rtyper/rexternalobj.py
deleted file mode 100644
--- a/rpython/rtyper/rexternalobj.py
+++ /dev/null
@@ -1,21 +0,0 @@
-from rpython.annotator import model as annmodel
-from rpython.rtyper import extregistry
-from rpython.rtyper.lltypesystem import lltype
-
-# ExternalObjects
-
-
-class __extend__(annmodel.SomeExternalObject):
- def rtyper_makerepr(self, rtyper):
- # delegate to the get_repr() of the extregistrered Entry class
- entry = extregistry.lookup_type(self.knowntype)
- return entry.get_repr(rtyper, self)
-
- def rtyper_makekey(self):
- # grab all attributes of the SomeExternalObject for the key
- attrs = lltype.frozendict(self.__dict__)
- if 'const' in attrs:
- del attrs['const']
- if 'const_box' in attrs:
- del attrs['const_box']
- return self.__class__, attrs
diff --git a/rpython/rtyper/rgeneric.py b/rpython/rtyper/rgeneric.py
deleted file mode 100644
--- a/rpython/rtyper/rgeneric.py
+++ /dev/null
@@ -1,56 +0,0 @@
-from rpython.annotator import model as annmodel
-from rpython.rtyper.lltypesystem import lltype
-from rpython.rtyper.rmodel import Repr
-from rpython.rtyper.rpbc import AbstractFunctionsPBCRepr
-from rpython.tool.pairtype import pairtype
-
-
-class AbstractGenericCallableRepr(Repr):
- def __init__(self, rtyper, s_generic):
- self.rtyper = rtyper
- self.s_generic = s_generic
- self.args_r = [self.rtyper.getrepr(arg) for arg in s_generic.args_s]
- self.r_result = self.rtyper.getrepr(s_generic.s_result)
- self.lowleveltype = self.create_low_leveltype()
-
- def rtype_simple_call(self, hop):
- return self.call('simple_call', hop)
-
- def rtype_call_args(self, hop):
- return self.call('call_args', hop)
-
- def call(self, opname, hop):
- vlist = hop.inputargs(self, *self.args_r) + [hop.inputconst(lltype.Void, None)]
- hop.exception_is_here()
- v_result = hop.genop('indirect_call', vlist, resulttype=self.r_result)
- return v_result
-
- def convert_const(self, value):
- bookkeeper = self.rtyper.annotator.bookkeeper
- if value is None:
- return self.rtyper.type_system.null_callable(self.lowleveltype)
- 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()
-
-class __extend__(pairtype(AbstractFunctionsPBCRepr, AbstractGenericCallableRepr)):
- def convert_from_to((pbcrepr, gencallrepr), v, llops):
- if pbcrepr.lowleveltype is lltype.Void:
- r = gencallrepr.convert_const(pbcrepr.s_pbc.const)
- r.setup()
- return r
- if pbcrepr.lowleveltype == gencallrepr.lowleveltype:
- return v
- return NotImplemented
diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py
--- a/rpython/rtyper/rtyper.py
+++ b/rpython/rtyper/rtyper.py
@@ -1012,9 +1012,7 @@
from rpython.rtyper import rrange
from rpython.rtyper import rstr, rdict, rlist, rbytearray
from rpython.rtyper import rclass, rbuiltin, rpbc
-from rpython.rtyper import rexternalobj
from rpython.rtyper import rptr
-from rpython.rtyper import rgeneric
from rpython.rtyper import rweakref
from rpython.rtyper import raddress # memory addresses
from rpython.rtyper.ootypesystem import rootype
diff --git a/rpython/rtyper/test/test_extfunc.py b/rpython/rtyper/test/test_extfunc.py
--- a/rpython/rtyper/test/test_extfunc.py
+++ b/rpython/rtyper/test/test_extfunc.py
@@ -58,32 +58,6 @@
res = interpret(f, [])
assert res == 7
- def test_callback(self):
- """
- Verify annotation when a callback function is in the arguments list.
- """
- def d(y):
- return eval("y()")
-
- class DTestFuncEntry(ExtFuncEntry):
- _about_ = d
- name = 'd'
- signature_args = [annmodel.SomeGenericCallable(args=[], result=
- annmodel.SomeFloat())]
- signature_result = annmodel.SomeFloat()
-
- def callback():
- return 2.5
-
- def f():
- return d(callback)
-
- policy = AnnotatorPolicy()
- a = RPythonAnnotator(policy=policy)
- s = a.build_types(f, [])
- assert isinstance(s, annmodel.SomeFloat)
- assert a.translator._graphof(callback)
-
def test_register_external_signature(self):
"""
Test the standard interface for external functions.
@@ -198,5 +172,5 @@
return os_execve(l)
py.test.raises(Exception, a.build_types, g, [[str]])
a.build_types(g, [[str0]]) # Does not raise
-
+
diff --git a/rpython/rtyper/test/test_extregistry.py b/rpython/rtyper/test/test_extregistry.py
--- a/rpython/rtyper/test/test_extregistry.py
+++ b/rpython/rtyper/test/test_extregistry.py
@@ -9,7 +9,7 @@
from rpython.rtyper.test.test_llinterp import interpret
from rpython.rtyper.rmodel import Repr
-def dummy():
+def dummy():
raiseNameError
class Entry(ExtRegistryEntry):
@@ -20,7 +20,7 @@
def func():
x = dummy()
return x
-
+
a = RPythonAnnotator()
s = a.build_types(func, [])
assert isinstance(s, annmodel.SomeInteger)
@@ -38,20 +38,20 @@
def func():
x = dummy2()
return x
-
+
a = RPythonAnnotator()
s = a.build_types(func, [])
assert isinstance(s, annmodel.SomeInteger)
-
+
def test_register_type_with_callable():
class DummyType(object):
pass
-
+
dummy_type = DummyType()
-
+
def func():
return dummy_type
-
+
class Entry(ExtRegistryEntry):
_type_ = DummyType
def compute_annotation(self):
@@ -65,15 +65,15 @@
def test_register_metatype():
class MetaType(type):
pass
-
+
class RealClass(object):
__metaclass__ = MetaType
-
+
real_class = RealClass()
-
+
def func():
return real_class
-
+
class Entry(ExtRegistryEntry):
_metatype_ = MetaType
def compute_annotation(self):
@@ -88,13 +88,13 @@
def test_register_metatype_2():
class MetaType(type):
pass
-
+
class RealClass(object):
__metaclass__ = MetaType
-
+
def func(real_class):
return real_class
-
+
class Entry(ExtRegistryEntry):
_metatype_ = MetaType
def compute_annotation(self):
@@ -119,7 +119,7 @@
def func():
return dummy_func()
-
+
res = interpret(func, [])
assert res == 42
@@ -127,18 +127,18 @@
def test_register_type_with_get_repr():
class DummyClass(object):
pass
-
+
class SomeDummyObject(annmodel.SomeObject):
def rtyper_makerepr(self, rtyper):
entry = extregistry.lookup_type(self.knowntype)
return entry.get_repr(rtyper, self)
-
+
def rtyper_makekey( self ):
return self.__class__, self.knowntype
class DummyRepr(Repr):
lowleveltype = lltype.Signed
-
+
def convert_const(self, value):
return 42
@@ -155,14 +155,14 @@
return DummyRepr()
dummy_class = DummyClass()
-
+
def func():
return dummy_class
-
+
res = interpret(func, [])
-
+
assert res == 42
-
+
def test_register_unhashable():
lst1 = [5, 6]
lst2 = [5, 6]
@@ -178,26 +178,3 @@
_about_ = n1
assert isinstance(extregistry.lookup(n1), Entry)
assert isinstance(extregistry.lookup(n2), Entry)
-
-def test_condition():
- stuff = object()
- class Entry(ExtRegistryEntry):
- _about_ = stuff
- _condition_ = lambda n: n == 'yes'
- assert isinstance(extregistry.lookup(stuff, 'yes'), Entry)
- py.test.raises(KeyError, "extregistry.lookup(stuff, 'no')")
- py.test.raises(KeyError, "extregistry.lookup(stuff)")
-
- class Entry2(ExtRegistryEntry):
- _about_ = stuff
- assert isinstance(extregistry.lookup(stuff, 'yes'), Entry)
- assert isinstance(extregistry.lookup(stuff, 'no'), Entry2)
- assert isinstance(extregistry.lookup(stuff), Entry2)
-
- otherstuff = object()
- class Entry3(Entry):
- _about_ = otherstuff
- # _condition_ is inherited from Entry
- assert isinstance(extregistry.lookup(otherstuff, 'yes'), Entry3)
- py.test.raises(KeyError, "extregistry.lookup(otherstuff, 'no')")
- py.test.raises(KeyError, "extregistry.lookup(otherstuff)")
diff --git a/rpython/rtyper/test/test_rgeneric.py b/rpython/rtyper/test/test_rgeneric.py
deleted file mode 100644
--- a/rpython/rtyper/test/test_rgeneric.py
+++ /dev/null
@@ -1,47 +0,0 @@
-from rpython.rtyper.rtyper import RPythonTyper
-from rpython.annotator import model as annmodel
-from rpython.annotator.annrpython import RPythonAnnotator
-from rpython.annotator import policy
-from rpython.rtyper.test.test_llinterp import interpret, interpret_raises
-
-import py
-from rpython.rtyper.test.tool import LLRtypeMixin, OORtypeMixin
-
-class BaseRGenericTest:
- def test_some_generic_function_call(self):
- def h(x):
- return int(x)
-
- def c(x):
- return int(x) + 1
-
- def default(x):
- return int(x) + 3
-
- def g(a, x):
- if x == -1:
- a = None
- if x > 0:
- if x == 1:
- a = h
- else:
- a = c
- x = x + 0.01
- return a(x)
-
- def f(x):
- return g(default, x)
-
- g._annenforceargs_ = policy.Sig(annmodel.SomeGenericCallable(
- args=[annmodel.SomeFloat()], result=annmodel.SomeInteger()),
- float)
-
- assert interpret(f, [1.]) == 1
- assert interpret(f, [10.]) == 11
- assert interpret(f, [-3.]) == 0
-
-class TestLLRgeneric(BaseRGenericTest, LLRtypeMixin):
- pass
-
-class TestOORgeneric(BaseRGenericTest, OORtypeMixin):
- pass
diff --git a/rpython/rtyper/typesystem.py b/rpython/rtyper/typesystem.py
--- a/rpython/rtyper/typesystem.py
+++ b/rpython/rtyper/typesystem.py
@@ -21,7 +21,7 @@
except ImportError:
return None
if name in ('rclass', 'rpbc', 'rbuiltin', 'rtuple', 'rlist',
- 'rslice', 'rdict', 'rrange', 'rstr', 'rgeneric',
+ 'rslice', 'rdict', 'rrange', 'rstr',
'll_str', 'rbuilder', 'rvirtualizable2', 'rbytearray',
'exceptiondata'):
mod = load(name)
@@ -50,7 +50,7 @@
def getcallabletype(self, ARGS, RESTYPE):
cls = self.callable_trait[0]
return cls(ARGS, RESTYPE)
-
+
def getcallable(self, graph, getconcretetype=None):
"""Return callable given a Python function."""
if getconcretetype is None:
@@ -59,7 +59,7 @@
lloutput = getconcretetype(graph.getreturnvar())
typ, constr = self.callable_trait
-
+
FT = typ(llinputs, lloutput)
name = graph.name
if hasattr(graph, 'func') and callable(graph.func):
@@ -138,7 +138,7 @@
if robj1.lowleveltype != robj2.lowleveltype:
raise TyperError('is of instances of different pointer types: %r, %r' % (
roriginal1, roriginal2))
-
+
v_list = hop.inputargs(robj1, robj2)
return hop.genop('ptr_eq', v_list, resulttype=lltype.Bool)
@@ -177,7 +177,7 @@
robj2.lowleveltype is not ootype.Class):
raise TyperError('is of instances of the non-instances: %r, %r' % (
roriginal1, roriginal2))
-
+
v_list = hop.inputargs(robj1, robj2)
return hop.genop('oois', v_list, resulttype=lltype.Bool)
More information about the pypy-commit
mailing list