From 21aa3f2d3ea904f09bb92b5b5c8471a80e385230 Mon Sep 17 00:00:00 2001 From: Nickolas Lloyd Date: Wed, 2 Nov 2016 21:10:43 -0400 Subject: [PATCH] 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) : 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 45234474a27..70404ecfb29 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 25f811e06ef..b61855a89de 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 ef58b20070d..d8cfc68361b 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 == '(') { -- 2.39.5