From 4496a3f5ba899c89e45cd478a22b25ddf77869ec Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Fri, 20 Dec 2019 05:22:09 +0100 Subject: [PATCH] initial compilation unit as object add --- src/alloc.c | 19 +++++++++++++++++++ src/comp.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lisp.h | 18 +++--------------- src/print.c | 11 ++++++++++- 4 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 src/comp.h diff --git a/src/alloc.c b/src/alloc.c index 5ff0d907915..d990f53f7a0 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -3023,6 +3023,15 @@ cleanup_vector (struct Lisp_Vector *vector) if (uptr->finalizer) uptr->finalizer (uptr->p); } +#ifdef HAVE_NATIVE_COMP + else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_NATIVE_COMP_UNIT)) + { + struct Lisp_Native_Compilation_Unit *cu = + PSEUDOVEC_STRUCT (vector, Lisp_Native_Compilation_Unit); + eassert (cu->handle); + dynlib_close (cu->handle); + } +#endif } /* Reclaim space used by unmarked vectors. */ @@ -6556,6 +6565,10 @@ mark_object (Lisp_Object arg) break; case PVEC_SUBR: +#ifdef HAVE_NATIVE_COMP + if (XSUBR (obj)->native_comp_u) + set_vector_marked (ptr); +#endif break; case PVEC_FREE: @@ -6700,7 +6713,13 @@ survives_gc_p (Lisp_Object obj) break; case Lisp_Vectorlike: +#ifdef HAVE_NATIVE_COMP + survives_p = + (SUBRP (obj) && !XSUBR (obj)->native_comp_u) || + vector_marked_p (XVECTOR (obj)); +#else survives_p = SUBRP (obj) || vector_marked_p (XVECTOR (obj)); +#endif break; case Lisp_Cons: diff --git a/src/comp.h b/src/comp.h new file mode 100644 index 00000000000..457b678699c --- /dev/null +++ b/src/comp.h @@ -0,0 +1,52 @@ +/* Elisp native compiler definitions +Copyright (C) 2012-2019 Free Software Foundation, Inc. + +This file is part of GNU Emacs. + +GNU Emacs is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +GNU Emacs is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Emacs. If not, see . */ + +#ifndef COMP_H +#define COMP_H + +#ifdef HAVE_NATIVE_COMP + +#include + +struct Lisp_Native_Compilation_Unit +{ + union vectorlike_header header; + /* Compilation unit file descriptor and handle. */ + int fd; + dynlib_handle_ptr handle; +}; + +INLINE bool +COMPILATIONP_UNITP (Lisp_Object a) +{ + return PSEUDOVECTORP (a, PVEC_NATIVE_COMP_UNIT); +} + +INLINE struct Lisp_Native_Compilation_Unit * +XCOMPILATION_UNIT (Lisp_Object a) +{ + eassert (COMPILATIONP_UNITP (a)); + return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Native_Compilation_Unit); +} + +/* Defined in comp.c. */ +extern void syms_of_comp (void); +extern void fill_freloc (void); + +#endif +#endif diff --git a/src/lisp.h b/src/lisp.h index 04f729f182a..bb441b181a1 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -34,10 +34,6 @@ along with GNU Emacs. If not, see . */ #include #include -#ifdef HAVE_NATIVE_COMP -#include -#endif - INLINE_HEADER_BEGIN /* Define a TYPE constant ID as an externally visible name. Use like this: @@ -1097,6 +1093,7 @@ enum pvec_type PVEC_MUTEX, PVEC_CONDVAR, PVEC_MODULE_FUNCTION, + PVEC_NATIVE_COMP_UNIT, /* These should be last, check internal_equal to see why. */ PVEC_COMPILED, @@ -2068,10 +2065,7 @@ CHAR_TABLE_SET (Lisp_Object ct, int idx, Lisp_Object val) char_table_set (ct, idx, val); } -struct Native_Compilation_Unit -{ - dynlib_handle_ptr handle; -}; +#include "comp.h" /* This structure describes a built-in function. It is generated by the DEFUN macro only. @@ -2104,7 +2098,7 @@ struct Lisp_Subr Lisp_Object native_doc; }; #ifdef HAVE_NATIVE_COMP - struct Native_Compilation_Unit *native_comp_u;; + Lisp_Object native_comp_u;; #endif } GCALIGNED_STRUCT; union Aligned_Lisp_Subr @@ -4759,12 +4753,6 @@ extern bool profiler_memory_running; extern void malloc_probe (size_t); extern void syms_of_profiler (void); -#ifdef HAVE_NATIVE_COMP -/* Defined in comp.c. */ -extern void syms_of_comp (void); -extern void fill_freloc (void); -#endif /* HAVE_NATIVE_COMP */ - #ifdef DOS_NT /* Defined in msdos.c, w32.c. */ extern char *emacs_root_dir (void); diff --git a/src/print.c b/src/print.c index 425b0dc4ee3..2e2c863ece8 100644 --- a/src/print.c +++ b/src/print.c @@ -1825,7 +1825,16 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, } break; #endif - +#ifdef HAVE_NATIVE_COMP + case PVEC_NATIVE_COMP_UNIT: + { + print_c_string ("#", printcharfun); + int len = sprintf (buf, "%d", XCOMPILATION_UNIT (obj)->fd); + strout (buf, len, len, printcharfun); + printchar ('>', printcharfun); + } + break; +#endif default: emacs_abort (); } -- 2.39.5