X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fir1tran-lambda.lisp;h=534933e1f6d92e625878b4ff514b6ad32e2353c7;hb=b63c4fb9b98fa8188e17ba926e150ba417a74635;hp=ef8d4e0c21b450125c48a2c61b117cd1d3de00f6;hpb=a574de23a28d9df8b89bdb4fa96f608b6f5777f0;p=sbcl.git diff --git a/src/compiler/ir1tran-lambda.lisp b/src/compiler/ir1tran-lambda.lisp index ef8d4e0..534933e 100644 --- a/src/compiler/ir1tran-lambda.lisp +++ b/src/compiler/ir1tran-lambda.lisp @@ -202,20 +202,22 @@ ;;; FIXME: This could and probably should be converted to use ;;; SOURCE-NAME and DEBUG-NAME. But I (WHN) don't use &AUX bindings, ;;; so I'm not motivated. Patches will be accepted... -(defun ir1-convert-aux-bindings (start cont body aux-vars aux-vals) - (declare (type continuation start cont) (list body aux-vars aux-vals)) +(defun ir1-convert-aux-bindings (start next result body aux-vars aux-vals) + (declare (type ctran start next) (type (or lvar null) result) + (list body aux-vars aux-vals)) (if (null aux-vars) - (ir1-convert-progn-body start cont body) - (let ((fun-cont (make-continuation)) + (ir1-convert-progn-body start next result body) + (let ((ctran (make-ctran)) + (fun-lvar (make-lvar)) (fun (ir1-convert-lambda-body body (list (first aux-vars)) :aux-vars (rest aux-vars) :aux-vals (rest aux-vals) :debug-name (debug-namify - "&AUX bindings ~S" + "&AUX bindings " aux-vars)))) - (reference-leaf start fun-cont fun) - (ir1-convert-combination-args fun-cont cont + (reference-leaf start ctran fun-lvar fun) + (ir1-convert-combination-args fun-lvar ctran next result (list (first aux-vals))))) (values)) @@ -225,29 +227,31 @@ ;;; the body, otherwise we do one special binding and recurse on the ;;; rest. ;;; -;;; We make a cleanup and introduce it into the lexical environment. -;;; If there are multiple special bindings, the cleanup for the blocks -;;; will end up being the innermost one. We force CONT to start a -;;; block outside of this cleanup, causing cleanup code to be emitted -;;; when the scope is exited. -(defun ir1-convert-special-bindings (start cont body aux-vars aux-vals svars) - (declare (type continuation start cont) +;;; We make a cleanup and introduce it into the lexical +;;; environment. If there are multiple special bindings, the cleanup +;;; for the blocks will end up being the innermost one. We force NEXT +;;; to start a block outside of this cleanup, causing cleanup code to +;;; be emitted when the scope is exited. +(defun ir1-convert-special-bindings + (start next result body aux-vars aux-vals svars) + (declare (type ctran start next) (type (or lvar null) result) (list body aux-vars aux-vals svars)) (cond ((null svars) - (ir1-convert-aux-bindings start cont body aux-vars aux-vals)) + (ir1-convert-aux-bindings start next result body aux-vars aux-vals)) (t - (continuation-starts-block cont) + (ctran-starts-block next) (let ((cleanup (make-cleanup :kind :special-bind)) (var (first svars)) - (next-cont (make-continuation)) - (nnext-cont (make-continuation))) - (ir1-convert start next-cont + (bind-ctran (make-ctran)) + (cleanup-ctran (make-ctran))) + (ir1-convert start bind-ctran nil `(%special-bind ',(lambda-var-specvar var) ,var)) - (setf (cleanup-mess-up cleanup) (continuation-use next-cont)) + (setf (cleanup-mess-up cleanup) (ctran-use bind-ctran)) (let ((*lexenv* (make-lexenv :cleanup cleanup))) - (ir1-convert next-cont nnext-cont '(%cleanup-point)) - (ir1-convert-special-bindings nnext-cont cont body aux-vars aux-vals + (ir1-convert bind-ctran cleanup-ctran nil '(%cleanup-point)) + (ir1-convert-special-bindings cleanup-ctran next result + body aux-vars aux-vals (rest svars)))))) (values)) @@ -263,11 +267,11 @@ ;;; the special binding code. ;;; ;;; We ignore any ARG-INFO in the VARS, trusting that someone else is -;;; dealing with &nonsense. +;;; dealing with &NONSENSE, except for &REST vars with DYNAMIC-EXTENT. ;;; ;;; AUX-VARS is a list of VAR structures for variables that are to be ;;; sequentially bound. Each AUX-VAL is a form that is to be evaluated -;;; to get the initial value for the corresponding AUX-VAR. +;;; to get the initial value for the corresponding AUX-VAR. (defun ir1-convert-lambda-body (body vars &key @@ -286,7 +290,12 @@ :bind bind :%source-name source-name :%debug-name debug-name)) - (result (make-continuation))) + (result-ctran (make-ctran)) + (result-lvar (make-lvar))) + + (awhen (lexenv-lambda *lexenv*) + (push lambda (lambda-children it)) + (setf (lambda-parent lambda) it)) ;; just to check: This function should fail internal assertions if ;; we didn't set up a valid debug name above. @@ -320,26 +329,25 @@ (setf (bind-lambda bind) lambda) (setf (node-lexenv bind) *lexenv*) - (let ((block (continuation-starts-block result))) - (let ((return (make-return :result result :lambda lambda)) - (tail-set (make-tail-set :funs (list lambda))) - (dummy (make-continuation))) + (let ((block (ctran-starts-block result-ctran))) + (let ((return (make-return :result result-lvar :lambda lambda)) + (tail-set (make-tail-set :funs (list lambda)))) (setf (lambda-tail-set lambda) tail-set) (setf (lambda-return lambda) return) - (setf (continuation-dest result) return) - (setf (block-last block) return) - (link-node-to-previous-continuation return result) - (use-continuation return dummy)) + (setf (lvar-dest result-lvar) return) + (link-node-to-previous-ctran return result-ctran) + (setf (block-last block) return)) (link-blocks block (component-tail *current-component*))) (with-component-last-block (*current-component* - (continuation-block result)) - (let ((cont1 (make-continuation)) - (cont2 (make-continuation))) - (continuation-starts-block cont1) - (link-node-to-previous-continuation bind cont1) - (use-continuation bind cont2) - (ir1-convert-special-bindings cont2 result body + (ctran-block result-ctran)) + (let ((prebind-ctran (make-ctran)) + (postbind-ctran (make-ctran))) + (ctran-starts-block prebind-ctran) + (link-node-to-previous-ctran bind prebind-ctran) + (use-ctran bind postbind-ctran) + (ir1-convert-special-bindings postbind-ctran result-ctran + result-lvar body aux-vars aux-vals (svars)))))) (link-blocks (component-head *current-component*) (node-block bind)) @@ -353,8 +361,7 @@ (type optional-dispatch dispatcher)) (setf (functional-kind entry) :optional) (setf (leaf-ever-used entry) t) - (setf (lambda-optional-dispatch entry) - dispatcher) + (setf (lambda-optional-dispatch entry) dispatcher) entry) ;;; Create the actual entry-point function for an optional entry @@ -390,8 +397,8 @@ ,@(default-vals)))) arg-vars :debug-name - (debug-namify "&OPTIONAL processor ~D" - (random 100)) + (debug-namify "&OPTIONAL processor " + (gensym)) :note-lexical-bindings nil)))) (mapc (lambda (var arg-var) (when (cdr (leaf-refs arg-var)) @@ -498,7 +505,8 @@ :type (leaf-type var) :where-from (leaf-where-from var)))) - (let* ((n-context (gensym "N-CONTEXT-")) + (let* ((*allow-instrumenting* nil) + (n-context (gensym "N-CONTEXT-")) (context-temp (make-lambda-var :%source-name n-context)) (n-count (gensym "N-COUNT-")) (count-temp (make-lambda-var :%source-name n-count @@ -507,7 +515,8 @@ (arg-vars context-temp count-temp) (when rest - (arg-vals `(%listify-rest-args ,n-context ,n-count))) + (arg-vals `(%listify-rest-args + ,n-context ,n-count))) (when morep (arg-vals n-context) (arg-vals n-count)) @@ -557,7 +566,7 @@ (tests `((eq ,n-key :allow-other-keys) (setq ,n-allowp ,n-value-temp)))) (tests `(t - (setq ,n-losep ,n-key)))) + (setq ,n-losep (list ,n-key))))) (body `(when (oddp ,n-count) @@ -576,7 +585,7 @@ (unless allowp (body `(when (and ,n-losep (not ,n-allowp)) - (%unknown-key-arg-error ,n-losep))))))) + (%unknown-key-arg-error (car ,n-losep)))))))) (let ((ep (ir1-convert-lambda-body `((let ,(temps) @@ -584,7 +593,7 @@ (%funcall ,(optional-dispatch-main-entry res) ,@(arg-vals)))) (arg-vars) - :debug-name (debug-namify "~S processing" '&more) + :debug-name "&MORE processing" :note-lexical-bindings nil))) (setf (optional-dispatch-more-entry res) (register-entry-point ep res))))) @@ -670,9 +679,8 @@ body (main-vars) :aux-vars (append (bind-vars) aux-vars) :aux-vals (append (bind-vals) aux-vals) - :debug-name (debug-namify "varargs entry for ~A" - (as-debug-name source-name - debug-name)))) + :debug-name (debug-namify + "varargs entry for " source-name debug-name))) (last-entry (convert-optional-entry main-entry default-vars (main-vals) ()))) (setf (optional-dispatch-main-entry res) @@ -740,9 +748,9 @@ :aux-vars aux-vars :aux-vals aux-vals :debug-name (debug-namify - "hairy arg processor for ~A" - (as-debug-name source-name - debug-name))))) + "hairy arg processor for " + source-name + debug-name)))) (setf (optional-dispatch-main-entry res) fun) (register-entry-point fun res) (push (if supplied-p-p @@ -809,7 +817,7 @@ &key (source-name '.anonymous.) (debug-name (debug-namify - "OPTIONAL-DISPATCH ~S" + "OPTIONAL-DISPATCH " vars))) (declare (list body vars aux-vars aux-vals)) (let ((res (make-optional-dispatch :arglist vars @@ -833,8 +841,7 @@ ;;; Convert a LAMBDA form into a LAMBDA leaf or an OPTIONAL-DISPATCH leaf. (defun ir1-convert-lambda (form &key (source-name '.anonymous.) - debug-name - allow-debug-catch-tag) + debug-name) (unless (consp form) (compiler-error "A ~S was found when expecting a lambda expression:~% ~S" @@ -850,34 +857,34 @@ "The lambda expression has a missing or non-list lambda list:~% ~S" form)) - (let ((*allow-debug-catch-tag* (and *allow-debug-catch-tag* allow-debug-catch-tag))) - (multiple-value-bind (vars keyp allow-other-keys aux-vars aux-vals) - (make-lambda-vars (cadr form)) - (multiple-value-bind (forms decls) (parse-body (cddr form)) - (binding* (((*lexenv* result-type) - (process-decls decls (append aux-vars vars) nil)) - (forms (if (and *allow-debug-catch-tag* - (policy *lexenv* (>= insert-debug-catch 2))) - `((catch (make-symbol "SB-DEBUG-CATCH-TAG") - ,@forms)) - forms)) - (forms (if (eq result-type *wild-type*) - forms - `((the ,result-type (progn ,@forms))))) - (res (if (or (find-if #'lambda-var-arg-info vars) keyp) - (ir1-convert-hairy-lambda forms vars keyp - allow-other-keys - aux-vars aux-vals - :source-name source-name - :debug-name debug-name) - (ir1-convert-lambda-body forms vars - :aux-vars aux-vars - :aux-vals aux-vals - :source-name source-name - :debug-name debug-name)))) - (setf (functional-inline-expansion res) form) - (setf (functional-arg-documentation res) (cadr form)) - res))))) + (multiple-value-bind (vars keyp allow-other-keys aux-vars aux-vals) + (make-lambda-vars (cadr form)) + (multiple-value-bind (forms decls) (parse-body (cddr form)) + (binding* (((*lexenv* result-type) + (process-decls decls (append aux-vars vars) nil)) + (forms (if (and *allow-instrumenting* + (policy *lexenv* (>= insert-debug-catch 2))) + `((catch (locally (declare (optimize (insert-step-conditions 0))) + (make-symbol "SB-DEBUG-CATCH-TAG")) + ,@forms)) + forms)) + (forms (if (eq result-type *wild-type*) + forms + `((the ,result-type (progn ,@forms))))) + (res (if (or (find-if #'lambda-var-arg-info vars) keyp) + (ir1-convert-hairy-lambda forms vars keyp + allow-other-keys + aux-vars aux-vals + :source-name source-name + :debug-name debug-name) + (ir1-convert-lambda-body forms vars + :aux-vars aux-vars + :aux-vals aux-vals + :source-name source-name + :debug-name debug-name)))) + (setf (functional-inline-expansion res) form) + (setf (functional-arg-documentation res) (cadr form)) + res)))) ;;; helper for LAMBDA-like things, to massage them into a form ;;; suitable for IR1-CONVERT-LAMBDA. @@ -889,8 +896,8 @@ ;;; 2003-01-25 (defun ir1-convert-lambdalike (thing &rest args &key (source-name '.anonymous.) - debug-name allow-debug-catch-tag) - (declare (ignorable source-name debug-name allow-debug-catch-tag)) + debug-name) + (declare (ignorable source-name debug-name)) (ecase (car thing) ((lambda) (apply #'ir1-convert-lambda thing args)) ((instance-lambda) @@ -927,8 +934,7 @@ ;;; reflect the state at the definition site. (defun ir1-convert-inline-lambda (fun &key (source-name '.anonymous.) - debug-name - allow-debug-catch-tag) + debug-name) (destructuring-bind (decls macros symbol-macros &rest body) (if (eq (car fun) 'lambda-with-lexenv) (cdr fun) @@ -944,8 +950,7 @@ :policy (lexenv-policy *lexenv*)))) (ir1-convert-lambda `(lambda ,@body) :source-name source-name - :debug-name debug-name - :allow-debug-catch-tag nil)))) + :debug-name debug-name)))) ;;; Get a DEFINED-FUN object for a function we are about to define. If ;;; the function has been forward referenced, then substitute for the @@ -1043,18 +1048,20 @@ ;;; ;;; The INLINE-EXPANSION is a LAMBDA-WITH-LEXENV, or NIL if there is ;;; no inline expansion. -(defun %compiler-defun (name lambda-with-lexenv) - +(defun %compiler-defun (name lambda-with-lexenv compile-toplevel) (let ((defined-fun nil)) ; will be set below if we're in the compiler - - (when (boundp '*lexenv*) ; when in the compiler - (when sb!xc:*compile-print* - (compiler-mumble "~&; recognizing DEFUN ~S~%" name)) + (when compile-toplevel + ;; better be in the compiler + (aver (boundp '*lexenv*)) (remhash name *free-funs*) - (setf defined-fun (get-defined-fun name))) + (setf defined-fun (get-defined-fun name)) + (aver (fasl-output-p *compile-object*)) + (if (member name *fun-names-in-this-file* :test #'equal) + (warn 'duplicate-definition :name name) + (push name *fun-names-in-this-file*))) (become-defined-fun-name name) - + (cond (lambda-with-lexenv (setf (info :function :inline-expansion-designator name) lambda-with-lexenv)