emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/zach-soc-funcall-from-bytecode f6ec28d 4/6: Store bytecode offse


From: Rocky Bernstein
Subject: feature/zach-soc-funcall-from-bytecode f6ec28d 4/6: Store bytecode offset within exec_byte_code
Date: Fri, 26 Jun 2020 11:54:47 -0400 (EDT)

branch: feature/zach-soc-funcall-from-bytecode
commit f6ec28d7974785b625e395d57cb18d1f2110fe4c
Author: Zach Shaftel <zshaftel@gmail.com>
Commit: Zach Shaftel <zshaftel@gmail.com>

    Store bytecode offset within exec_byte_code
    
    * src/bytecode.c (exec_byte_code): Store offset in the backtrace frame
    for the function being executed, before calling Ffuncall.
    
    * src/eval.c (record_in_backtrace): Don't record the offset.
    (backtrace_next, backtrace_top): Move declarations to lisp.h.
    
    * src/lisp.h (backtrace_next, backtrace_top): Declare.
---
 src/bytecode.c | 11 ++++++++---
 src/eval.c     |  9 +--------
 src/lisp.h     |  3 ++-
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/bytecode.c b/src/bytecode.c
index 6b7e9cb..f4900fc 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -378,6 +378,8 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, 
Lisp_Object maxdepth,
   memcpy (bytestr_data, SDATA (bytestr), bytestr_length);
   unsigned char const *pc = bytestr_data;
   ptrdiff_t count = SPECPDL_INDEX ();
+  union specbinding *bt_frame = specpdl_ptr;
+  bt_frame = backtrace_next (bt_frame);
 
   if (!NILP (args_template))
     {
@@ -424,14 +426,16 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, 
Lisp_Object maxdepth,
         Threading provides a performance boost.  These macros are how
         we allow the code to be compiled both ways.  */
 #ifdef BYTE_CODE_THREADED
-#define UPDATE_OFFSET (backtrace_byte_offset = pc - bytestr_data);
+#define UPDATE_OFFSET(to)                                      \
+      if (bt_frame->kind == SPECPDL_BACKTRACE)                 \
+       bt_frame->bt.bytecode_offset = (to);
       /* The CASE macro introduces an instruction's body.  It is
         either a label or a case label.  */
 #define CASE(OP) insn_ ## OP
       /* NEXT is invoked at the end of an instruction to go to the
         next instruction.  It is either a computed goto, or a
         plain break.  */
-#define NEXT UPDATE_OFFSET goto *(targets[op = FETCH])
+#define NEXT goto *(targets[op = FETCH])
       /* FIRST is like NEXT, but is only used at the start of the
         interpreter body.  In the switch-based interpreter it is the
         switch, so the threaded definition must include a semicolon.  */
@@ -633,6 +637,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, 
Lisp_Object maxdepth,
                  }
              }
 #endif
+           UPDATE_OFFSET(pc - bytestr_data);
            TOP = Ffuncall (op + 1, &TOP);
            NEXT;
          }
@@ -1449,7 +1454,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, 
Lisp_Object maxdepth,
        unbind_to (count, Qnil);
       error ("binding stack not balanced (serious byte compiler bug)");
     }
-  backtrace_byte_offset = -1;
+  UPDATE_OFFSET(-1);
   Lisp_Object result = TOP;
   SAFE_FREE ();
   return result;
diff --git a/src/eval.c b/src/eval.c
index 5b43b81..26e552e 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -56,14 +56,10 @@ Lisp_Object Vrun_hooks;
 /* FIXME: We should probably get rid of this!  */
 Lisp_Object Vsignaling_function;
 
-int backtrace_byte_offset = -1;
-
 /* These would ordinarily be static, but they need to be visible to GDB.  */
 bool backtrace_p (union specbinding *) EXTERNALLY_VISIBLE;
 Lisp_Object *backtrace_args (union specbinding *) EXTERNALLY_VISIBLE;
 Lisp_Object backtrace_function (union specbinding *) EXTERNALLY_VISIBLE;
-union specbinding *backtrace_next (union specbinding *) EXTERNALLY_VISIBLE;
-union specbinding *backtrace_top (void) EXTERNALLY_VISIBLE;
 
 static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *);
 static Lisp_Object apply_lambda (Lisp_Object, Lisp_Object, ptrdiff_t);
@@ -2156,10 +2152,7 @@ record_in_backtrace (Lisp_Object function, Lisp_Object 
*args, ptrdiff_t nargs)
   specpdl_ptr->bt.function = function;
   current_thread->stack_top = specpdl_ptr->bt.args = args;
   specpdl_ptr->bt.nargs = nargs;
-  union specbinding *nxt = specpdl_ptr;
-  nxt = backtrace_next(nxt);
-  if (nxt->kind == SPECPDL_BACKTRACE)
-    nxt->bt.bytecode_offset = backtrace_byte_offset;
+  specpdl_ptr->bt.bytecode_offset = -1;
   grow_specpdl ();
 
   return count;
diff --git a/src/lisp.h b/src/lisp.h
index ef6302a..8a7f62d 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4113,7 +4113,6 @@ extern Lisp_Object Vautoload_queue;
 extern Lisp_Object Vrun_hooks;
 extern Lisp_Object Vsignaling_function;
 extern Lisp_Object inhibit_lisp_code;
-extern int backtrace_byte_offset;
 
 /* To run a normal hook, use the appropriate function from the list below.
    The calling convention:
@@ -4195,6 +4194,8 @@ extern void prog_ignore (Lisp_Object);
 extern ptrdiff_t record_in_backtrace (Lisp_Object, Lisp_Object *, ptrdiff_t);
 extern void mark_specpdl (union specbinding *first, union specbinding *ptr);
 extern void get_backtrace (Lisp_Object array);
+extern union specbinding *backtrace_next (union specbinding *pdl) 
EXTERNALLY_VISIBLE;
+extern union specbinding *backtrace_top (void) EXTERNALLY_VISIBLE;
 Lisp_Object backtrace_top_function (void);
 extern bool let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol);
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]