[pypy-svn] r45014 - in pypy/dist/pypy/objspace/flow: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Jul 13 14:24:06 CEST 2007
Author: fijal
Date: Fri Jul 13 14:24:05 2007
New Revision: 45014
Modified:
pypy/dist/pypy/objspace/flow/flowcontext.py
pypy/dist/pypy/objspace/flow/test/test_objspace.py
Log:
(anto, fijal, pedronis) - Patch flow objspace to take care about
introduced opcodes.
Modified: pypy/dist/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/flowcontext.py (original)
+++ pypy/dist/pypy/objspace/flow/flowcontext.py Fri Jul 13 14:24:05 2007
@@ -19,6 +19,23 @@
self.block = block
self.currentstate = currentstate
+class PyFrame(pyframe.PyFrame):
+ def LOOKUP_METHOD(f, nameindex, *ignored):
+ space = f.space
+ w_obj = f.popvalue()
+ w_name = f.getname_w(nameindex)
+ w_value = space.getattr(w_obj, w_name)
+ f.pushvalue(w_value)
+ #f.pushvalue(None)
+
+ def CALL_METHOD(f, nargs, *ignored):
+ # 'nargs' is the argument count excluding the implicit 'self'
+ w_callable = f.peekvalue(nargs)
+ try:
+ w_result = f.space.call_valuestack(w_callable, nargs, f)
+ finally:
+ f.dropvalues(nargs + 1)
+ f.pushvalue(w_result)
class SpamBlock(Block):
# make slots optional, for debugging
@@ -219,7 +236,7 @@
# create an empty frame suitable for the code object
# while ignoring any operation like the creation of the locals dict
self.recorder = []
- frame = pyframe.PyFrame(self.space, self.code,
+ frame = PyFrame(self.space, self.code,
self.w_globals, self.closure)
frame.last_instr = 0
return frame
Modified: pypy/dist/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/test/test_objspace.py (original)
+++ pypy/dist/pypy/objspace/flow/test/test_objspace.py Fri Jul 13 14:24:05 2007
@@ -795,6 +795,34 @@
simplify_graph(graph)
assert self.all_operations(graph) == {'getitem': 1}
+ def test_callmethod_opcode(self):
+ """ Tests code generated by pypy-c compiled with CALL_METHOD
+ bytecode
+ """
+ class X:
+ def m(self):
+ return 3
+
+ def f():
+ x = X()
+ return x.m()
+
+ # monkey patch code
+ import new
+ c = f.func_code
+ # this code is generated by pypy-c when compiling above f
+ pypy_code = 't\x00\x00\x83\x00\x00}\x00\x00|\x00\x00\x91\x02\x00\x92\x00\x00Sd\x00\x00S'
+ new_c = new.code(c.co_argcount, c.co_nlocals, 3,
+ 3, pypy_code, c.co_consts, ('X', 'x', 'm'),
+ ('x',), c.co_filename,
+ 'f', c.co_firstlineno, c.co_lnotab)
+ f2 = new.function(new_c, locals(), 'f')
+
+ graph = self.codetest(f2)
+ all_ops = self.all_operations(graph)
+ assert all_ops['simple_call'] == 2
+ assert all_ops['getattr'] == 1
+
class TestFlowObjSpaceDelay(Base):
def setup_class(cls):
cls.space = FlowObjSpace()
More information about the Pypy-commit
mailing list