[pypy-svn] r17447 - in pypy/dist/pypy/rpython: . test
pedronis at codespeak.net
pedronis at codespeak.net
Sun Sep 11 01:51:02 CEST 2005
Author: pedronis
Date: Sun Sep 11 01:51:00 2005
New Revision: 17447
Modified:
pypy/dist/pypy/rpython/rpbc.py
pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
hlinvoke support for frozen pbc methods
Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py (original)
+++ pypy/dist/pypy/rpython/rpbc.py Sun Sep 11 01:51:00 2005
@@ -287,6 +287,13 @@
self.r_im_self = rtyper.getrepr(self.s_im_self)
self.lowleveltype = self.r_im_self.lowleveltype
+ def get_s_callable(self):
+ return annmodel.SomePBC({self.function: True})
+
+ def get_r_implfunc(self):
+ r_func = self.rtyper.getrepr(self.get_s_callable())
+ return r_func, 1
+
def convert_const(self, method):
if getattr(method, 'im_func', None) is not self.function:
raise TyperError("not a method bound on %r: %r" % (self.function,
Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py (original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py Sun Sep 11 01:51:00 2005
@@ -1029,3 +1029,55 @@
c_a = A_repr.convert_const(A(None))
res = interp.eval_function(llfunction, [None, c_f, c_a])
assert typeOf(res) == A_repr.lowleveltype
+
+def test_hlinvoke_pbc_method_hltype():
+ class A(object):
+ def __init__(self, v):
+ self.v = v
+ class Impl(object):
+ def _freeze_(self):
+ return True
+
+ def f(self, a):
+ return A(a)
+
+ from pypy.translator import annrpython
+ a = annrpython.RPythonAnnotator()
+ from pypy.annotation import model as annmodel
+
+ i = Impl()
+
+ def g():
+ a = A(None)
+ i.f(a)
+
+ a.build_types(g, [])
+
+ from pypy.rpython import rtyper
+ from pypy.rpython import rclass
+ rt = rtyper.RPythonTyper(a)
+ rt.specialize()
+
+ def ll_h(R, f, a):
+ from pypy.rpython.objectmodel import hlinvoke
+ return hlinvoke(R, f, a)
+
+ from pypy.rpython import annlowlevel
+
+ s_f = a.bookkeeper.immutablevalue(i.f)
+ r_f = rt.getrepr(s_f)
+
+ s_R = a.bookkeeper.immutablevalue(r_f)
+ s_ll_f = annmodel.lltype_to_annotation(r_f.lowleveltype)
+ A_repr = rclass.getinstancerepr(rt, a.getuserclasses()[A])
+ s, llfunction = annlowlevel.annotate_lowlevel_helper(a, ll_h, [s_R, s_ll_f, annmodel.SomePtr(A_repr.lowleveltype)])
+ assert s.ll_ptrtype == A_repr.lowleveltype
+ rt.specialize_more_blocks()
+
+ from pypy.rpython.llinterp import LLInterpreter
+ interp = LLInterpreter(a.translator.flowgraphs, rt)
+
+ c_f = r_f.convert_const(i.f)
+ c_a = A_repr.convert_const(A(None))
+ res = interp.eval_function(llfunction, [None, c_f, c_a])
+ assert typeOf(res) == A_repr.lowleveltype
More information about the Pypy-commit
mailing list