[pypy-svn] r23886 - in pypy/dist/pypy/rpython: ootypesystem test
nik at codespeak.net
nik at codespeak.net
Thu Mar 2 01:55:30 CET 2006
Author: nik
Date: Thu Mar 2 01:55:26 2006
New Revision: 23886
Modified:
pypy/dist/pypy/rpython/ootypesystem/rclass.py
pypy/dist/pypy/rpython/ootypesystem/rpbc.py
pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
(pedronis, nik)
made specialized methods work for ootype with surprisingly little
hair-pulling. all method names are now mangled, so that all
specialized variants have distinct names (even if there is only
one variant).
Modified: pypy/dist/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rclass.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rclass.py Thu Mar 2 01:55:26 2006
@@ -259,9 +259,9 @@
# get method implementation
from pypy.rpython.ootypesystem.rpbc import MethodImplementations
methimpls = MethodImplementations.get(self.rtyper, s_value)
- m = methimpls.get_impl(mangled, methdesc)
-
- methods[mangled] = m
+ m_impls = methimpls.get_impl(mangled, methdesc)
+
+ methods.update(m_impls)
for classdef in self.classdef.getmro():
Modified: pypy/dist/pypy/rpython/ootypesystem/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rpbc.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rpbc.py Thu Mar 2 01:55:26 2006
@@ -73,21 +73,21 @@
rtype_call_args = rtype_simple_call
+def row_method_name(methodname, rowname):
+ return "%s_%s" % (methodname, rowname)
+
class MethodImplementations(object):
def __init__(self, rtyper, methdescs):
samplemdesc = methdescs.iterkeys().next()
concretetable, uniquerows = get_concrete_calltable(rtyper,
samplemdesc.funcdesc.getcallfamily())
- self._uniquerows = uniquerows
- if len(uniquerows) == 1:
- row = uniquerows[0]
+ self.row_mapping = {}
+ for row in uniquerows:
sample_as_static_meth = row.itervalues().next()
SM = ootype.typeOf(sample_as_static_meth)
M = ootype.Meth(SM.ARGS[1:], SM.RESULT) # cut self
- self.lowleveltype = M
- else:
- XXX_later
+ self.row_mapping[row.attrname] = row, M
def get(rtyper, s_pbc):
lst = list(s_pbc.descriptions)
@@ -102,18 +102,25 @@
get = staticmethod(get)
def get_impl(self, name, methdesc):
- M = self.lowleveltype
- if methdesc is None:
- return ootype.meth(M, _name=name, abstract=True)
- else:
- impl_graph = self._uniquerows[0][methdesc.funcdesc].graph
- return ootype.meth(M, _name=name, graph=impl_graph)
-
+ impls = {}
+ for rowname, (row, M) in self.row_mapping.iteritems():
+ if methdesc is None:
+ m = ootype.meth(M, _name=name, abstract=True)
+ else:
+ impl_graph = row[methdesc.funcdesc].graph
+ m = ootype.meth(M, _name=name, graph=impl_graph)
+ derived_name = row_method_name(name, rowname)
+ impls[derived_name] = m
+ return impls
+
class MethodsPBCRepr(AbstractMethodsPBCRepr):
def __init__(self, rtyper, s_pbc):
AbstractMethodsPBCRepr.__init__(self, rtyper, s_pbc)
+ sampledesc = s_pbc.descriptions.iterkeys().next()
+ self.concretetable, _ = get_concrete_calltable(rtyper,
+ sampledesc.funcdesc.getcallfamily())
def rtype_simple_call(self, hop):
return self.call("simple_call", hop)
@@ -138,7 +145,9 @@
rresult = callparse.getrresult(self.rtyper, anygraph)
hop.exception_is_here()
mangled = mangle(self.methodname)
- cname = hop.inputconst(ootype.Void, mangled)
+ row = self.concretetable[shape, index]
+ derived_mangled = row_method_name(mangled, row.attrname)
+ cname = hop.inputconst(ootype.Void, derived_mangled)
v = hop.genop("oosend", [cname]+vlist, resulttype=rresult)
return hop.llops.convertvar(v, rresult, hop.r_result)
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 Thu Mar 2 01:55:26 2006
@@ -1018,7 +1018,7 @@
res = interpret(f, [0], type_system=self.ts)
assert ''.join(res.chars) == 'tag2:hellotag2:< 42 >'
- def DONT_test_specialized_method(self):
+ def test_specialized_method(self):
class A:
def __init__(self, tag):
self.tag = tag
More information about the Pypy-commit
mailing list