- ;; for optionals and keywords args.
- (parse-default (spec info)
- (when (consp (cdr spec))
- (setf (arg-info-default info) (second spec))
- (when (consp (cddr spec))
- (let* ((supplied-p (third spec))
- (supplied-var (varify-lambda-arg supplied-p
- (names-so-far))))
- (setf (arg-info-supplied-p info) supplied-var)
- (names-so-far supplied-p)
- (when (> (length (the list spec)) 3)
- (compiler-error
- "The list ~S is too long to be an arg specifier."
- spec)))))))
-
- (dolist (name required)
- (let ((var (varify-lambda-arg name (names-so-far))))
- (vars var)
- (names-so-far name)))
-
- (dolist (spec optional)
- (if (atom spec)
- (let ((var (varify-lambda-arg spec (names-so-far))))
- (setf (lambda-var-arg-info var)
- (make-arg-info :kind :optional))
- (vars var)
- (names-so-far spec))
- (let* ((name (first spec))
- (var (varify-lambda-arg name (names-so-far)))
- (info (make-arg-info :kind :optional)))
- (setf (lambda-var-arg-info var) info)
- (vars var)
- (names-so-far name)
- (parse-default spec info))))
-
- (when restp
- (let ((var (varify-lambda-arg rest (names-so-far))))
- (setf (lambda-var-arg-info var) (make-arg-info :kind :rest))
- (vars var)
- (names-so-far rest)))
-
- (when morep
- (let ((var (varify-lambda-arg more-context (names-so-far))))
- (setf (lambda-var-arg-info var)
- (make-arg-info :kind :more-context))
- (vars var)
- (names-so-far more-context))
- (let ((var (varify-lambda-arg more-count (names-so-far))))
- (setf (lambda-var-arg-info var)
- (make-arg-info :kind :more-count))
- (vars var)
- (names-so-far more-count)))
-
- (dolist (spec keys)
- (cond
- ((atom spec)
- (let ((var (varify-lambda-arg spec (names-so-far))))
- (setf (lambda-var-arg-info var)
- (make-arg-info :kind :keyword
- :key (make-keyword-for-arg spec
- (vars)
- t)))
- (vars var)
- (names-so-far spec)))
- ((atom (first spec))
- (let* ((name (first spec))
- (var (varify-lambda-arg name (names-so-far)))
- (info (make-arg-info
- :kind :keyword
- :key (make-keyword-for-arg name (vars) t))))
- (setf (lambda-var-arg-info var) info)
- (vars var)
- (names-so-far name)
- (parse-default spec info)))
- (t
- (let ((head (first spec)))
- (unless (proper-list-of-length-p head 2)
- (error "malformed &KEY argument specifier: ~S" spec))
- (let* ((name (second head))
- (var (varify-lambda-arg name (names-so-far)))
- (info (make-arg-info
- :kind :keyword
- :key (make-keyword-for-arg (first head)
- (vars)
- nil))))
- (setf (lambda-var-arg-info var) info)
- (vars var)
- (names-so-far name)
- (parse-default spec info))))))
-
- (dolist (spec aux)
- (cond ((atom spec)
- (let ((var (varify-lambda-arg spec nil)))
- (aux-vars var)
- (aux-vals nil)
- (names-so-far spec)))
- (t
- (unless (proper-list-of-length-p spec 1 2)
- (compiler-error "malformed &AUX binding specifier: ~S"
- spec))
- (let* ((name (first spec))
- (var (varify-lambda-arg name nil)))
- (aux-vars var)
- (aux-vals (second spec))
- (names-so-far name)))))
-
- (values (vars) keyp allowp (aux-vars) (aux-vals))))))
+ ;; for optionals and keywords args.
+ (parse-default (spec info)
+ (when (consp (cdr spec))
+ (setf (arg-info-default info) (second spec))
+ (when (consp (cddr spec))
+ (let* ((supplied-p (third spec))
+ (supplied-var (varify-lambda-arg supplied-p
+ (names-so-far))))
+ (setf (arg-info-supplied-p info) supplied-var)
+ (names-so-far supplied-p)
+ (when (> (length (the list spec)) 3)
+ (compiler-error
+ "The list ~S is too long to be an arg specifier."
+ spec)))))))
+
+ (dolist (name required)
+ (let ((var (varify-lambda-arg name (names-so-far))))
+ (vars var)
+ (names-so-far name)))
+
+ (dolist (spec optional)
+ (if (atom spec)
+ (let ((var (varify-lambda-arg spec (names-so-far))))
+ (setf (lambda-var-arg-info var)
+ (make-arg-info :kind :optional))
+ (vars var)
+ (names-so-far spec))
+ (let* ((name (first spec))
+ (var (varify-lambda-arg name (names-so-far)))
+ (info (make-arg-info :kind :optional)))
+ (setf (lambda-var-arg-info var) info)
+ (vars var)
+ (names-so-far name)
+ (parse-default spec info))))
+
+ (when restp
+ (let ((var (varify-lambda-arg rest (names-so-far))))
+ (setf (lambda-var-arg-info var) (make-arg-info :kind :rest))
+ (vars var)
+ (names-so-far rest)))
+
+ (when morep
+ (let ((var (varify-lambda-arg more-context (names-so-far))))
+ (setf (lambda-var-arg-info var)
+ (make-arg-info :kind :more-context))
+ (vars var)
+ (names-so-far more-context))
+ (let ((var (varify-lambda-arg more-count (names-so-far))))
+ (setf (lambda-var-arg-info var)
+ (make-arg-info :kind :more-count))
+ (vars var)
+ (names-so-far more-count)))
+
+ (dolist (spec keys)
+ (cond
+ ((atom spec)
+ (let ((var (varify-lambda-arg spec (names-so-far))))
+ (setf (lambda-var-arg-info var)
+ (make-arg-info :kind :keyword
+ :key (make-keyword-for-arg spec
+ (vars)
+ t)))
+ (vars var)
+ (names-so-far spec)))
+ ((atom (first spec))
+ (let* ((name (first spec))
+ (var (varify-lambda-arg name (names-so-far)))
+ (info (make-arg-info
+ :kind :keyword
+ :key (make-keyword-for-arg name (vars) t))))
+ (setf (lambda-var-arg-info var) info)
+ (vars var)
+ (names-so-far name)
+ (parse-default spec info)))
+ (t
+ (let ((head (first spec)))
+ (unless (proper-list-of-length-p head 2)
+ (error "malformed &KEY argument specifier: ~S" spec))
+ (let* ((name (second head))
+ (var (varify-lambda-arg name (names-so-far)))
+ (info (make-arg-info
+ :kind :keyword
+ :key (make-keyword-for-arg (first head)
+ (vars)
+ nil))))
+ (setf (lambda-var-arg-info var) info)
+ (vars var)
+ (names-so-far name)
+ (parse-default spec info))))))
+
+ (dolist (spec aux)
+ (cond ((atom spec)
+ (let ((var (varify-lambda-arg spec nil)))
+ (aux-vars var)
+ (aux-vals nil)
+ (names-so-far spec)))
+ (t
+ (unless (proper-list-of-length-p spec 1 2)
+ (compiler-error "malformed &AUX binding specifier: ~S"
+ spec))
+ (let* ((name (first spec))
+ (var (varify-lambda-arg name nil)))
+ (aux-vars var)
+ (aux-vals (second spec))
+ (names-so-far name)))))
+
+ (values (vars) keyp allowp (aux-vars) (aux-vals))))))
- (ep (if supplied-p
- (ir1-convert-hairy-args
- res
- (list* supplied-p arg default-vars)
- (list* (leaf-source-name supplied-p) arg-name default-vals)
- (cons arg entry-vars)
- (list* t arg-name entry-vals)
- (rest vars) t body aux-vars aux-vals
- source-name debug-name
- force)
- (ir1-convert-hairy-args
- res
- (cons arg default-vars)
- (cons arg-name default-vals)
- (cons arg entry-vars)
- (cons arg-name entry-vals)
- (rest vars) supplied-p-p body aux-vars aux-vals
- source-name debug-name
- force))))
+ (ep (if supplied-p
+ (ir1-convert-hairy-args
+ res
+ (list* supplied-p arg default-vars)
+ (list* (leaf-source-name supplied-p) arg-name default-vals)
+ (cons arg entry-vars)
+ (list* t arg-name entry-vals)
+ (rest vars) t body aux-vars aux-vals
+ source-name debug-name
+ force post-binding-lexenv)
+ (ir1-convert-hairy-args
+ res
+ (cons arg default-vars)
+ (cons arg-name default-vals)
+ (cons arg entry-vars)
+ (cons arg-name entry-vals)
+ (rest vars) supplied-p-p body aux-vars aux-vals
+ source-name debug-name
+ force post-binding-lexenv))))
- (if (or force
- supplied-p-p ; this entry will be of kind NIL
- (and (lambda-p ep) (eq (lambda-kind ep) nil)))
- (convert-optional-entry ep
- default-vars default-vals
- (if supplied-p
- (list default nil)
- (list default)))
- (delay
- (register-entry-point
- (convert-optional-entry (force ep)
- default-vars default-vals
- (if supplied-p
- (list default nil)
- (list default)))
- res)))))
+ (let ((name (or debug-name source-name)))
+ (if (or force
+ supplied-p-p ; this entry will be of kind NIL
+ (and (lambda-p ep) (eq (lambda-kind ep) nil)))
+ (convert-optional-entry ep
+ default-vars default-vals
+ (if supplied-p (list default nil) (list default))
+ name)
+ (let* ((default `',(constant-form-value default))
+ (defaults (if supplied-p (list default nil) (list default))))
+ ;; DEFAULT can contain a reference to a
+ ;; to-be-optimized-away function/block/tag, so better to
+ ;; reduce code now (but we possibly lose syntax checking
+ ;; in an unreachable code).
+ (delay
+ (register-entry-point
+ (convert-optional-entry (force ep)
+ default-vars default-vals
+ defaults
+ name)
+ res)))))))
- (temps `(,n-index (1- ,n-count)) n-key n-value-temp)
- (body `(declare (fixnum ,n-index) (ignorable ,n-key ,n-value-temp)))
-
- (collect ((tests))
- (dolist (key keys)
- (let* ((info (lambda-var-arg-info key))
- (default (arg-info-default info))
- (keyword (arg-info-key info))
- (supplied-p (arg-info-supplied-p info))
- (n-value (gensym "N-VALUE-"))
+ (temps #!-stack-grows-downward-not-upward
+ `(,n-index (1- ,n-count))
+ #!+stack-grows-downward-not-upward
+ `(,n-index (- (1- ,n-count)))
+ #!-stack-grows-downward-not-upward n-value-temp
+ #!-stack-grows-downward-not-upward n-key)
+ (body `(declare (fixnum ,n-index)
+ #!-stack-grows-downward-not-upward
+ (ignorable ,n-value-temp ,n-key)))
+
+ (collect ((tests))
+ (dolist (key keys)
+ (let* ((info (lambda-var-arg-info key))
+ (default (arg-info-default info))
+ (keyword (arg-info-key info))
+ (supplied-p (arg-info-supplied-p info))
+ (n-value (gensym "N-VALUE-"))
- (tests `(t
- (setq ,n-losep (list ,n-key)))))
-
- (body
- `(when (oddp ,n-count)
- (%odd-key-args-error)))
-
- (body
- `(locally
- (declare (optimize (safety 0)))
- (loop
- (when (minusp ,n-index) (return))
- (setf ,n-value-temp (%more-arg ,n-context ,n-index))
- (decf ,n-index)
- (setq ,n-key (%more-arg ,n-context ,n-index))
- (decf ,n-index)
- (cond ,@(tests)))))
-
- (unless allowp
- (body `(when (and ,n-losep (not ,n-allowp))
- (%unknown-key-arg-error (car ,n-losep))))))))
+ (tests `(t
+ (setq ,n-losep (list ,n-key)))))
+
+ (body
+ `(when (oddp ,n-count)
+ (%odd-key-args-error)))
+
+ (body
+ #!-stack-grows-downward-not-upward
+ `(locally
+ (declare (optimize (safety 0)))
+ (loop
+ (when (minusp ,n-index) (return))
+ (setf ,n-value-temp (%more-arg ,n-context ,n-index))
+ (decf ,n-index)
+ (setq ,n-key (%more-arg ,n-context ,n-index))
+ (decf ,n-index)
+ (cond ,@(tests))))
+ #!+stack-grows-downward-not-upward
+ `(locally (declare (optimize (safety 0)))
+ (loop
+ (when (plusp ,n-index) (return))
+ (multiple-value-bind (,n-value-temp ,n-key)
+ (%more-kw-arg ,n-context ,n-index)
+ (declare (ignorable ,n-value-temp ,n-key))
+ (incf ,n-index 2)
+ (cond ,@(tests))))))
+
+ (unless allowp
+ (body `(when (and ,n-losep (not ,n-allowp))
+ (%unknown-key-arg-error (car ,n-losep))))))))
- (default (arg-info-default info))
- (hairy-default (not (sb!xc:constantp default)))
- (supplied-p (arg-info-supplied-p info))
- (n-val (make-symbol (format nil
- "~A-DEFAULTING-TEMP"
- (leaf-source-name key))))
- (key-type (leaf-type key))
- (val-temp (make-lambda-var
- :%source-name n-val
- :type (if hairy-default
- (type-union key-type (specifier-type 'null))
- key-type))))
- (main-vars val-temp)
- (bind-vars key)
- (cond ((or hairy-default supplied-p)
- (let* ((n-supplied (gensym "N-SUPPLIED-"))
- (supplied-temp (make-lambda-var
- :%source-name n-supplied)))
- (unless supplied-p
- (setf (arg-info-supplied-p info) supplied-temp))
- (when hairy-default
- (setf (arg-info-default info) nil))
- (main-vars supplied-temp)
- (cond (hairy-default
- (main-vals nil nil)
- (bind-vals `(if ,n-supplied ,n-val ,default)))
- (t
- (main-vals default nil)
- (bind-vals n-val)))
- (when supplied-p
- (bind-vars supplied-p)
- (bind-vals n-supplied))))
- (t
- (main-vals (arg-info-default info))
- (bind-vals n-val)))))
-
- (let* ((main-entry (ir1-convert-lambda-body
- body (main-vars)
- :aux-vars (append (bind-vars) aux-vars)
- :aux-vals (append (bind-vals) aux-vals)
- :debug-name (debug-namify
- "varargs entry for " source-name debug-name)))
- (last-entry (convert-optional-entry main-entry default-vars
- (main-vals) ())))
+ (default (arg-info-default info))
+ (hairy-default (not (sb!xc:constantp default)))
+ (supplied-p (arg-info-supplied-p info))
+ (n-val (make-symbol (format nil
+ "~A-DEFAULTING-TEMP"
+ (leaf-source-name key))))
+ (val-temp (make-lambda-var :%source-name n-val)))
+ (main-vars val-temp)
+ (bind-vars key)
+ (cond ((or hairy-default supplied-p)
+ (let* ((n-supplied (gensym "N-SUPPLIED-"))
+ (supplied-temp (make-lambda-var
+ :%source-name n-supplied)))
+ (unless supplied-p
+ (setf (arg-info-supplied-p info) supplied-temp))
+ (when hairy-default
+ (setf (arg-info-default info) nil))
+ (main-vars supplied-temp)
+ (cond (hairy-default
+ (main-vals nil nil)
+ (bind-vals `(if ,n-supplied ,n-val ,default)))
+ (t
+ (main-vals default nil)
+ (bind-vals n-val)))
+ (when supplied-p
+ (bind-vars supplied-p)
+ (bind-vals n-supplied))))
+ (t
+ (main-vals (arg-info-default info))
+ (bind-vals n-val)))))
+
+ (let* ((name (or debug-name source-name))
+ (main-entry (ir1-convert-lambda-body
+ body (main-vars)
+ :aux-vars (append (bind-vars) aux-vars)
+ :aux-vals (append (bind-vals) aux-vals)
+ :post-binding-lexenv post-binding-lexenv
+ :debug-name (debug-name 'varargs-entry name)))
+ (last-entry (convert-optional-entry main-entry default-vars
+ (main-vals) () name)))
+(defun wrap-forms-in-debug-catch (forms)
+ #!+unwind-to-frame-and-call-vop
+ `((multiple-value-prog1
+ (progn
+ ,@forms)
+ ;; Just ensure that there won't be any tail-calls, IR2 magic will
+ ;; handle the rest.
+ (values)))
+ #!-unwind-to-frame-and-call-vop
+ `( ;; Normally, we'll return from this block with the below RETURN-FROM.
+ (block
+ return-value-tag
+ ;; If DEBUG-CATCH-TAG is thrown (with a thunk as the value) the
+ ;; RETURN-FROM is elided and we funcall the thunk instead. That
+ ;; thunk might either return a value (for a RETURN-FROM-FRAME)
+ ;; or call this same function again (for a RESTART-FRAME).
+ ;; -- JES, 2007-01-09
+ (funcall
+ (the function
+ ;; Use a constant catch tag instead of consing a new one for every
+ ;; entry to this block. The uniquencess of the catch tags is
+ ;; ensured when the tag is throw by the debugger. It'll allocate a
+ ;; new tag, and modify the reference this tag in the proper
+ ;; catch-block structure to refer to that new tag. This
+ ;; significantly decreases the runtime cost of high debug levels.
+ ;; -- JES, 2007-01-09
+ (catch 'debug-catch-tag
+ (return-from return-value-tag
+ (progn
+ ,@forms))))))))
+
- (aver (not (info :function :inlinep name)))
- (let* ((where-from (leaf-where-from found))
- (res (make-defined-fun
- :%source-name name
- :where-from (if (eq where-from :declared)
- :declared :defined)
- :type (leaf-type found))))
- (substitute-leaf res found)
- (setf (gethash name *free-funs*) res)))
- ;; If *FREE-FUNS* has a previously converted definition
- ;; for this name, then blow it away and try again.
- ((defined-fun-functional found)
- (remhash name *free-funs*)
- (get-defined-fun name))
- (t found))))
+ (aver (not (info :function :inlinep name)))
+ (let* ((where-from (leaf-where-from found))
+ (res (make-defined-fun
+ :%source-name name
+ :where-from (if (eq where-from :declared)
+ :declared :defined)
+ :type (leaf-type found))))
+ (substitute-leaf res found)
+ (setf (gethash name *free-funs*) res)))
+ ;; If *FREE-FUNS* has a previously converted definition
+ ;; for this name, then blow it away and try again.
+ ((defined-fun-functional found)
+ (remhash name *free-funs*)
+ (get-defined-fun name))
+ (t found))))
- "previous declaration"
- "previous definition"))))
-
-;;; Convert a lambda doing all the basic stuff we would do if we were
-;;; converting a DEFUN. In the old CMU CL system, this was used both
-;;; by the %DEFUN translator and for global inline expansion, but
-;;; since sbcl-0.pre7.something %DEFUN does things differently.
-;;; FIXME: And now it's probably worth rethinking whether this
-;;; function is a good idea.
-;;;
-;;; Unless a :INLINE function, we temporarily clobber the inline
-;;; expansion. This prevents recursive inline expansion of
-;;; opportunistic pseudo-inlines.
-(defun ir1-convert-lambda-for-defun (lambda var expansion converter)
- (declare (cons lambda) (function converter) (type defined-fun var))
- (let ((var-expansion (defined-fun-inline-expansion var)))
- (unless (eq (defined-fun-inlinep var) :inline)
- (setf (defined-fun-inline-expansion var) nil))
- (let* ((name (leaf-source-name var))
- (fun (funcall converter lambda
- :source-name name))
- (fun-info (info :function :info name)))
- (setf (functional-inlinep fun) (defined-fun-inlinep var))
- (assert-new-definition var fun)
- (setf (defined-fun-inline-expansion var) var-expansion)
- ;; If definitely not an interpreter stub, then substitute for
- ;; any old references.
- (unless (or (eq (defined-fun-inlinep var) :notinline)
- (not *block-compile*)
- (and fun-info
- (or (fun-info-transforms fun-info)
- (fun-info-templates fun-info)
- (fun-info-ir2-convert fun-info))))
- (substitute-leaf fun var)
- ;; If in a simple environment, then we can allow backward
- ;; references to this function from following top level forms.
- (when expansion (setf (defined-fun-functional var) fun)))
- fun)))
+ "previous declaration"
+ "previous definition"))))
+
+;;; Used for global inline expansion. Earlier something like this was
+;;; used by %DEFUN too. FIXME: And now it's probably worth rethinking
+;;; whether this function is a good idea at all.
+(defun ir1-convert-inline-expansion (name expansion var inlinep info)
+ ;; Unless a :INLINE function, we temporarily clobber the inline
+ ;; expansion. This prevents recursive inline expansion of
+ ;; opportunistic pseudo-inlines.
+ (unless (eq inlinep :inline)
+ (setf (defined-fun-inline-expansion var) nil))
+ (let ((fun (ir1-convert-inline-lambda expansion
+ :source-name name
+ ;; prevent instrumentation of
+ ;; known function expansions
+ :system-lambda (and info t))))
+ (setf (functional-inlinep fun) inlinep)
+ (assert-new-definition var fun)
+ (setf (defined-fun-inline-expansion var) expansion)
+ ;; substitute for any old references
+ (unless (or (not *block-compile*)
+ (and info
+ (or (fun-info-transforms info)
+ (fun-info-templates info)
+ (fun-info-ir2-convert info))))
+ (substitute-leaf fun var))
+ fun))