From e92cfdf437fd848096f9fbe4e36f744d96dc745f Mon Sep 17 00:00:00 2001 From: Daniel Kochmanski Date: Thu, 15 Feb 2018 12:44:49 +0100 Subject: [PATCH] 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). --- src/c/compiler.d | 32 ++++++++++++++++++++++++-------- src/c/symbols_list.h | 1 + src/c/symbols_list2.h | 1 + src/clos/method.lsp | 5 ++--- src/cmp/cmpblock.lsp | 8 ++++---- src/cmp/cmpcatch.lsp | 2 +- src/cmp/cmpenv-api.lsp | 8 ++++---- src/cmp/cmpglobals.lsp | 14 +++++++------- src/cmp/cmplam.lsp | 2 +- src/cmp/cmppackage.lsp | 5 ----- 10 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/c/compiler.d b/src/c/compiler.d index 327138d44..70ae6814d 100644 --- a/src/c/compiler.d +++ b/src/c/compiler.d @@ -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)) { diff --git a/src/c/symbols_list.h b/src/c/symbols_list.h index ffe8c65e3..a613c6f0d 100755 --- a/src/c/symbols_list.h +++ b/src/c/symbols_list.h @@ -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}, diff --git a/src/c/symbols_list2.h b/src/c/symbols_list2.h index acd1b8442..0c212c59e 100644 --- a/src/c/symbols_list2.h +++ b/src/c/symbols_list2.h @@ -2104,6 +2104,7 @@ cl_symbols[] = { {SYS_ "*TRACE-LIST*",NULL}, {SYS_ "FUNCTION-BOUNDARY",NULL}, +{SYS_ "UNWIND-PROTECT-BOUNDARY",NULL}, {EXT_ "*INSPECTOR-HOOK*",NULL}, diff --git a/src/clos/method.lsp b/src/clos/method.lsp index fafd75b23..5f6fcda3f 100644 --- a/src/clos/method.lsp +++ b/src/clos/method.lsp @@ -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) diff --git a/src/cmp/cmpblock.lsp b/src/cmp/cmpblock.lsp index 7bafa1dad..72821ccf7 100644 --- a/src/cmp/cmpblock.lsp +++ b/src/cmp/cmpblock.lsp @@ -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) diff --git a/src/cmp/cmpcatch.lsp b/src/cmp/cmpcatch.lsp index 93257fc1b..e02b20e38 100644 --- a/src/cmp/cmpcatch.lsp +++ b/src/cmp/cmpcatch.lsp @@ -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))))))) diff --git a/src/cmp/cmpenv-api.lsp b/src/cmp/cmpenv-api.lsp index c2ad0fb03..1892c4b6e 100644 --- a/src/cmp/cmpenv-api.lsp +++ b/src/cmp/cmpenv-api.lsp @@ -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" diff --git a/src/cmp/cmpglobals.lsp b/src/cmp/cmpglobals.lsp index e115e36e1..31f4e89ad 100644 --- a/src/cmp/cmpglobals.lsp +++ b/src/cmp/cmpglobals.lsp @@ -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* diff --git a/src/cmp/cmplam.lsp b/src/cmp/cmplam.lsp index 7770212ec..f3843e2a3 100644 --- a/src/cmp/cmplam.lsp +++ b/src/cmp/cmplam.lsp @@ -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* diff --git a/src/cmp/cmppackage.lsp b/src/cmp/cmppackage.lsp index 68a610fbb..9e7bdbdf0 100644 --- a/src/cmp/cmppackage.lsp +++ b/src/cmp/cmppackage.lsp @@ -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)