Author: Armin Rigo <[email protected]>
Branch: share-cpyext-cpython-api
Changeset: r84061:d69ecfcd442d
Date: 2016-04-30 17:11 +0100
http://bitbucket.org/pypy/pypy/changeset/d69ecfcd442d/
Log: hg merge default
diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py
--- a/rpython/rtyper/rpbc.py
+++ b/rpython/rtyper/rpbc.py
@@ -544,6 +544,21 @@
ll_compress = compression_function(r_set)
return llops.gendirectcall(ll_compress, v)
+class __extend__(pairtype(FunctionReprBase, FunctionReprBase)):
+ def rtype_is_((robj1, robj2), hop):
+ if hop.s_result.is_constant():
+ return inputconst(Bool, hop.s_result.const)
+ s_pbc = annmodel.unionof(robj1.s_pbc, robj2.s_pbc)
+ r_pbc = hop.rtyper.getrepr(s_pbc)
+ v1, v2 = hop.inputargs(r_pbc, r_pbc)
+ assert v1.concretetype == v2.concretetype
+ if v1.concretetype == Char:
+ return hop.genop('char_eq', [v1, v2], resulttype=Bool)
+ elif isinstance(v1.concretetype, Ptr):
+ return hop.genop('ptr_eq', [v1, v2], resulttype=Bool)
+ else:
+ raise TyperError("unknown type %r" % (v1.concretetype,))
+
def conversion_table(r_from, r_to):
if r_to in r_from._conversion_tables:
diff --git a/rpython/rtyper/test/test_rpbc.py b/rpython/rtyper/test/test_rpbc.py
--- a/rpython/rtyper/test/test_rpbc.py
+++ b/rpython/rtyper/test/test_rpbc.py
@@ -1497,6 +1497,47 @@
res = self.interpret(f, [2])
assert res == False
+ def test_is_among_functions_2(self):
+ def g1(): pass
+ def g2(): pass
+ def f(n):
+ if n > 5:
+ g = g2
+ else:
+ g = g1
+ g()
+ return g is g2
+ res = self.interpret(f, [2])
+ assert res == False
+ res = self.interpret(f, [8])
+ assert res == True
+
+ def test_is_among_functions_3(self):
+ def g0(): pass
+ def g1(): pass
+ def g2(): pass
+ def g3(): pass
+ def g4(): pass
+ def g5(): pass
+ def g6(): pass
+ def g7(): pass
+ glist = [g0, g1, g2, g3, g4, g5, g6, g7]
+ def f(n):
+ if n > 5:
+ g = g2
+ else:
+ g = g1
+ h = glist[n]
+ g()
+ h()
+ return g is h
+ res = self.interpret(f, [2])
+ assert res == False
+ res = self.interpret(f, [1])
+ assert res == True
+ res = self.interpret(f, [6])
+ assert res == False
+
def test_shrink_pbc_set(self):
def g1():
return 10
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit