destructure: improve context handling
authorDaniel Kochmański <daniel@turtleware.eu>
Wed, 19 Aug 2015 14:02:38 +0000 (16:02 +0200)
committerDaniel Kochmański <daniel@turtleware.eu>
Wed, 19 Aug 2015 14:33:48 +0000 (16:33 +0200)
Add handling of arbitrary context as case clause

Signed-off-by: Daniel Kochmański <daniel@turtleware.eu>
src/lsp/defmacro.lsp
src/lsp/predlib.lsp

index f80fb64..08629df 100644 (file)
                *current-form*))
       (error "Too few arguments supplied to a inlined lambda form.")))
 
-(defun sys::destructure (vl macro &aux (basis-form (gensym)) (destructure-symbols (list basis-form)))
+(defun sys::destructure (vl context &aux
+                                      (basis-form (gensym))
+                                      (destructure-symbols (list basis-form)))
   (declare (special *dl* *arg-check*))
   (labels ((tempsym ()
              (let ((x (gensym)))
                (push x destructure-symbols)
                x))
-           (dm-vl (vl whole macro)
+           (dm-vl (vl whole context)
              (multiple-value-bind (reqs opts rest key-flag keys allow-other-keys auxs)
-                 (si::process-lambda-list vl (if macro 'macro 'destructuring-bind))
+                 (si::process-lambda-list
+                  vl (case context
+                       ((defmacro define-compiler-macro)
+                        'macro)
+                       (otherwise 'destructuring-bind)))
                (let* ((pointer (tempsym))
                       (cons-pointer `(truly-the cons ,pointer))
                       (unsafe-car `(car ,cons-pointer))
                       (ppn (+ (length reqs) (first opts)))
                       all-keywords)
                  ;; In macros, eliminate the name of the macro from the list
-                 (dm-v pointer (if macro
-                                   ;; Special handling if define-compiler-macro called this
-                                   (if (eq macro 'define-compiler-macro)
-                                       `(if (and (eq (car ,whole) 'cl:funcall)
-                                                 (eq (caadr ,whole) 'cl:function))
-                                             (cddr (truly-the cons ,whole))
-                                             (cdr (truly-the cons ,whole)))
-                                       `(cdr (truly-the cons ,whole)))
-                                   whole))
+                 (dm-v pointer (case context
+                                 (define-compiler-macro
+                                  `(if (and (eq (car ,whole) 'cl:funcall)
+                                            (eq (caadr ,whole) 'cl:function))
+                                       (cddr (truly-the cons ,whole))
+                                       (cdr (truly-the cons ,whole))))
+                                 (defmacro
+                                     `(cdr (truly-the cons ,whole)))
+                                 (otherwise whole)))
                  (dolist (v (cdr reqs))
                    (dm-v v `(progn
                               (if (null ,pointer)
             ((symbolp vl)
              (setq vl (list '&rest vl)))
             (t (error "The destructuring-lambda-list ~s is not a list." vl)))
-      (values (dm-vl vl whole macro) whole
+      (values (dm-vl vl whole context) whole
               (nreverse *dl*)
               *arg-check*
               destructure-symbols))))
index 27c817e..4584d0b 100644 (file)
@@ -106,7 +106,7 @@ retrieved by (documentation 'NAME 'type)."
   (multiple-value-bind (decls body documentation)
       (si::find-declarations body)
     (multiple-value-bind (ppn whole dl arg-check ignorables)
-        (destructure lambda-list nil)
+        (destructure lambda-list 'deftype)
       (declare (ignore ppn))
       (let ((function `#'(ext::lambda-block ,name (,whole &aux ,@dl)
                                             (declare (ignorable ,@ignorables))