mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-23 13:01:42 -08:00
Unify compilation environment markers
In both bytecmp and c compiler we use si:function-boundary and si:unwind-protect-boundary where appropriate. Previously bytecmp used an ad-hoc special variable for function-boundary and didn't mark unwind-protect at all. Remove recently-introduced ECI package (maybe we will reintroduce it later when we'll have a common frontend for compilers).
This commit is contained in:
parent
c94784ac77
commit
e92cfdf437
10 changed files with 45 additions and 33 deletions
|
|
@ -393,18 +393,21 @@ asm_op2c(cl_env_ptr env, int code, cl_object o) {
|
|||
* (:function function-name used-p [location]) |
|
||||
* (var-name {:special | nil} bound-p [location]) |
|
||||
* (symbol si::symbol-macro macro-function) |
|
||||
* ECI:FUNCTION | ECI:UNWIND-PROTECT |
|
||||
* SI:FUNCTION-BOUNDARY |
|
||||
* SI:UNWIND-PROTECT-BOUNDARY
|
||||
* (:declare declaration-arguments*)
|
||||
* macro-record = (function-name FUNCTION [| function-object]) |
|
||||
* (macro-name si::macro macro-function)
|
||||
* ECI:FUNCTION | ECI:UNWIND-PROTECT
|
||||
* SI:FUNCTION-BOUNDARY |
|
||||
* SI:UNWIND-PROTECT-BOUNDARY
|
||||
*
|
||||
* A *-NAME is a symbol. A TAG-ID is either a symbol or a number. A
|
||||
* MACRO-FUNCTION is a function that provides us with the expansion for that
|
||||
* local macro or symbol macro. BOUND-P is true when the variable has been bound
|
||||
* by an enclosing form, while it is NIL if the variable-record corresponds just
|
||||
* to a special declaration. ECI:FUNCTION and ECIUNWIND-PROTECT are only used
|
||||
* by the C compiler and they denote function and unwind-protect boundaries.
|
||||
* to a special declaration. SI:FUNCTION-BOUNDARY and SI:UNWIND-PROTECT-BOUNDARY
|
||||
* are only used by the C compiler and they denote function and unwind-protect
|
||||
* boundaries.
|
||||
*
|
||||
* The brackets [] denote differences between the bytecodes and C compiler
|
||||
* environments, with the first option belonging to the interpreter and the
|
||||
|
|
@ -500,6 +503,14 @@ c_register_var(cl_env_ptr env, cl_object var, bool special, bool bound)
|
|||
c_env->variables);
|
||||
}
|
||||
|
||||
static void
|
||||
c_register_boundary(cl_env_ptr env, cl_object type)
|
||||
{
|
||||
const cl_compiler_ptr c_env = env->c_env;
|
||||
c_env->variables = CONS(type, c_env->variables);
|
||||
c_env->macros = CONS(type, c_env->macros);
|
||||
}
|
||||
|
||||
static void
|
||||
guess_environment(cl_env_ptr env, cl_object interpreter_env)
|
||||
{
|
||||
|
|
@ -725,6 +736,8 @@ c_undo_bindings(cl_env_ptr the_env, cl_object old_vars, int only_specials)
|
|||
{
|
||||
cl_object record, name, special;
|
||||
record = ECL_CONS_CAR(env);
|
||||
if (ECL_ATOM(record))
|
||||
continue;
|
||||
name = ECL_CONS_CAR(record);
|
||||
record = ECL_CONS_CDR(record);
|
||||
special = ECL_CONS_CAR(record);
|
||||
|
|
@ -2106,6 +2119,10 @@ static int
|
|||
c_unwind_protect(cl_env_ptr env, cl_object args, int flags) {
|
||||
cl_index label = asm_jmp(env, OP_PROTECT);
|
||||
|
||||
/* We register unwind-protect boundary. This mark is not used in bytecode
|
||||
compiler but we do it anyway to have better compilation environment. */
|
||||
c_register_boundary(env, @'si::unwind-protect-boundary');
|
||||
|
||||
flags = maybe_values(flags);
|
||||
|
||||
/* Compile form to be protected */
|
||||
|
|
@ -2973,10 +2990,9 @@ ecl_make_lambda(cl_env_ptr env, cl_object name, cl_object lambda) {
|
|||
if (!Null(name) && Null(si_valid_function_name_p(name)))
|
||||
FEprogram_error("LAMBDA: Not a valid function name ~S.",1,name);
|
||||
|
||||
/* We register as special variable a symbol which is not
|
||||
* to be used. We use this to mark the boundary of a function
|
||||
* environment and when code-walking */
|
||||
c_register_var(env, @'si::function-boundary', TRUE, FALSE);
|
||||
/* We register the function boundary. We use this mark in both variables and
|
||||
* macros for code-walking. */
|
||||
c_register_boundary(env, @'si::function-boundary');
|
||||
|
||||
reqs = ECL_CONS_CDR(reqs); /* Required arguments */
|
||||
while (!Null(reqs)) {
|
||||
|
|
|
|||
|
|
@ -2104,6 +2104,7 @@ cl_symbols[] = {
|
|||
{SYS_ "*TRACE-LIST*", SI_SPECIAL, NULL, -1, ECL_NIL},
|
||||
|
||||
{SYS_ "FUNCTION-BOUNDARY", SI_ORDINARY, NULL, -1, OBJNULL},
|
||||
{SYS_ "UNWIND-PROTECT-BOUNDARY", SI_ORDINARY, NULL, -1, OBJNULL},
|
||||
|
||||
{EXT_ "*INSPECTOR-HOOK*", EXT_SPECIAL, NULL, -1, ECL_NIL},
|
||||
|
||||
|
|
|
|||
|
|
@ -2104,6 +2104,7 @@ cl_symbols[] = {
|
|||
{SYS_ "*TRACE-LIST*",NULL},
|
||||
|
||||
{SYS_ "FUNCTION-BOUNDARY",NULL},
|
||||
{SYS_ "UNWIND-PROTECT-BOUNDARY",NULL},
|
||||
|
||||
{EXT_ "*INSPECTOR-HOOK*",NULL},
|
||||
|
||||
|
|
|
|||
|
|
@ -208,9 +208,8 @@
|
|||
(let ((counter 0))
|
||||
(declare (fixnum counter))
|
||||
(dolist (item (car env))
|
||||
(when (and (consp item)
|
||||
(eq (first (the cons item)) 'si::function-boundary)
|
||||
(> (incf counter) 1))
|
||||
(when (and (eq item 'si::function-boundary)
|
||||
(> (incf counter) 1))
|
||||
(return t)))))
|
||||
|
||||
(defun walk-method-lambda (method-lambda env)
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@
|
|||
;;; A dummy variable is created to hold the block identifier. When a reference
|
||||
;;; to the block (via `return-from') is found, the `var-ref' count for that
|
||||
;;; variable is incremented only if the reference appears across a boundary
|
||||
;;; (`ECI:FUNCTION' or `ECI:UNWIND-PROTECT'), while the `blk-ref' is always
|
||||
;;; incremented. Therefore `blk-ref' represents whether the block is used at
|
||||
;;; all and `var-ref' for the dummy variable represents whether a block
|
||||
;;; identifier must be created and stored in such variable.
|
||||
;;; (`SI:FUNCTION-BOUNDARY' or `SI:UNWIND-PROTECT-BOUNDARY'), while the
|
||||
;;; `blk-ref' is always incremented. Therefore `blk-ref' represents whether the
|
||||
;;; block is used at all and `var-ref' for the dummy variable represents whether
|
||||
;;; a block identifier must be created and stored in such variable.
|
||||
|
||||
(defun c1block (args)
|
||||
(check-args-number 'BLOCK args 1)
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
(c1expr (first args)))
|
||||
(T
|
||||
(incf *setjmps*)
|
||||
(let ((form (let ((*cmp-env* (cmp-env-mark 'ECI:UNWIND-PROTECT)))
|
||||
(let ((form (let ((*cmp-env* (cmp-env-mark 'SI:UNWIND-PROTECT-BOUNDARY)))
|
||||
(c1expr (first args)))))
|
||||
(make-c1form* 'UNWIND-PROTECT :type (c1form-type form) :sp-change t
|
||||
:args form (c1progn (rest args)))))))
|
||||
|
|
|
|||
|
|
@ -121,9 +121,9 @@ that are susceptible to be changed by PROCLAIM."
|
|||
(unw nil)
|
||||
(found nil))
|
||||
(dolist (record (cmp-env-functions env))
|
||||
(cond ((eq record 'ECI:FUNCTION)
|
||||
(cond ((eq record 'SI:FUNCTION-BOUNDARY)
|
||||
(setf cfb t))
|
||||
((eq record 'ECI:UNWIND-PROTECT)
|
||||
((eq record 'SI:UNWIND-PROTECT-BOUNDARY)
|
||||
(setf unw t))
|
||||
((atom record)
|
||||
(baboon :format-control "Uknown record found in environment~%~S"
|
||||
|
|
@ -139,9 +139,9 @@ that are susceptible to be changed by PROCLAIM."
|
|||
(unw nil)
|
||||
(found nil))
|
||||
(dolist (record (cmp-env-variables env))
|
||||
(cond ((eq record 'ECI:FUNCTION)
|
||||
(cond ((eq record 'SI:FUNCTION-BOUNDARY)
|
||||
(setf cfb t))
|
||||
((eq record 'ECI:UNWIND-PROTECT)
|
||||
((eq record 'SI:UNWIND-PROTECT-BOUNDARY)
|
||||
(setf unw t))
|
||||
((atom record)
|
||||
(baboon :format-control "Uknown record found in environment~%~S"
|
||||
|
|
|
|||
|
|
@ -165,21 +165,21 @@ variable-record = (:block block-name) |
|
|||
(:function function-name) |
|
||||
(var-name {:special | nil} bound-p) |
|
||||
(symbol si::symbol-macro macro-function) |
|
||||
ECI:FUNCTION |
|
||||
ECI:UNWIND-PROTECT
|
||||
SI:FUNCTION-BOUNDARY |
|
||||
SI:UNWIND-PROTECT-BOUNDARY
|
||||
|
||||
macro-record = (function-name function) |
|
||||
(macro-name si::macro macro-function)
|
||||
ECI:FUNCTION |
|
||||
ECI:UNWIND-PROTECT
|
||||
SI:FUNCTION-BOUNDARY |
|
||||
SI:UNWIND-PROTECT-BOUNDARY
|
||||
|
||||
A *-NAME is a symbol. A TAG-ID is either a symbol or a number. A MACRO-FUNCTION
|
||||
is a function that provides us with the expansion for that local macro or symbol
|
||||
macro. BOUND-P is true when the variable has been bound by an enclosing form,
|
||||
while it is NIL if the variable-record corresponds just to a special
|
||||
declaration. ECI:FUNCTION and ECI:UNWIND-PROTECT are only used by the C
|
||||
compiler and they denote function and unwind-protect boundaries. Note that
|
||||
compared with the bytecodes compiler, these records contain an additional
|
||||
declaration. SI:FUNCTION-BOUNDARY and SI:UNWIND-PROTECT-BOUNDARY are only used
|
||||
by the C compiler and they denote function and unwind-protect boundaries. Note
|
||||
that compared with the bytecodes compiler, these records contain an additional
|
||||
variable, block, tag or function object at the end.")
|
||||
|
||||
(defvar *cmp-env-root*
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ The function thus belongs to the type of functions that ecl_make_cfun accepts."
|
|||
(when *current-function*
|
||||
(push fun (fun-child-funs *current-function*)))
|
||||
(let* ((*current-function* fun)
|
||||
(*cmp-env* (setf (fun-cmp-env fun) (cmp-env-mark 'ECI:FUNCTION)))
|
||||
(*cmp-env* (setf (fun-cmp-env fun) (cmp-env-mark 'SI:FUNCTION-BOUNDARY)))
|
||||
(setjmps *setjmps*)
|
||||
(decl (si::process-declarations (rest lambda-list-and-body)))
|
||||
(global (and *use-c-global*
|
||||
|
|
|
|||
|
|
@ -14,10 +14,6 @@
|
|||
;;;; CMPPACKAGE -- Package definitions and exported symbols
|
||||
;;;;
|
||||
|
||||
(defpackage #:ecl-cmp-internals
|
||||
(:export #:unwind-protect
|
||||
#:function))
|
||||
|
||||
(defpackage "C"
|
||||
(:nicknames "COMPILER")
|
||||
(:use "FFI" "EXT" #+threads "MP" "CL")
|
||||
|
|
@ -54,4 +50,3 @@
|
|||
"COMPILER-LET"))
|
||||
|
||||
(ext:package-lock "CL" nil)
|
||||
(ext:add-package-local-nickname "ECI" '#:ecl-cmp-internals '#:compiler)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue