[pypy-svn] r7920 - in pypy/branch/src-pytest/pypy/interpreter: . test

arigo at codespeak.net arigo at codespeak.net
Sat Dec 18 18:08:16 CET 2004


Author: arigo
Date: Sat Dec 18 18:08:15 2004
New Revision: 7920

Modified:
   pypy/branch/src-pytest/pypy/interpreter/pyframe.py
   pypy/branch/src-pytest/pypy/interpreter/test/test_pyframe.py
   pypy/branch/src-pytest/pypy/interpreter/typedef.py
Log:
- the f_lineno attribute of frames.


Modified: pypy/branch/src-pytest/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/pyframe.py	(original)
+++ pypy/branch/src-pytest/pypy/interpreter/pyframe.py	Sat Dec 18 18:08:15 2004
@@ -81,7 +81,23 @@
             if valuestackdepth <= self.valuestack.depth():
                 break
             self.exceptionstack.pop()
-    
+
+    ### line numbers ###
+
+    def fget_f_lineno(space, w_self):
+        "Returns the line number of the instruction currently being executed."
+        self = space.unwrap_builtin(w_self)
+        return space.wrap(self.get_last_lineno())
+
+    def get_last_lineno(self):
+        "Returns the line number of the instruction currently being executed."
+        return pytraceback.offset2lineno(self.code, self.next_instr-1)
+
+    def get_next_lineno(self):
+        "Returns the line number of the next instruction to execute."
+        return pytraceback.offset2lineno(self.code, self.next_instr)
+
+
 ### Frame Blocks ###
 
 class FrameBlock:

Modified: pypy/branch/src-pytest/pypy/interpreter/test/test_pyframe.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/test/test_pyframe.py	(original)
+++ pypy/branch/src-pytest/pypy/interpreter/test/test_pyframe.py	Sat Dec 18 18:08:15 2004
@@ -28,6 +28,17 @@
             return f.f_code
         self.failUnless(g() is g.func_code)
 
+    def test_f_lineno(self):
+        def g():
+            import sys
+            f = sys._getframe()
+            x = f.f_lineno
+            y = f.f_lineno
+            z = f.f_lineno
+            return [x, y, z]
+        origin = g.func_code.co_firstlineno
+        self.assertEquals(g(), [origin+3, origin+4, origin+5])
+
 
 if __name__ == '__main__':
     testit.main()

Modified: pypy/branch/src-pytest/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/typedef.py	(original)
+++ pypy/branch/src-pytest/pypy/interpreter/typedef.py	Sat Dec 18 18:08:15 2004
@@ -212,6 +212,7 @@
 
 PyFrame.typedef = TypeDef('frame',
     f_builtins = attrproperty_w('w_builtins'),
+    f_lineno = GetSetProperty(PyFrame.fget_f_lineno.im_func),
     **Frame.typedef.rawdict)
 
 Module.typedef = TypeDef("module",



More information about the Pypy-commit mailing list