[pypy-svn] r9955 - pypy/dist/pypy/interpreter

rxe at codespeak.net rxe at codespeak.net
Sun Mar 20 23:04:42 CET 2005


Author: rxe
Date: Sun Mar 20 23:04:41 2005
New Revision: 9955

Modified:
   pypy/dist/pypy/interpreter/executioncontext.py
   pypy/dist/pypy/interpreter/pyframe.py
Log:
Updates for getting sys.settrace() working.


Modified: pypy/dist/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/dist/pypy/interpreter/executioncontext.py	(original)
+++ pypy/dist/pypy/interpreter/executioncontext.py	Sun Mar 20 23:04:41 2005
@@ -1,3 +1,4 @@
+import sys
 from pypy.interpreter.miscutils import getthreadlocals, Stack
 from pypy.interpreter.error import OperationError
 
@@ -56,6 +57,49 @@
 
     def bytecode_trace(self, frame):
         "Trace function called before each bytecode."
+        if self.is_tracing or frame.w_f_trace is None:
+            return
+
+        if frame.instr_lb <= frame.last_instr < frame.instr_ub:
+            return
+
+        code = getattr(frame, 'code')
+
+        size = len(code.co_lnotab) / 2
+        addr = 0
+        line = code.co_firstlineno
+        p = iter(code.co_lnotab)
+
+        while size > 0:
+            c = ord(p.next())
+            if (addr + c) > frame.last_instr:
+                break
+            addr += c
+            if c:
+                frame.instr_lb = addr
+
+            c = ord(p.next())
+            line += c
+            size -= 1
+
+        if addr == frame.last_instr:
+            frame.f_lineno = line
+            self._trace(frame, 'line', self.space.w_None)
+
+        if size > 0:
+            size -= 1
+            while size >= 0:
+
+                c = ord(p.next())
+                addr += c
+                if c:
+                    break
+
+            frame.instr_ub = addr
+        else:
+            frame.instr_ub = sys.maxint
+
+
 
     def exception_trace(self, operationerr):
         "Trace function called upon OperationError."

Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py	(original)
+++ pypy/dist/pypy/interpreter/pyframe.py	Sun Mar 20 23:04:41 2005
@@ -43,6 +43,11 @@
         self.w_f_trace = None
         self.last_instr = -1
         self.f_back = None
+        self.f_lineno = self.code.co_firstlineno
+        
+        # For tracing
+        self.instr_lb = 0
+        self.instr_ub = -1
         
     def getfastscope(self):
         "Get the fast locals as a list."
@@ -73,8 +78,8 @@
                             while True:
                                 # fetch and dispatch the next opcode
                                 # dispatch() is abstract, see pyopcode.
-                                executioncontext.bytecode_trace(self)
                                 self.last_instr = self.next_instr
+                                executioncontext.bytecode_trace(self)
                                 self.dispatch()
                         # catch asynchronous exceptions and turn them
                         # into OperationErrors
@@ -129,7 +134,23 @@
     def fget_f_lineno(space, w_self):
         "Returns the line number of the instruction currently being executed."
         self = space.interpclass_w(w_self)
-        return space.wrap(self.get_last_lineno())
+        if self.w_f_trace is None:
+            return space.wrap(self.get_last_lineno())
+        else:
+            return space.wrap(self.f_lineno)
+
+##     def fset_f_lineno(space, w_self, w_f_lineo):
+##         "Returns the line number of the instruction currently being executed."
+##         f_lineo = space.int_w(w_f_lineo)
+
+##         self = space.interpclass_w(w_self)
+##         if self.self.w_f_trace is None:
+##             raise OperationError(self.space.w_ValueError, space.wrap("f_lineo can only be set by a trace function."))
+
+##         if f_lineo < self.code.co_firstlineno:
+##             raise OperationError(self.space.w_ValueError, space.wrap("line %d comes before the current code." % f_lineo))
+
+##         self.f_lineno = f_lineo
 
     def get_last_lineno(self):
         "Returns the line number of the instruction currently being executed."



More information about the Pypy-commit mailing list