emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] nick.lloyd-bytecode-jit 21aa3f2 1/9: Add COMPILED_JIT_ID f


From: Nickolas Lloyd
Subject: [Emacs-diffs] nick.lloyd-bytecode-jit 21aa3f2 1/9: Add COMPILED_JIT_ID field to byte-code pseudovectors
Date: Fri, 23 Dec 2016 16:33:37 +0000 (UTC)

branch: nick.lloyd-bytecode-jit
commit 21aa3f2d3ea904f09bb92b5b5c8471a80e385230
Author: Nickolas Lloyd <address@hidden>
Commit: Nickolas Lloyd <address@hidden>

    Add COMPILED_JIT_ID field to byte-code pseudovectors
    
    * src/alloc.c (make_byte_code, Fmake_byte_code): Remove make_byte_code,
    reserve space in allocated vectors for COMPILED_JIT_ID recordkeeping field.
    * src/lisp.h: Update function prototypes, update Lisp_Compiled enum.
    * src/lread.c (read1) <compiled>: Use Fmake_byte_code in place of
    make_byte_code.
---
 src/alloc.c |   39 +++++++++++++++++++--------------------
 src/lisp.h  |    4 ++--
 src/lread.c |    6 +++---
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/src/alloc.c b/src/alloc.c
index 4523447..70404ec 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3429,23 +3429,6 @@ usage: (vector &rest OBJECTS)  */)
   return val;
 }
 
-void
-make_byte_code (struct Lisp_Vector *v)
-{
-  /* Don't allow the global zero_vector to become a byte code object.  */
-  eassert (0 < v->header.size);
-
-  if (v->header.size > 1 && STRINGP (v->contents[1])
-      && STRING_MULTIBYTE (v->contents[1]))
-    /* BYTECODE-STRING must have been produced by Emacs 20.2 or the
-       earlier because they produced a raw 8-bit string for byte-code
-       and now such a byte-code string is loaded as multibyte while
-       raw 8-bit characters converted to multibyte form.  Thus, now we
-       must convert them back to the original unibyte form.  */
-    v->contents[1] = Fstring_as_unibyte (v->contents[1]);
-  XSETPVECTYPE (v, PVEC_COMPILED);
-}
-
 DEFUN ("make-byte-code", Fmake_byte_code, Smake_byte_code, 4, MANY, 0,
        doc: /* Create a byte-code object with specified arguments as elements.
 The arguments should be the ARGLIST, bytecode-string BYTE-CODE, constant
@@ -3465,8 +3448,12 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH 
&optional DOCSTRING INT
   (ptrdiff_t nargs, Lisp_Object *args)
 {
   ptrdiff_t i;
-  register Lisp_Object val = make_uninit_vector (nargs);
+  register Lisp_Object val = make_uninit_vector (max(nargs, COMPILED_JIT_ID + 
1));
   register struct Lisp_Vector *p = XVECTOR (val);
+  size_t size = min(nargs, COMPILED_JIT_ID);
+
+  /* Don't allow the global zero_vector to become a byte code object.  */
+  eassert (0 < nargs);
 
   /* We used to purecopy everything here, if purify-flag was set.  This worked
      OK for Emacs-23, but with Emacs-24's lexical binding code, it can be
@@ -3476,9 +3463,21 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH 
&optional DOCSTRING INT
      just wasteful and other times plainly wrong (e.g. those free vars may want
      to be setcar'd).  */
 
-  for (i = 0; i < nargs; i++)
+  for (i = 0; i < size; i++)
     p->contents[i] = args[i];
-  make_byte_code (p);
+
+  if (STRINGP (p->contents[COMPILED_BYTECODE])
+      && STRING_MULTIBYTE (p->contents[COMPILED_BYTECODE]))
+    /* BYTECODE-STRING must have been produced by Emacs 20.2 or the
+       earlier because they produced a raw 8-bit string for byte-code
+       and now such a byte-code string is loaded as multibyte while
+       raw 8-bit characters converted to multibyte form.  Thus, now we
+       must convert them back to the original unibyte form.  */
+    p->contents[COMPILED_BYTECODE] = Fstring_as_unibyte 
(p->contents[COMPILED_BYTECODE]);
+
+  /* set rest size so that total footprint = COMPILED_JIT_ID + 1 */
+  XSETPVECTYPESIZE (p, PVEC_COMPILED, size, COMPILED_JIT_ID + 1 - size);
+  p->contents[COMPILED_JIT_ID] = 0;
   XSETCOMPILED (val, p);
   return val;
 }
diff --git a/src/lisp.h b/src/lisp.h
index 25f811e..b61855a 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2524,7 +2524,8 @@ enum Lisp_Compiled
     COMPILED_CONSTANTS = 2,
     COMPILED_STACK_DEPTH = 3,
     COMPILED_DOC_STRING = 4,
-    COMPILED_INTERACTIVE = 5
+    COMPILED_INTERACTIVE = 5,
+    COMPILED_JIT_ID = 6
   };
 
 /* Flag bits in a character.  These also get used in termhooks.h.
@@ -3671,7 +3672,6 @@ build_string (const char *str)
 }
 
 extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object);
-extern void make_byte_code (struct Lisp_Vector *);
 extern struct Lisp_Vector *allocate_vector (EMACS_INT);
 
 /* Make an uninitialized vector for SIZE objects.  NOTE: you must
diff --git a/src/lread.c b/src/lread.c
index ef58b20..d8cfc68 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -2660,14 +2660,14 @@ read1 (Lisp_Object readcharfun, int *pch, bool 
first_in_list)
        {
          /* Accept compiled functions at read-time so that we don't have to
             build them using function calls.  */
-         Lisp_Object tmp;
+         Lisp_Object tmp, ret;
          struct Lisp_Vector *vec;
          tmp = read_vector (readcharfun, 1);
          vec = XVECTOR (tmp);
          if (vec->header.size == 0)
            invalid_syntax ("Empty byte-code object");
-         make_byte_code (vec);
-         return tmp;
+         ret = Fmake_byte_code (vec->header.size, vec->contents);
+         return ret;
        }
       if (c == '(')
        {



reply via email to

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