[pypy-svn] r18681 - in pypy/dist/pypy/rpython: . ootypesystem ootypesystem/test
bert at codespeak.net
bert at codespeak.net
Sun Oct 16 14:07:29 CEST 2005
Author: bert
Date: Sun Oct 16 14:07:29 2005
New Revision: 18681
Modified:
pypy/dist/pypy/rpython/llinterp.py
pypy/dist/pypy/rpython/ootypesystem/ootype.py
pypy/dist/pypy/rpython/ootypesystem/rclass.py
pypy/dist/pypy/rpython/ootypesystem/test/test_ooclean.py
Log:
(boria, mwh, bert, samuele, arigo)
* ootype: test and support for overridden methods
* llinterp: interpret "oosend" rather than just calling the method, implement "oodowncast"
Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py (original)
+++ pypy/dist/pypy/rpython/llinterp.py Sun Oct 16 14:07:29 2005
@@ -221,7 +221,7 @@
ophandler = self.getoperationhandler(operation.opname)
vals = [self.getval(x) for x in operation.args]
# if these special cases pile up, do something better here
- if operation.opname in ['cast_pointer', 'ooupcast']:
+ if operation.opname in ['cast_pointer', 'ooupcast', 'oodowncast']:
vals.insert(0, operation.result.concretetype)
retval = ophandler(*vals)
self.setvar(operation.result, retval)
@@ -640,11 +640,17 @@
def op_oosend(self, message, inst, *args):
assert isinstance(inst, ootype._instance)
assert isinstance(message, str)
- return getattr(inst, message)(*args)
+ bm = getattr(inst, message)
+ m = bm.meth
+ m._checkargs(args)
+ return self.op_direct_call(m, inst, *args)
def op_ooupcast(self, INST, inst):
return ootype.ooupcast(INST, inst)
+ def op_oodowncast(self, INST, inst):
+ return ootype.oodowncast(INST, inst)
+
# by default we route all logging messages to nothingness
# e.g. tests can then switch on logging to get more help
# for failing tests
Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py Sun Oct 16 14:07:29 2005
@@ -283,3 +283,7 @@
assert instanceof(instance, INSTANCE)
return instance
+def oodowncast(INSTANCE, instance):
+ assert instanceof(instance, INSTANCE)
+ return instance
+
Modified: pypy/dist/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rclass.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rclass.py Sun Oct 16 14:07:29 2005
@@ -48,20 +48,20 @@
methods = {}
baseInstance = self.lowleveltype._superclass
- for name, attrdef in attrs:
- if attrdef.readonly:
- # if the following line suffers an AttributeError,
- # maybe the attr is actually not a method.
- assert len(attrdef.s_value.prebuiltinstances) == 1, 'no support for overridden methods yet'
- # XXX following might not always succeed
- impl = self.classdef.cls.__dict__[name]
-
- f, inputs, ret = getsignature(self.rtyper, impl)
- M = ootype.Meth([r.lowleveltype for r in inputs[1:]], ret.lowleveltype)
- m = ootype.meth(M, _name=name, _callable=impl)
-
- methods[name] = m
-
+ for classdef in self.classdef.getmro():
+ attrs = classdef.attrs.items()
+ for name, attrdef in attrs:
+ if attrdef.readonly:
+ try:
+ impl = self.classdef.cls.__dict__[name]
+ except KeyError:
+ pass
+ else:
+ f, inputs, ret = getsignature(self.rtyper, impl)
+ M = ootype.Meth([r.lowleveltype for r in inputs[1:]], ret.lowleveltype)
+ m = ootype.meth(M, _name=name, _callable=impl)
+ methods[name] = m
+
ootype.addMethods(self.lowleveltype, methods)
def rtype_getattr(self, hop):
Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_ooclean.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_ooclean.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_ooclean.py Sun Oct 16 14:07:29 2005
@@ -101,3 +101,19 @@
return inst.f()
result = interpret(dummyfn, [], type_system='ootype')
assert result == 1
+
+class OverridesAMethod(HasAMethod):
+ def f(self):
+ return 2
+
+def test_override():
+ def dummyfn(flag):
+ if flag:
+ inst = HasAMethod()
+ else:
+ inst = OverridesAMethod()
+ return inst.f()
+ result = interpret(dummyfn, [True], type_system='ootype')
+ assert result == 1
+ result = interpret(dummyfn, [False], type_system='ootype')
+ assert result == 2
More information about the Pypy-commit
mailing list