Author: Armin Rigo <[email protected]>
Branch:
Changeset: r71777:5c276051bf44
Date: 2014-05-29 19:32 +0200
http://bitbucket.org/pypy/pypy/changeset/5c276051bf44/
Log: Backed out changeset 8faa5a81be74
Forgot to add rnone.py, making imports break.
diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -160,6 +160,8 @@
def consider_call_site_for_pbc(self, s_callable, args, s_result,
call_op):
descs = list(s_callable.descriptions)
+ if not descs:
+ return
family = descs[0].getcallfamily()
s_callable.getKind().consider_call_site(self, family, descs, args,
s_result, call_op)
diff --git a/rpython/rtyper/annlowlevel.py b/rpython/rtyper/annlowlevel.py
--- a/rpython/rtyper/annlowlevel.py
+++ b/rpython/rtyper/annlowlevel.py
@@ -486,7 +486,7 @@
assert False
def specialize_call(self, hop):
- from rpython.rtyper.rnone import NoneRepr
+ from rpython.rtyper import rpbc
PTR = hop.r_result.lowleveltype
if isinstance(PTR, lltype.Ptr):
T = lltype.Ptr
@@ -496,7 +496,7 @@
assert False
hop.exception_cannot_occur()
- if isinstance(hop.args_r[1], NoneRepr):
+ if isinstance(hop.args_r[1], rpbc.NoneFrozenPBCRepr):
return hop.inputconst(PTR, null)
v_arg = hop.inputarg(hop.args_r[1], arg=1)
assert isinstance(v_arg.concretetype, T)
diff --git a/rpython/rtyper/lltypesystem/rpbc.py
b/rpython/rtyper/lltypesystem/rpbc.py
--- a/rpython/rtyper/lltypesystem/rpbc.py
+++ b/rpython/rtyper/lltypesystem/rpbc.py
@@ -7,15 +7,39 @@
from rpython.rtyper.lltypesystem import rclass, llmemory
from rpython.rtyper.lltypesystem.lltype import (typeOf, Void, ForwardReference,
Struct, Bool, Char, Ptr, malloc, nullptr, Array, Signed)
-from rpython.rtyper.rmodel import Repr, inputconst
+from rpython.rtyper.rmodel import Repr, TyperError, inputconst
from rpython.rtyper.rpbc import (AbstractClassesPBCRepr,
AbstractMethodsPBCRepr,
OverriddenFunctionPBCRepr, AbstractMultipleFrozenPBCRepr,
AbstractFunctionsPBCRepr, AbstractMultipleUnrelatedFrozenPBCRepr,
- SingleFrozenPBCRepr, get_concrete_calltable)
+ SingleFrozenPBCRepr, MethodOfFrozenPBCRepr, none_frozen_pbc_repr,
+ get_concrete_calltable)
from rpython.rtyper.typesystem import getfunctionptr
from rpython.tool.pairtype import pairtype
+def rtype_is_None(robj1, rnone2, hop, pos=0):
+ if isinstance(robj1.lowleveltype, Ptr):
+ v1 = hop.inputarg(robj1, pos)
+ return hop.genop('ptr_iszero', [v1], resulttype=Bool)
+ elif robj1.lowleveltype == llmemory.Address:
+ v1 = hop.inputarg(robj1, pos)
+ cnull = hop.inputconst(llmemory.Address, robj1.null_instance())
+ return hop.genop('adr_eq', [v1, cnull], resulttype=Bool)
+ elif robj1 == none_frozen_pbc_repr:
+ return hop.inputconst(Bool, True)
+ elif isinstance(robj1, SmallFunctionSetPBCRepr):
+ if robj1.s_pbc.can_be_None:
+ v1 = hop.inputarg(robj1, pos)
+ return hop.genop('char_eq', [v1, inputconst(Char, '\000')],
+ resulttype=Bool)
+ else:
+ return inputconst(Bool, False)
+ else:
+ raise TyperError('rtype_is_None of %r' % (robj1))
+
+
+# ____________________________________________________________
+
class MultipleFrozenPBCRepr(AbstractMultipleFrozenPBCRepr):
"""Representation selected for multiple non-callable pre-built
constants."""
def __init__(self, rtyper, access_set):
diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py
--- a/rpython/rtyper/rpbc.py
+++ b/rpython/rtyper/rpbc.py
@@ -4,8 +4,9 @@
from rpython.flowspace.model import Constant
from rpython.annotator.argument import simple_args
from rpython.rtyper import rclass, callparse
+from rpython.rtyper.annlowlevel import llstr
from rpython.rtyper.error import TyperError
-from rpython.rtyper.lltypesystem.lltype import typeOf, Void
+from rpython.rtyper.lltypesystem.lltype import typeOf, Void, Bool
from rpython.rtyper.rmodel import (Repr, inputconst, CanBeNull, mangle,
inputdesc, warning, impossible_repr)
from rpython.tool.pairtype import pair, pairtype
@@ -22,7 +23,8 @@
class __extend__(annmodel.SomePBC):
def rtyper_makerepr(self, rtyper):
from rpython.rtyper.lltypesystem.rpbc import (FunctionsPBCRepr,
- SmallFunctionSetPBCRepr, ClassesPBCRepr, MethodsPBCRepr)
+ SmallFunctionSetPBCRepr, ClassesPBCRepr, MethodsPBCRepr,
+ MethodOfFrozenPBCRepr)
kind = self.getKind()
if issubclass(kind, description.FunctionDesc):
sample = self.any_description()
@@ -59,6 +61,13 @@
t = ()
return tuple([self.__class__, self.can_be_None]+lst)+t
+class __extend__(annmodel.SomeNone):
+ def rtyper_makerepr(self, rtyper):
+ return none_frozen_pbc_repr
+
+ def rtyper_makekey(self):
+ return self.__class__,
+
# ____________________________________________________________
class ConcreteCallTableRow(dict):
@@ -580,6 +589,56 @@
def convert_from_to((r_from, r_to), v, llops):
return pair(r_from.r_im_self, r_to.r_im_self).convert_from_to(v, llops)
+# __ None ____________________________________________________
+class NoneFrozenPBCRepr(Repr):
+ lowleveltype = Void
+
+ def rtype_bool(self, hop):
+ return Constant(False, Bool)
+
+ def none_call(self, hop):
+ raise TyperError("attempt to call constant None")
+
+ def ll_str(self, none):
+ return llstr("None")
+
+ def get_ll_eq_function(self):
+ return None
+
+ def get_ll_hash_function(self):
+ return ll_none_hash
+
+ rtype_simple_call = none_call
+ rtype_call_args = none_call
+
+none_frozen_pbc_repr = NoneFrozenPBCRepr()
+
+def ll_none_hash(_):
+ return 0
+
+
+class __extend__(pairtype(Repr, NoneFrozenPBCRepr)):
+
+ def convert_from_to((r_from, _), v, llops):
+ return inputconst(Void, None)
+
+ def rtype_is_((robj1, rnone2), hop):
+ from rpython.rtyper.lltypesystem.rpbc import rtype_is_None
+ if hop.s_result.is_constant():
+ return hop.inputconst(Bool, hop.s_result.const)
+ return rtype_is_None(robj1, rnone2, hop)
+
+class __extend__(pairtype(NoneFrozenPBCRepr, Repr)):
+
+ def convert_from_to((_, r_to), v, llops):
+ return inputconst(r_to, None)
+
+ def rtype_is_((rnone1, robj2), hop):
+ from rpython.rtyper.lltypesystem.rpbc import rtype_is_None
+ if hop.s_result.is_constant():
+ return hop.inputconst(Bool, hop.s_result.const)
+ return rtype_is_None(robj2, rnone1, hop, pos=1)
+
# ____________________________________________________________
class AbstractClassesPBCRepr(Repr):
diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py
--- a/rpython/rtyper/rtyper.py
+++ b/rpython/rtyper/rtyper.py
@@ -936,7 +936,7 @@
# _______________________________________________________________________
# this has the side-effect of registering the unary and binary operations
# and the rtyper_chooserepr() methods
-from rpython.rtyper import rint, rbool, rfloat, rnone
+from rpython.rtyper import rint, rbool, rfloat
from rpython.rtyper import rrange
from rpython.rtyper import rstr, rdict, rlist, rbytearray
from rpython.rtyper import rclass, rbuiltin, rpbc
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit