/[cmucl]/src/code/macros.lisp
ViewVC logotype

Contents of /src/code/macros.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.35.1.3 - (hide annotations) (vendor branch)
Fri Feb 26 17:29:59 1993 UTC (21 years, 2 months ago) by ram
Branch: new_struct
Changes since 1.35.1.2: +14 -10 lines
Global setf macros aren't applied to local macro calls with the same name,
but local macros are expanded to see if they contain setfable forms.
1 ram 1.1 ;;; -*- Log: code.log; Package: Lisp -*-
2     ;;;
3     ;;; **********************************************************************
4 ram 1.20 ;;; This code was written as part of the CMU Common Lisp project at
5     ;;; Carnegie Mellon University, and has been placed in the public domain.
6     ;;; If you want to use this code or any part of CMU Common Lisp, please contact
7     ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
8     ;;;
9     (ext:file-comment
10 ram 1.35.1.3 "$Header: /tiger/var/lib/cvsroots/cmucl/src/code/macros.lisp,v 1.35.1.3 1993/02/26 17:29:59 ram Exp $")
11 ram 1.20 ;;;
12 ram 1.1 ;;; **********************************************************************
13     ;;;
14     ;;; This file contains the macros that are part of the standard
15     ;;; Spice Lisp environment.
16     ;;;
17     ;;; Written by Scott Fahlman and Rob MacLachlan.
18 ram 1.22 ;;; Modified by Bill Chiles to adhere to the wall.
19 ram 1.1 ;;;
20 wlott 1.10 (in-package "LISP")
21 wlott 1.13 (export '(defvar defparameter defconstant when unless setf
22 ram 1.1 defsetf define-setf-method psetf shiftf rotatef push pushnew pop
23     incf decf remf case typecase with-open-file
24     with-open-stream with-input-from-string with-output-to-string
25     locally etypecase ctypecase ecase ccase
26     get-setf-method get-setf-method-multiple-value
27 ram 1.18 define-modify-macro destructuring-bind nth-value
28 wlott 1.33 otherwise ; Sacred to CASE and related macros.
29     define-compiler-macro))
30 ram 1.1
31     (in-package "EXTENSIONS")
32     (export '(do-anonymous collect iterate))
33    
34     (in-package "LISP")
35    
36    
37     ;;; Parse-Body -- Public
38     ;;;
39     ;;; Parse out declarations and doc strings, *not* expanding macros.
40     ;;; Eventually the environment arg should be flushed, since macros can't expand
41     ;;; into declarations anymore.
42     ;;;
43     (defun parse-body (body environment &optional (doc-string-allowed t))
44     "This function is to parse the declarations and doc-string out of the body of
45     a defun-like form. Body is the list of stuff which is to be parsed.
46     Environment is ignored. If Doc-String-Allowed is true, then a doc string
47     will be parsed out of the body and returned. If it is false then a string
48     will terminate the search for declarations. Three values are returned: the
49     tail of Body after the declarations and doc strings, a list of declare forms,
50     and the doc-string, or NIL if none."
51     (declare (ignore environment))
52     (let ((decls ())
53     (doc nil))
54     (do ((tail body (cdr tail)))
55     ((endp tail)
56     (values tail (nreverse decls) doc))
57     (let ((form (car tail)))
58     (cond ((and (stringp form) (cdr tail))
59     (if doc-string-allowed
60     (setq doc form)
61     (return (values tail (nreverse decls) doc))))
62     ((not (and (consp form) (symbolp (car form))))
63     (return (values tail (nreverse decls) doc)))
64     ((eq (car form) 'declare)
65     (push form decls))
66     (t
67     (return (values tail (nreverse decls) doc))))))))
68    
69    
70     ;;;; DEFMACRO:
71    
72     ;;; Defmacro -- Public
73     ;;;
74     ;;; Parse the definition and make an expander function. The actual
75     ;;; definition is done by %defmacro which we expand into.
76     ;;;
77     (defmacro defmacro (name lambda-list &body body)
78 wlott 1.13 (let ((whole (gensym "WHOLE-"))
79     (environment (gensym "ENV-")))
80 ram 1.1 (multiple-value-bind
81     (body local-decs doc)
82 wlott 1.13 (parse-defmacro lambda-list whole body name 'defmacro
83     :environment environment)
84 ram 1.1 (let ((def `(lambda (,whole ,environment)
85     ,@local-decs
86     (block ,name
87     ,body))))
88 wlott 1.13 `(c::%defmacro ',name #',def ',lambda-list ,doc)))))
89 ram 1.1
90    
91     ;;; %Defmacro, %%Defmacro -- Internal
92     ;;;
93     ;;; Defmacro expands into %Defmacro which is a function that is treated
94     ;;; magically the compiler. After the compiler has gotten the information it
95     ;;; wants out of macro definition, it compiles a call to %%Defmacro which
96     ;;; happens at load time. We have a %Defmacro function which just calls
97     ;;; %%Defmacro in order to keep the interpreter happy.
98     ;;;
99     ;;; Eventually %%Defmacro should deal with clearing old compiler information
100     ;;; for the functional value.
101     ;;;
102     (defun c::%defmacro (name definition lambda-list doc)
103 wlott 1.13 (assert (eval:interpreted-function-p definition))
104     (setf (eval:interpreted-function-name definition)
105     (format nil "DEFMACRO ~S" name))
106     (setf (eval:interpreted-function-arglist definition) lambda-list)
107 ram 1.1 (c::%%defmacro name definition doc))
108     ;;;
109     (defun c::%%defmacro (name definition doc)
110     (clear-info function where-from name)
111 wlott 1.10 (setf (macro-function name) definition)
112 ram 1.1 (setf (documentation name 'function) doc)
113     name)
114 wlott 1.33
115    
116    
117     ;;;; DEFINE-COMPILER-MACRO
118    
119     (defmacro define-compiler-macro (name lambda-list &body body)
120     "Define a compiler-macro for NAME."
121     (let ((whole (gensym "WHOLE-"))
122     (environment (gensym "ENV-")))
123     (multiple-value-bind
124     (body local-decs doc)
125     (parse-defmacro lambda-list whole body name 'define-compiler-macro
126     :environment environment)
127     (let ((def `(lambda (,whole ,environment)
128     ,@local-decs
129     (block ,name
130     ,body))))
131     `(c::%define-compiler-macro ',name #',def ',lambda-list ,doc)))))
132    
133     (defun c::%define-compiler-macro (name definition lambda-list doc)
134     (assert (eval:interpreted-function-p definition))
135     (setf (eval:interpreted-function-name definition)
136     (let ((*print-case* :upcase))
137     (format nil "DEFINE-COMPILER-MACRO ~S" name)))
138     (setf (eval:interpreted-function-arglist definition) lambda-list)
139     (c::%%define-compiler-macro name definition doc))
140     ;;;
141     (defun c::%%define-compiler-macro (name definition doc)
142     (setf (compiler-macro-function name) definition)
143     (setf (documentation name 'compiler-macro) doc)
144     name)
145    
146 ram 1.1
147    
148     ;;; DEFTYPE is a lot like DEFMACRO.
149    
150     (defmacro deftype (name arglist &body body)
151     "Syntax like DEFMACRO, but defines a new type."
152     (unless (symbolp name)
153     (error "~S -- Type name not a symbol." name))
154    
155 wlott 1.13 (let ((whole (gensym "WHOLE-")))
156 ram 1.1 (multiple-value-bind (body local-decs doc)
157 wlott 1.13 (parse-defmacro arglist whole body name 'deftype
158     :default-default ''*)
159     `(eval-when (compile load eval)
160     (%deftype ',name
161     #'(lambda (,whole)
162     ,@local-decs
163     (block ,name ,body))
164     ,@(when doc `(,doc)))))))
165 ram 1.7 ;;;
166     (defun %deftype (name expander &optional doc)
167 ram 1.12 (ecase (info type kind name)
168     (:primitive
169 ram 1.35.1.1 (when *type-system-initialized*
170     (error "Illegal to redefine standard type: ~S." name)))
171     #+ns-boot
172 ram 1.12 (:structure
173     (warn "Redefining structure type ~S with DEFTYPE." name)
174 ram 1.35.1.1 (c::undefine-structure (info type structure-info name))
175     (setf (info type kind name) :defined))
176     (:instance
177     (warn "Redefining class ~S to be a DEFTYPE." name)
178     (undefine-structure (layout-info (class-layout (info type class name))))
179     (setf (info type class name) nil)
180     (setf (info type compiler-layout name) nil)
181     (setf (info type kind name) :defined))
182     (:defined)
183     ((nil)
184     (setf (info type kind name) :defined)))
185    
186 wlott 1.13 (setf (info type expander name) expander)
187 ram 1.7 (when doc
188     (setf (documentation name 'type) doc))
189 wlott 1.10 ;; ### Bootstrap hack -- we need to define types before %note-type-defined
190     ;; is defined.
191 ram 1.12 (when (fboundp 'c::%note-type-defined)
192 wlott 1.10 (c::%note-type-defined name))
193 ram 1.7 name)
194    
195 ram 1.1
196     ;;; And so is DEFINE-SETF-METHOD.
197    
198     (defparameter defsetf-error-string "Setf expander for ~S cannot be called with ~S args.")
199    
200     (defmacro define-setf-method (access-fn lambda-list &body body)
201     "Syntax like DEFMACRO, but creates a Setf-Method generator. The body
202     must be a form that returns the five magical values."
203     (unless (symbolp access-fn)
204     (error "~S -- Access-function name not a symbol in DEFINE-SETF-METHOD."
205     access-fn))
206    
207 wlott 1.13 (let ((whole (gensym "WHOLE-"))
208     (environment (gensym "ENV-")))
209 ram 1.1 (multiple-value-bind (body local-decs doc)
210     (parse-defmacro lambda-list whole body access-fn
211 wlott 1.13 'define-setf-method
212     :environment environment)
213 ram 1.1 `(eval-when (load compile eval)
214 ram 1.22 (%define-setf-macro
215     ',access-fn
216     #'(lambda (,whole ,environment)
217     ,@local-decs
218     (block ,access-fn ,body))
219     nil
220     ',doc)))))
221 ram 1.1
222 ram 1.22
223     ;;; %DEFINE-SETF-MACRO -- Internal
224     ;;;
225     ;;; Do stuff for defining a setf macro.
226     ;;;
227     (defun %define-setf-macro (name expander inverse doc)
228     (cond ((not (fboundp `(setf ,name))))
229     ((info function accessor-for name)
230     (warn "Defining setf macro for destruct slot accessor; redefining as ~
231     a normal function:~% ~S"
232     name)
233     (c::define-function-name name))
234     ((not (eq (symbol-package name) (symbol-package 'aref)))
235     (warn "Defining setf macro for ~S, but ~S is fbound."
236     name `(setf ,name))))
237     (when (or inverse (info setf inverse name))
238     (setf (info setf inverse name) inverse))
239     (when (or expander (info setf expander name))
240     (setf (info setf expander name) expander))
241     (when doc
242     (setf (documentation name 'setf) doc))
243     name)
244    
245 wlott 1.13
246     ;;;; Destructuring-bind
247 ram 1.1
248 wlott 1.13 (defmacro destructuring-bind (lambda-list arg-list &rest body)
249     "Bind the variables in LAMBDA-LIST to the contents of ARG-LIST."
250     (let* ((arg-list-name (gensym "ARG-LIST-")))
251     (multiple-value-bind
252 wlott 1.14 (body local-decls)
253 wlott 1.17 (parse-defmacro lambda-list arg-list-name body nil 'destructuring-bind
254 wlott 1.13 :annonymousp t :doc-string-allowed nil)
255     `(let ((,arg-list-name ,arg-list))
256 wlott 1.14 ,@local-decls
257 wlott 1.13 ,body))))
258    
259 ram 1.1
260     ;;;; Defun, Defvar, Defparameter, Defconstant:
261    
262     ;;; Defun -- Public
263     ;;;
264     ;;; Very similar to Defmacro, but simpler. We don't have to parse the
265     ;;; lambda-list.
266     ;;;
267 wlott 1.13 (defmacro defun (&whole source name lambda-list &body (body decls doc))
268 ram 1.1 (let ((def `(lambda ,lambda-list
269     ,@decls
270     (block ,(if (and (consp name) (eq (car name) 'setf))
271     (cadr name)
272     name)
273     ,@body))))
274     `(c::%defun ',name #',def ,doc ',source)))
275    
276    
277     ;;; %Defun, %%Defun -- Internal
278     ;;;
279     ;;; Similar to %Defmacro, ...
280     ;;;
281     (defun c::%%defun (name def doc &optional inline-expansion)
282     (setf (fdefinition name) def)
283     (when doc
284     (if (and (consp name) (eq (first name) 'setf))
285     (setf (documentation (second name) 'setf) doc)
286     (setf (documentation name 'function) doc)))
287 ram 1.12 (c::define-function-name name)
288     (when (eq (info function where-from name) :assumed)
289     (setf (info function where-from name) :defined)
290     (when (info function assumed-type name)
291     (setf (info function assumed-type name) nil)))
292 ram 1.1 (when (or inline-expansion
293     (info function inline-expansion name))
294     (setf (info function inline-expansion name) inline-expansion))
295     name)
296     ;;;
297     (defun c::%defun (name def doc source)
298     (declare (ignore source))
299 ram 1.3 (assert (eval:interpreted-function-p def))
300     (setf (eval:interpreted-function-name def) name)
301 ram 1.1 (c::%%defun name def doc))
302    
303    
304     ;;; DEFCONSTANT -- Public
305     ;;;
306     (defmacro defconstant (var val &optional doc)
307     "For defining global constants at top level. The DEFCONSTANT says that the
308     value is constant and may be compiled into code. If the variable already has
309     a value, and this is not equal to the init, an error is signalled. The third
310     argument is an optional documentation string for the variable."
311     `(c::%defconstant ',var ,val ',doc))
312    
313     ;;; %Defconstant, %%Defconstant -- Internal
314     ;;;
315     ;;; Like the other %mumbles except that we currently actually do something
316     ;;; interesting at load time, namely checking if the constant is being
317     ;;; redefined.
318     ;;;
319     (defun c::%defconstant (name value doc)
320     (c::%%defconstant name value doc))
321     ;;;
322     (defun c::%%defconstant (name value doc)
323     (when doc
324     (setf (documentation name 'variable) doc))
325     (when (boundp name)
326     (unless (equalp (symbol-value name) value)
327     (cerror "Go ahead and change the value."
328     "Constant ~S being redefined." name)))
329     (setf (symbol-value name) value)
330     (setf (info variable kind name) :constant)
331     (clear-info variable constant-value name)
332     name)
333    
334    
335     (defmacro defvar (var &optional (val nil valp) (doc nil docp))
336     "For defining global variables at top level. Declares the variable
337     SPECIAL and, optionally, initializes it. If the variable already has a
338     value, the old value is not clobbered. The third argument is an optional
339     documentation string for the variable."
340     `(progn
341     (proclaim '(special ,var))
342     ,@(when valp
343     `((unless (boundp ',var)
344     (setq ,var ,val))))
345     ,@(when docp
346     `((setf (documentation ',var 'variable) ',doc)))
347     ',var))
348    
349     (defmacro defparameter (var val &optional (doc nil docp))
350     "Defines a parameter that is not normally changed by the program,
351     but that may be changed without causing an error. Declares the
352     variable special and sets its value to VAL. The third argument is
353     an optional documentation string for the parameter."
354     `(progn
355     (proclaim '(special ,var))
356     (setq ,var ,val)
357     ,@(when docp
358     `((setf (documentation ',var 'variable) ',doc)))
359     ',var))
360    
361    
362     ;;;; ASSORTED CONTROL STRUCTURES
363    
364    
365     (defmacro when (test &body forms)
366     "First arg is a predicate. If it is non-null, the rest of the forms are
367     evaluated as a PROGN."
368     `(cond (,test nil ,@forms)))
369    
370     (defmacro unless (test &rest forms)
371     "First arg is a predicate. If it is null, the rest of the forms are
372     evaluated as a PROGN."
373     `(cond ((not ,test) nil ,@forms)))
374    
375    
376     (defmacro return (&optional (value nil))
377     `(return-from nil ,value))
378    
379     (defmacro prog (varlist &body (body decls))
380     `(block nil
381     (let ,varlist
382     ,@decls
383     (tagbody ,@body))))
384    
385     (defmacro prog* (varlist &body (body decls))
386     `(block nil
387     (let* ,varlist
388     ,@decls
389     (tagbody ,@body))))
390    
391    
392     ;;; Prog1, Prog2 -- Public
393     ;;;
394     ;;; These just turn into a Let.
395     ;;;
396     (defmacro prog1 (result &rest body)
397     (let ((n-result (gensym)))
398     `(let ((,n-result ,result))
399     ,@body
400     ,n-result)))
401     ;;;
402     (defmacro prog2 (form1 result &rest body)
403     `(prog1 (progn ,form1 ,result) ,@body))
404    
405    
406     ;;; And, Or -- Public
407     ;;;
408     ;;; AND and OR are defined in terms of IF.
409     ;;;
410     (defmacro and (&rest forms)
411     (cond ((endp forms) t)
412     ((endp (rest forms)) (first forms))
413     (t
414     `(if ,(first forms)
415     (and ,@(rest forms))
416     nil))))
417     ;;;
418     (defmacro or (&rest forms)
419     (cond ((endp forms) nil)
420     ((endp (rest forms)) (first forms))
421     (t
422     (let ((n-result (gensym)))
423     `(let ((,n-result ,(first forms)))
424     (if ,n-result
425     ,n-result
426     (or ,@(rest forms))))))))
427    
428    
429     ;;; Cond -- Public
430     ;;;
431     ;;; COND also turns into IF.
432     ;;;
433     (defmacro cond (&rest clauses)
434     (if (endp clauses)
435     nil
436     (let ((clause (first clauses)))
437     (when (atom clause)
438     (error "Cond clause is not a list: ~S." clause))
439     (let ((test (first clause))
440     (forms (rest clause)))
441     (if (endp forms)
442     (let ((n-result (gensym)))
443     `(let ((,n-result ,test))
444     (if ,n-result
445     ,n-result
446     (cond ,@(rest clauses)))))
447     `(if ,test
448     (progn ,@forms)
449     (cond ,@(rest clauses))))))))
450    
451    
452     ;;;; Multiple value macros:
453    
454     ;;; Multiple-Value-XXX -- Public
455     ;;;
456     ;;; All the multiple-value receiving forms are defined in terms of
457     ;;; Multiple-Value-Call.
458     ;;;
459     (defmacro multiple-value-setq (varlist value-form)
460     (unless (and (listp varlist) (every #'symbolp varlist))
461     (error "Varlist is not a list of symbols: ~S." varlist))
462     (let ((temps (mapcar #'(lambda (x) (declare (ignore x)) (gensym)) varlist)))
463     `(multiple-value-bind ,temps ,value-form
464     ,@(mapcar #'(lambda (var temp)
465     `(setq ,var ,temp))
466     varlist temps)
467     ,(car temps))))
468     ;;;
469     (defmacro multiple-value-bind (varlist value-form &body body)
470     (unless (and (listp varlist) (every #'symbolp varlist))
471     (error "Varlist is not a list of symbols: ~S." varlist))
472     (if (= (length varlist) 1)
473     `(let ((,(car varlist) ,value-form))
474     ,@body)
475     (let ((ignore (gensym)))
476     `(multiple-value-call #'(lambda (&optional ,@varlist &rest ,ignore)
477     (declare (ignore ,ignore))
478     ,@body)
479     ,value-form))))
480     ;;;
481     (defmacro multiple-value-list (value-form)
482     `(multiple-value-call #'list ,value-form))
483 ram 1.18
484    
485     (defmacro nth-value (n form)
486     "Evaluates FORM and returns the Nth value (zero based). This involves no
487     consing when N is a trivial constant integer."
488     (if (integerp n)
489     (let ((dummy-list nil)
490 wlott 1.30 (keeper (gensym "KEEPER-")))
491 ram 1.26 ;; We build DUMMY-LIST, a list of variables to bind to useless
492     ;; values, then we explicitly IGNORE those bindings and return
493 wlott 1.30 ;; KEEPER, the only thing we're really interested in right now.
494 ram 1.26 (dotimes (i n)
495 wlott 1.30 (push (gensym "IGNORE-") dummy-list))
496     `(multiple-value-bind (,@dummy-list ,keeper)
497 ram 1.26 ,form
498     (declare (ignore ,@dummy-list))
499 wlott 1.30 ,keeper))
500     (once-only ((n n))
501     `(case (the fixnum ,n)
502     (0 (nth-value 0 ,form))
503     (1 (nth-value 1 ,form))
504     (2 (nth-value 2 ,form))
505     (T (nth (the fixnum ,n) (multiple-value-list ,form)))))))
506 ram 1.1
507    
508     ;;;; SETF and friends.
509    
510     ;;; Note: The expansions for SETF and friends sometimes create needless
511     ;;; LET-bindings of argument values. The compiler will remove most of
512     ;;; these spurious bindings, so SETF doesn't worry too much about creating
513     ;;; them.
514 ram 1.35.1.3
515 ram 1.1 ;;; The inverse for a generalized-variable reference function is stored in
516     ;;; one of two ways:
517     ;;;
518     ;;; A SETF-INVERSE property corresponds to the short form of DEFSETF. It is
519     ;;; the name of a function takes the same args as the reference form, plus a
520     ;;; new-value arg at the end.
521     ;;;
522     ;;; A SETF-METHOD-EXPANDER property is created by the long form of DEFSETF or
523     ;;; by DEFINE-SETF-METHOD. It is a function that is called on the reference
524     ;;; form and that produces five values: a list of temporary variables, a list
525     ;;; of value forms, a list of the single store-value form, a storing function,
526     ;;; and an accessing function.
527    
528 wlott 1.29 (defun get-setf-method-multiple-value (form &optional environment)
529 ram 1.1 "Returns five values needed by the SETF machinery: a list of temporary
530 wlott 1.29 variables, a list of values with which to fill them, a list of temporaries
531     for the new values, the setting function, and the accessing function."
532 ram 1.1 (let (temp)
533     (cond ((symbolp form)
534 wlott 1.32 (multiple-value-bind
535     (expansion expanded)
536     (macroexpand-1 form environment)
537     (if expanded
538     (get-setf-method-multiple-value expansion)
539     (let ((new-var (gensym)))
540     (values nil nil (list new-var)
541     `(setq ,form ,new-var) form)))))
542 ram 1.25 ;;
543     ;; Local functions inhibit global setf methods...
544 ram 1.22 ((and environment
545 ram 1.35.1.2 (let ((name (car form)))
546     (dolist (x (c::lexenv-functions environment) nil)
547     (when (and (eq (car x) name)
548     (not (c::defined-function-p (cdr x))))
549     (return t)))))
550 ram 1.35.1.3 (get-setf-method-maybe-macro form environment))
551 ram 1.1 ((setq temp (info setf inverse (car form)))
552 wlott 1.10 (get-setf-method-inverse form `(,temp) nil))
553 ram 1.1 ((setq temp (info setf expander (car form)))
554     (funcall temp form environment))
555 ram 1.25 ;;
556     ;; If a macro, expand one level and try again. If not, go for the
557     ;; SETF function.
558 ram 1.1 (t
559 ram 1.35.1.3 (get-setf-method-maybe-macro form environment)))))
560    
561    
562     (defun get-setf-method-maybe-macro (form environment)
563     (multiple-value-bind (res win)
564     (macroexpand-1 form environment)
565     (if win
566     (get-setf-method-multiple-value res environment)
567     (get-setf-method-inverse form
568     `(funcall #'(setf ,(car form)))
569     t))))
570 ram 1.1
571 wlott 1.10 (defun get-setf-method-inverse (form inverse setf-function)
572 ram 1.1 (let ((new-var (gensym))
573     (vars nil)
574     (vals nil))
575     (dolist (x (cdr form))
576     (push (gensym) vars)
577     (push x vals))
578     (setq vals (nreverse vals))
579     (values vars vals (list new-var)
580 wlott 1.10 (if setf-function
581     `(,@inverse ,new-var ,@vars)
582     `(,@inverse ,@vars ,new-var))
583 ram 1.1 `(,(car form) ,@vars))))
584    
585    
586 wlott 1.29 (defun get-setf-method (form &optional environment)
587     "Like Get-Setf-Method-Multiple-Value, but signal an error if there are
588     more than one new-value variables."
589     (multiple-value-bind
590     (temps value-forms store-vars store-form access-form)
591     (get-setf-method-multiple-value form environment)
592     (when (cdr store-vars)
593     (error "GET-SETF-METHOD used for a form with multiple store ~
594     variables:~% ~S" form))
595     (values temps value-forms store-vars store-form access-form)))
596 ram 1.1
597 wlott 1.29
598 wlott 1.16 (defun defsetter (fn rest)
599 wlott 1.14 (let ((arglist (car rest))
600     (arglist-var (gensym "ARGS-"))
601     (new-var (car (cadr rest))))
602     (multiple-value-bind
603     (body local-decs doc)
604 wlott 1.16 (parse-defmacro arglist arglist-var (cddr rest) fn 'defsetf)
605 ram 1.1 (values
606 wlott 1.14 `(lambda (,arglist-var ,new-var)
607     ,@local-decs
608 wlott 1.16 ,body)
609 wlott 1.15 doc))))
610 ram 1.1
611    
612 wlott 1.16 (defmacro defsetf (access-fn &rest rest)
613 ram 1.1 "Associates a SETF update function or macro with the specified access
614     function or macro. The format is complex. See the manual for
615     details."
616     (cond ((not (listp (car rest)))
617     `(eval-when (load compile eval)
618 ram 1.22 (%define-setf-macro ',access-fn nil ',(car rest)
619     ,(when (and (car rest) (stringp (cadr rest)))
620     `',(cadr rest)))))
621 wlott 1.29 ((and (cdr rest) (listp (cadr rest)))
622     (destructuring-bind
623     (lambda-list (&rest store-variables) &body body)
624     rest
625     (let ((arglist-var (gensym "ARGS-"))
626     (access-form-var (gensym "ACCESS-FORM-"))
627     (env-var (gensym "ENVIRONMENT-")))
628     (multiple-value-bind
629     (body local-decs doc)
630     (parse-defmacro `(,lambda-list ,@store-variables)
631     arglist-var body access-fn 'defsetf
632     :annonymousp t)
633     `(eval-when (load compile eval)
634     (%define-setf-macro
635     ',access-fn
636     #'(lambda (,access-form-var ,env-var)
637     (declare (ignore ,env-var))
638     (%defsetf ,access-form-var ,(length store-variables)
639     #'(lambda (,arglist-var)
640     ,@local-decs
641     (block ,access-fn
642     ,body))))
643     nil
644     ',doc))))))
645     (t
646     (error "Ill-formed DEFSETF for ~S." access-fn))))
647 ram 1.1
648 wlott 1.29 (defun %defsetf (orig-access-form num-store-vars expander)
649 wlott 1.34 (collect ((subforms) (subform-vars) (subform-exprs) (store-vars))
650     (dolist (subform (cdr orig-access-form))
651     (if (constantp subform)
652     (subforms subform)
653     (let ((var (gensym)))
654     (subforms var)
655     (subform-vars var)
656     (subform-exprs subform))))
657     (dotimes (i num-store-vars)
658     (store-vars (gensym)))
659     (values (subform-vars)
660     (subform-exprs)
661     (store-vars)
662     (funcall expander (cons (subforms) (store-vars)))
663     `(,(car orig-access-form) ,@(subforms)))))
664 wlott 1.29
665    
666 ram 1.23 ;;; SETF -- Public
667     ;;;
668     ;;; Except for atoms, we always call GET-SETF-METHOD, since it has some
669     ;;; non-trivial semantics. But when there is a setf inverse, and G-S-M uses
670     ;;; it, then we return a call to the inverse, rather than returning a hairy let
671     ;;; form. This is probably important mainly as a convenince in allowing the
672     ;;; use of setf inverses without the full interpreter.
673     ;;;
674 ram 1.1 (defmacro setf (&rest args &environment env)
675     "Takes pairs of arguments like SETQ. The first is a place and the second
676     is the value that is supposed to go into that place. Returns the last
677     value. The place argument may be any of the access forms for which SETF
678     knows a corresponding setting form."
679 ram 1.22 (let ((nargs (length args)))
680     (cond
681     ((= nargs 2)
682 ram 1.23 (let ((place (first args))
683     (value-form (second args)))
684     (if (atom place)
685     `(setq ,place ,value-form)
686     (multiple-value-bind (dummies vals newval setter getter)
687 wlott 1.29 (get-setf-method-multiple-value place env)
688 ram 1.23 (declare (ignore getter))
689     (let ((inverse (info setf inverse (car place))))
690     (if (and inverse (eq inverse (car setter)))
691     `(,inverse ,@(cdr place) ,value-form)
692 wlott 1.29 `(let* (,@(mapcar #'list dummies vals))
693     (multiple-value-bind ,newval ,value-form
694     ,setter))))))))
695 ram 1.22 ((oddp nargs)
696     (error "Odd number of args to SETF."))
697     (t
698     (do ((a args (cddr a)) (l nil))
699     ((null a) `(progn ,@(nreverse l)))
700     (setq l (cons (list 'setf (car a) (cadr a)) l)))))))
701 ram 1.1
702     (defmacro psetf (&rest args &environment env)
703     "This is to SETF as PSETQ is to SETQ. Args are alternating place
704     expressions and values to go into those places. All of the subforms and
705     values are determined, left to right, and only then are the locations
706     updated. Returns NIL."
707 wlott 1.29 (collect ((let*-bindings) (mv-bindings) (setters))
708     (do ((a args (cddr a)))
709     ((endp a))
710     (if (endp (cdr a))
711     (error "Odd number of args to PSETF."))
712     (multiple-value-bind
713     (dummies vals newval setter getter)
714     (get-setf-method-multiple-value (car a) env)
715     (declare (ignore getter))
716     (let*-bindings (mapcar #'list dummies vals))
717     (mv-bindings (list newval (cadr a)))
718     (setters setter)))
719     (labels ((thunk (let*-bindings mv-bindings)
720     (if let*-bindings
721     `(let* ,(car let*-bindings)
722     (multiple-value-bind ,@(car mv-bindings)
723     ,(thunk (cdr let*-bindings) (cdr mv-bindings))))
724     `(progn ,@(setters) nil))))
725     (thunk (let*-bindings) (mv-bindings)))))
726 ram 1.1
727    
728     (defmacro shiftf (&rest args &environment env)
729     "One or more SETF-style place expressions, followed by a single
730 wlott 1.29 value expression. Evaluates all of the expressions in turn, then
731     assigns the value of each expression to the place on its left,
732     returning the value of the leftmost."
733 ram 1.1 (if (< (length args) 2)
734     (error "Too few argument forms to a SHIFTF."))
735 wlott 1.29 (collect ((let*-bindings) (forms))
736     (do ((first t nil)
737     (a args (cdr a))
738     (prev-store-vars)
739     (prev-setter))
740     ((endp (cdr a))
741     (forms `(multiple-value-bind ,prev-store-vars ,(car a)
742     ,prev-setter)))
743     (multiple-value-bind
744     (temps exprs store-vars setter getter)
745     (get-setf-method-multiple-value (car a) env)
746     (loop
747     for temp in temps
748     for expr in exprs
749     do (let*-bindings `(,temp ,expr)))
750     (forms (if first
751     getter
752     `(multiple-value-bind ,prev-store-vars ,getter
753     ,prev-setter)))
754     (setf prev-store-vars store-vars)
755     (setf prev-setter setter)))
756     `(let* ,(let*-bindings)
757     (multiple-value-prog1
758     ,@(forms)))))
759 ram 1.1
760     (defmacro rotatef (&rest args &environment env)
761     "Takes any number of SETF-style place expressions. Evaluates all of the
762 wlott 1.29 expressions in turn, then assigns to each place the value of the form to
763     its right. The rightmost form gets the value of the leftmost.
764     Returns NIL."
765     (when args
766     (collect ((let*-bindings) (mv-bindings) (setters) (getters))
767     (dolist (arg args)
768     (multiple-value-bind
769     (temps subforms store-vars setter getter)
770     (get-setf-method-multiple-value arg env)
771     (loop
772     for temp in temps
773     for subform in subforms
774     do (let*-bindings `(,temp ,subform)))
775     (mv-bindings store-vars)
776     (setters setter)
777     (getters getter)))
778     (setters nil)
779     (getters (car (getters)))
780     (labels ((thunk (mv-bindings getters)
781     (if mv-bindings
782     `((multiple-value-bind
783     ,(car mv-bindings)
784     ,(car getters)
785     ,@(thunk (cdr mv-bindings) (cdr getters))))
786     (setters))))
787     `(let* ,(let*-bindings)
788     ,@(thunk (mv-bindings) (cdr (getters))))))))
789 ram 1.1
790    
791     (defmacro define-modify-macro (name lambda-list function &optional doc-string)
792     "Creates a new read-modify-write macro like PUSH or INCF."
793     (let ((other-args nil)
794     (rest-arg nil)
795     (env (gensym))
796     (reference (gensym)))
797    
798     ;; Parse out the variable names and rest arg from the lambda list.
799     (do ((ll lambda-list (cdr ll))
800     (arg nil))
801     ((null ll))
802     (setq arg (car ll))
803     (cond ((eq arg '&optional))
804     ((eq arg '&rest)
805     (if (symbolp (cadr ll))
806     (setq rest-arg (cadr ll))
807     (error "Non-symbol &rest arg in definition of ~S." name))
808     (if (null (cddr ll))
809     (return nil)
810     (error "Illegal stuff after &rest arg in Define-Modify-Macro.")))
811     ((memq arg '(&key &allow-other-keys &aux))
812     (error "~S not allowed in Define-Modify-Macro lambda list." arg))
813     ((symbolp arg)
814     (push arg other-args))
815     ((and (listp arg) (symbolp (car arg)))
816     (push (car arg) other-args))
817     (t (error "Illegal stuff in lambda list of Define-Modify-Macro."))))
818     (setq other-args (nreverse other-args))
819     `(defmacro ,name (,reference ,@lambda-list &environment ,env)
820     ,doc-string
821     (multiple-value-bind (dummies vals newval setter getter)
822 wlott 1.13 (get-setf-method ,reference ,env)
823 ram 1.1 (do ((d dummies (cdr d))
824     (v vals (cdr v))
825     (let-list nil (cons (list (car d) (car v)) let-list)))
826     ((null d)
827     (push
828     (list (car newval)
829     ,(if rest-arg
830     `(list* ',function getter ,@other-args ,rest-arg)
831     `(list ',function getter ,@other-args)))
832     let-list)
833     `(let* ,(nreverse let-list)
834     ,setter)))))))
835    
836    
837    
838     (defmacro push (obj place &environment env)
839     "Takes an object and a location holding a list. Conses the object onto
840     the list, returning the modified list."
841     (if (symbolp place)
842     `(setq ,place (cons ,obj ,place))
843     (multiple-value-bind (dummies vals newval setter getter)
844 wlott 1.13 (get-setf-method place env)
845 ram 1.1 (do* ((d dummies (cdr d))
846     (v vals (cdr v))
847     (let-list nil))
848     ((null d)
849     (push (list (car newval) `(cons ,obj ,getter))
850     let-list)
851     `(let* ,(nreverse let-list)
852     ,setter))
853     (push (list (car d) (car v)) let-list)))))
854    
855    
856     (defmacro pushnew (obj place &rest keys &environment env)
857     "Takes an object and a location holding a list. If the object is already
858     in the list, does nothing. Else, conses the object onto the list. Returns
859     NIL. If there is a :TEST keyword, this is used for the comparison."
860     (if (symbolp place)
861     `(setq ,place (adjoin ,obj ,place ,@keys))
862     (multiple-value-bind (dummies vals newval setter getter)
863 wlott 1.13 (get-setf-method place env)
864 ram 1.1 (do* ((d dummies (cdr d))
865     (v vals (cdr v))
866     (let-list nil))
867     ((null d)
868     (push (list (car newval) `(adjoin ,obj ,getter ,@keys))
869     let-list)
870     `(let* ,(nreverse let-list)
871     ,setter))
872     (push (list (car d) (car v)) let-list)))))
873    
874    
875     (defmacro pop (place &environment env)
876     "The argument is a location holding a list. Pops one item off the front
877     of the list and returns it."
878     (if (symbolp place)
879     `(prog1 (car ,place) (setq ,place (cdr ,place)))
880     (multiple-value-bind (dummies vals newval setter getter)
881 wlott 1.13 (get-setf-method place env)
882 ram 1.1 (do* ((d dummies (cdr d))
883     (v vals (cdr v))
884     (let-list nil))
885     ((null d)
886     (push (list (car newval) getter) let-list)
887     `(let* ,(nreverse let-list)
888     (prog1 (car ,(car newval))
889     (setq ,(car newval) (cdr ,(car newval)))
890     ,setter)))
891     (push (list (car d) (car v)) let-list)))))
892    
893    
894     (define-modify-macro incf (&optional (delta 1)) +
895     "The first argument is some location holding a number. This number is
896     incremented by the second argument, DELTA, which defaults to 1.")
897    
898    
899     (define-modify-macro decf (&optional (delta 1)) -
900     "The first argument is some location holding a number. This number is
901     decremented by the second argument, DELTA, which defaults to 1.")
902    
903    
904     (defmacro remf (place indicator &environment env)
905     "Place may be any place expression acceptable to SETF, and is expected
906     to hold a property list or (). This list is destructively altered to
907     remove the property specified by the indicator. Returns T if such a
908     property was present, NIL if not."
909     (multiple-value-bind (dummies vals newval setter getter)
910 wlott 1.13 (get-setf-method place env)
911 ram 1.1 (do* ((d dummies (cdr d))
912     (v vals (cdr v))
913     (let-list nil)
914     (ind-temp (gensym))
915     (local1 (gensym))
916     (local2 (gensym)))
917     ((null d)
918     (push (list (car newval) getter) let-list)
919     (push (list ind-temp indicator) let-list)
920     `(let* ,(nreverse let-list)
921     (do ((,local1 ,(car newval) (cddr ,local1))
922     (,local2 nil ,local1))
923     ((atom ,local1) nil)
924     (cond ((atom (cdr ,local1))
925     (error "Odd-length property list in REMF."))
926     ((eq (car ,local1) ,ind-temp)
927     (cond (,local2
928     (rplacd (cdr ,local2) (cddr ,local1))
929     (return t))
930     (t (setq ,(car newval) (cddr ,(car newval)))
931     ,setter
932     (return t))))))))
933     (push (list (car d) (car v)) let-list))))
934    
935    
936     ;;; The built-in DEFSETFs.
937    
938     (defsetf car %rplaca)
939     (defsetf cdr %rplacd)
940     (defsetf caar (x) (v) `(%rplaca (car ,x) ,v))
941     (defsetf cadr (x) (v) `(%rplaca (cdr ,x) ,v))
942     (defsetf cdar (x) (v) `(%rplacd (car ,x) ,v))
943     (defsetf cddr (x) (v) `(%rplacd (cdr ,x) ,v))
944     (defsetf caaar (x) (v) `(%rplaca (caar ,x) ,v))
945     (defsetf cadar (x) (v) `(%rplaca (cdar ,x) ,v))
946     (defsetf cdaar (x) (v) `(%rplacd (caar ,x) ,v))
947     (defsetf cddar (x) (v) `(%rplacd (cdar ,x) ,v))
948     (defsetf caadr (x) (v) `(%rplaca (cadr ,x) ,v))
949     (defsetf caddr (x) (v) `(%rplaca (cddr ,x) ,v))
950     (defsetf cdadr (x) (v) `(%rplacd (cadr ,x) ,v))
951     (defsetf cdddr (x) (v) `(%rplacd (cddr ,x) ,v))
952     (defsetf caaaar (x) (v) `(%rplaca (caaar ,x) ,v))
953     (defsetf cadaar (x) (v) `(%rplaca (cdaar ,x) ,v))
954     (defsetf cdaaar (x) (v) `(%rplacd (caaar ,x) ,v))
955     (defsetf cddaar (x) (v) `(%rplacd (cdaar ,x) ,v))
956     (defsetf caadar (x) (v) `(%rplaca (cadar ,x) ,v))
957     (defsetf caddar (x) (v) `(%rplaca (cddar ,x) ,v))
958     (defsetf cdadar (x) (v) `(%rplacd (cadar ,x) ,v))
959     (defsetf cdddar (x) (v) `(%rplacd (cddar ,x) ,v))
960     (defsetf caaadr (x) (v) `(%rplaca (caadr ,x) ,v))
961     (defsetf cadadr (x) (v) `(%rplaca (cdadr ,x) ,v))
962     (defsetf cdaadr (x) (v) `(%rplacd (caadr ,x) ,v))
963     (defsetf cddadr (x) (v) `(%rplacd (cdadr ,x) ,v))
964     (defsetf caaddr (x) (v) `(%rplaca (caddr ,x) ,v))
965     (defsetf cadddr (x) (v) `(%rplaca (cdddr ,x) ,v))
966     (defsetf cdaddr (x) (v) `(%rplacd (caddr ,x) ,v))
967     (defsetf cddddr (x) (v) `(%rplacd (cdddr ,x) ,v))
968    
969     (defsetf first %rplaca)
970     (defsetf second (x) (v) `(%rplaca (cdr ,x) ,v))
971     (defsetf third (x) (v) `(%rplaca (cddr ,x) ,v))
972     (defsetf fourth (x) (v) `(%rplaca (cdddr ,x) ,v))
973     (defsetf fifth (x) (v) `(%rplaca (cddddr ,x) ,v))
974     (defsetf sixth (x) (v) `(%rplaca (cdr (cddddr ,x)) ,v))
975     (defsetf seventh (x) (v) `(%rplaca (cddr (cddddr ,x)) ,v))
976     (defsetf eighth (x) (v) `(%rplaca (cdddr (cddddr ,x)) ,v))
977     (defsetf ninth (x) (v) `(%rplaca (cddddr (cddddr ,x)) ,v))
978     (defsetf tenth (x) (v) `(%rplaca (cdr (cddddr (cddddr ,x))) ,v))
979     (defsetf rest %rplacd)
980    
981     (defsetf elt %setelt)
982     (defsetf aref %aset)
983 wlott 1.10 (defsetf row-major-aref %set-row-major-aref)
984 ram 1.1 (defsetf svref %svset)
985     (defsetf char %charset)
986     (defsetf bit %bitset)
987     (defsetf schar %scharset)
988     (defsetf sbit %sbitset)
989 wlott 1.10 (defsetf %array-dimension %set-array-dimension)
990     (defsetf %raw-bits %set-raw-bits)
991 ram 1.1 (defsetf symbol-value set)
992 wlott 1.28 (defsetf symbol-function fset)
993     (defsetf symbol-plist %set-symbol-plist)
994 ram 1.1 (defsetf documentation %set-documentation)
995     (defsetf nth %setnth)
996     (defsetf fill-pointer %set-fill-pointer)
997     (defsetf search-list %set-search-list)
998    
999 wlott 1.10 (defsetf sap-ref-8 %set-sap-ref-8)
1000 wlott 1.27 (defsetf signed-sap-ref-8 %set-signed-sap-ref-8)
1001 wlott 1.10 (defsetf sap-ref-16 %set-sap-ref-16)
1002 wlott 1.27 (defsetf signed-sap-ref-16 %set-signed-sap-ref-16)
1003 wlott 1.10 (defsetf sap-ref-32 %set-sap-ref-32)
1004 wlott 1.27 (defsetf signed-sap-ref-32 %set-signed-sap-ref-32)
1005 wlott 1.10 (defsetf sap-ref-sap %set-sap-ref-sap)
1006     (defsetf sap-ref-single %set-sap-ref-single)
1007     (defsetf sap-ref-double %set-sap-ref-double)
1008 ram 1.1
1009     (define-setf-method getf (place prop &optional default &environment env)
1010     (multiple-value-bind (temps values stores set get)
1011 wlott 1.13 (get-setf-method place env)
1012 ram 1.1 (let ((newval (gensym))
1013     (ptemp (gensym))
1014 wlott 1.31 (def-temp (if default (gensym))))
1015     (values `(,@temps ,ptemp ,@(if default `(,def-temp)))
1016     `(,@values ,prop ,@(if default `(,default)))
1017 ram 1.1 `(,newval)
1018 wlott 1.31 `(let ((,(car stores) (%putf ,get ,ptemp ,newval)))
1019     ,set
1020     ,newval)
1021     `(getf ,get ,ptemp ,@(if default `(,def-temp)))))))
1022 ram 1.1
1023     (define-setf-method get (symbol prop &optional default)
1024     (let ((symbol-temp (gensym))
1025     (prop-temp (gensym))
1026     (def-temp (gensym))
1027     (newval (gensym)))
1028     (values `(,symbol-temp ,prop-temp ,@(if default `(,def-temp)))
1029     `(,symbol ,prop ,@(if default `(,default)))
1030     (list newval)
1031     `(%put ,symbol-temp ,prop-temp ,newval)
1032     `(get ,symbol-temp ,prop-temp ,@(if default `(,def-temp))))))
1033    
1034     (define-setf-method gethash (key hashtable &optional default)
1035     (let ((key-temp (gensym))
1036     (hashtable-temp (gensym))
1037     (default-temp (gensym))
1038     (new-value-temp (gensym)))
1039     (values
1040     `(,key-temp ,hashtable-temp ,@(if default `(,default-temp)))
1041     `(,key ,hashtable ,@(if default `(,default)))
1042     `(,new-value-temp)
1043     `(%puthash ,key-temp ,hashtable-temp ,new-value-temp)
1044     `(gethash ,key-temp ,hashtable-temp ,@(if default `(,default-temp))))))
1045    
1046     (defsetf subseq (sequence start &optional (end nil)) (v)
1047     `(progn (replace ,sequence ,v :start1 ,start :end1 ,end)
1048     ,v))
1049    
1050    
1051 ram 1.35.1.2 ;;; Evil hack invented by the gnomes of Vassar Street (though not as evil as
1052     ;;; it used to be.) The function arg must be constant, and is converted to an
1053     ;;; APPLY of ther SETF function, which ought to exist.
1054 ram 1.22 ;;;
1055 ram 1.35.1.2 (define-setf-method apply (function &rest args)
1056 ram 1.22 (unless (and (listp function)
1057     (= (list-length function) 2)
1058     (eq (first function) 'function)
1059     (symbolp (second function)))
1060     (error "Setf of Apply is only defined for function args like #'symbol."))
1061 ram 1.35.1.2 (let ((function (second function))
1062     (new-var (gensym))
1063     (vars nil))
1064     (dolist (x args)
1065     (declare (ignore x))
1066     (push (gensym) vars))
1067     (values vars args (list new-var)
1068     `(apply #'(setf ,function) ,new-var ,@vars)
1069     `(apply #',function ,@vars))))
1070 ram 1.1
1071    
1072 wlott 1.10 ;;; Special-case a BYTE bytespec so that the compiler can recognize it.
1073     ;;;
1074 ram 1.1 (define-setf-method ldb (bytespec place &environment env)
1075     "The first argument is a byte specifier. The second is any place form
1076     acceptable to SETF. Replaces the specified byte of the number in this
1077     place with bits from the low-order end of the new value."
1078     (multiple-value-bind (dummies vals newval setter getter)
1079 wlott 1.13 (get-setf-method place env)
1080 wlott 1.10 (if (and (consp bytespec) (eq (car bytespec) 'byte))
1081     (let ((n-size (gensym))
1082     (n-pos (gensym))
1083     (n-new (gensym)))
1084     (values (list* n-size n-pos dummies)
1085     (list* (second bytespec) (third bytespec) vals)
1086     (list n-new)
1087     `(let ((,(car newval) (dpb ,n-new (byte ,n-size ,n-pos)
1088     ,getter)))
1089     ,setter
1090     ,n-new)
1091     `(ldb (byte ,n-size ,n-pos) ,getter)))
1092     (let ((btemp (gensym))
1093     (gnuval (gensym)))
1094     (values (cons btemp dummies)
1095     (cons bytespec vals)
1096     (list gnuval)
1097     `(let ((,(car newval) (dpb ,gnuval ,btemp ,getter)))
1098     ,setter
1099     ,gnuval)
1100     `(ldb ,btemp ,getter))))))
1101 ram 1.1
1102    
1103     (define-setf-method mask-field (bytespec place &environment env)
1104     "The first argument is a byte specifier. The second is any place form
1105     acceptable to SETF. Replaces the specified byte of the number in this place
1106     with bits from the corresponding position in the new value."
1107     (multiple-value-bind (dummies vals newval setter getter)
1108 wlott 1.13 (get-setf-method place env)
1109 ram 1.1 (let ((btemp (gensym))
1110     (gnuval (gensym)))
1111     (values (cons btemp dummies)
1112     (cons bytespec vals)
1113     (list gnuval)
1114     `(let ((,(car newval) (deposit-field ,gnuval ,btemp ,getter)))
1115     ,setter
1116     ,gnuval)
1117     `(mask-field ,btemp ,getter)))))
1118    
1119    
1120     (define-setf-method the (type place &environment env)
1121     (multiple-value-bind (dummies vals newval setter getter)
1122 wlott 1.13 (get-setf-method place env)
1123 ram 1.1 (values dummies
1124     vals
1125     newval
1126     (subst `(the ,type ,(car newval)) (car newval) setter)
1127     `(the ,type ,getter))))
1128    
1129    
1130     ;;;; CASE, TYPECASE, & Friends.
1131    
1132     (eval-when (compile load eval)
1133    
1134     ;;; CASE-BODY returns code for all the standard "case" macros. Name is the
1135     ;;; macro name, and keyform is the thing to case on. Multi-p indicates whether
1136     ;;; a branch may fire off a list of keys; otherwise, a key that is a list is
1137     ;;; interpreted in some way as a single key. When multi-p, test is applied to
1138     ;;; the value of keyform and each key for a given branch; otherwise, test is
1139     ;;; applied to the value of keyform and the entire first element, instead of
1140     ;;; each part, of the case branch. When errorp, no t or otherwise branch is
1141     ;;; permitted, and an ERROR form is generated. When proceedp, it is an error
1142     ;;; to omit errorp, and the ERROR form generated is executed within a
1143     ;;; RESTART-CASE allowing keyform to be set and retested.
1144     ;;;
1145     (defun case-body (name keyform cases multi-p test errorp proceedp)
1146     (let ((keyform-value (gensym))
1147     (clauses ())
1148     (keys ()))
1149     (dolist (case cases)
1150     (cond ((atom case)
1151     (error "~S -- Bad clause in ~S." case name))
1152     ((memq (car case) '(t otherwise))
1153     (if errorp
1154     (error "No default clause allowed in ~S: ~S" name case)
1155     (push `(t nil ,@(rest case)) clauses)))
1156     ((and multi-p (listp (first case)))
1157     (setf keys (append (first case) keys))
1158     (push `((or ,@(mapcar #'(lambda (key)
1159     `(,test ,keyform-value ',key))
1160     (first case)))
1161     nil ,@(rest case))
1162     clauses))
1163     (t
1164     (push (first case) keys)
1165     (push `((,test ,keyform-value
1166     ',(first case)) nil ,@(rest case)) clauses))))
1167     (case-body-aux name keyform keyform-value clauses keys errorp proceedp
1168     `(,(if multi-p 'member 'or) ,@keys))))
1169    
1170     ;;; CASE-BODY-AUX provides the expansion once CASE-BODY has groveled all the
1171     ;;; cases. Note: it is not necessary that the resulting code signal
1172     ;;; case-failure conditions, but that's what KMP's prototype code did. We call
1173     ;;; CASE-BODY-ERROR, because of how closures are compiled. RESTART-CASE has
1174     ;;; forms with closures that the compiler causes to be generated at the top of
1175     ;;; any function using the case macros, regardless of whether they are needed.
1176     ;;;
1177     (defun case-body-aux (name keyform keyform-value clauses keys
1178     errorp proceedp expected-type)
1179     (if proceedp
1180     (let ((block (gensym))
1181     (again (gensym)))
1182     `(let ((,keyform-value ,keyform))
1183     (block ,block
1184     (tagbody
1185     ,again
1186     (return-from
1187     ,block
1188     (cond ,@(nreverse clauses)
1189     (t
1190     (setf ,keyform-value
1191     (setf ,keyform
1192     (case-body-error
1193     ',name ',keyform ,keyform-value
1194     ',expected-type ',keys)))
1195     (go ,again))))))))
1196     `(let ((,keyform-value ,keyform))
1197     (cond
1198     ,@(nreverse clauses)
1199     ,@(if errorp
1200     `((t (error 'conditions::case-failure
1201     :name ',name
1202     :datum ,keyform-value
1203     :expected-type ',expected-type
1204     :possibilities ',keys))))))))
1205    
1206     ); eval-when
1207    
1208     (defun case-body-error (name keyform keyform-value expected-type keys)
1209     (restart-case
1210     (error 'conditions::case-failure
1211     :name name
1212     :datum keyform-value
1213     :expected-type expected-type
1214     :possibilities keys)
1215     (store-value (value)
1216     :report (lambda (stream)
1217     (format stream "Supply a new value for ~S." keyform))
1218     :interactive read-evaluated-form
1219     value)))
1220    
1221    
1222     (defmacro case (keyform &body cases)
1223     "CASE Keyform {({(Key*) | Key} Form*)}*
1224     Evaluates the Forms in the first clause with a Key EQL to the value of
1225     Keyform. If a singleton key is T then the clause is a default clause."
1226     (case-body 'case keyform cases t 'eql nil nil))
1227    
1228     (defmacro ccase (keyform &body cases)
1229     "CCASE Keyform {({(Key*) | Key} Form*)}*
1230     Evaluates the Forms in the first clause with a Key EQL to the value of
1231     Keyform. If none of the keys matches then a correctable error is
1232     signalled."
1233     (case-body 'ccase keyform cases t 'eql t t))
1234    
1235     (defmacro ecase (keyform &body cases)
1236     "ECASE Keyform {({(Key*) | Key} Form*)}*
1237     Evaluates the Forms in the first clause with a Key EQL to the value of
1238     Keyform. If none of the keys matches then an error is signalled."
1239     (case-body 'ecase keyform cases t 'eql t nil))
1240    
1241     (defmacro typecase (keyform &body cases)
1242     "TYPECASE Keyform {(Type Form*)}*
1243     Evaluates the Forms in the first clause for which TYPEP of Keyform and Type
1244     is true."
1245     (case-body 'typecase keyform cases nil 'typep nil nil))
1246    
1247     (defmacro ctypecase (keyform &body cases)
1248     "CTYPECASE Keyform {(Type Form*)}*
1249     Evaluates the Forms in the first clause for which TYPEP of Keyform and Type
1250     is true. If no form is satisfied then a correctable error is signalled."
1251     (case-body 'ctypecase keyform cases nil 'typep t t))
1252    
1253     (defmacro etypecase (keyform &body cases)
1254     "ETYPECASE Keyform {(Type Form*)}*
1255     Evaluates the Forms in the first clause for which TYPEP of Keyform and Type
1256     is true. If no form is satisfied then an error is signalled."
1257     (case-body 'etypecase keyform cases nil 'typep t nil))
1258    
1259    
1260     ;;;; ASSERT and CHECK-TYPE.
1261    
1262     ;;; ASSERT is written this way, to call ASSERT-ERROR, because of how closures
1263     ;;; are compiled. RESTART-CASE has forms with closures that the compiler
1264     ;;; causes to be generated at the top of any function using ASSERT, regardless
1265     ;;; of whether they are needed.
1266     ;;;
1267     (defmacro assert (test-form &optional places datum &rest arguments)
1268     "Signals an error if the value of test-form is nil. Continuing from this
1269     error using the CONTINUE restart will allow the user to alter the value of
1270     some locations known to SETF, starting over with test-form. Returns nil."
1271     `(loop
1272     (when ,test-form (return nil))
1273     (assert-error ',test-form ',places ,datum ,@arguments)
1274     ,@(mapcar #'(lambda (place)
1275     `(setf ,place (assert-prompt ',place ,place)))
1276     places)))
1277    
1278     (defun assert-error (test-form places datum &rest arguments)
1279     (restart-case (if datum
1280     (apply #'error datum arguments)
1281     (simple-assertion-failure test-form))
1282     (continue ()
1283     :report (lambda (stream) (assert-report places stream))
1284     nil)))
1285    
1286     (defun simple-assertion-failure (assertion)
1287     (error 'simple-type-error
1288     :datum assertion
1289     :expected-type nil ;this needs some work in next revision. -kmp
1290     :format-string "The assertion ~S failed."
1291     :format-arguments (list assertion)))
1292    
1293     (defun assert-report (names stream)
1294     (format stream "Retry assertion")
1295     (if names
1296     (format stream " with new value~P for ~{~S~^, ~}."
1297     (length names) names)
1298     (format stream ".")))
1299    
1300     (defun assert-prompt (name value)
1301     (cond ((y-or-n-p "The old value of ~S is ~S.~
1302     ~%Do you want to supply a new value? "
1303     name value)
1304     (format *query-io* "~&Type a form to be evaluated:~%")
1305     (flet ((read-it () (eval (read *query-io*))))
1306     (if (symbolp name) ;help user debug lexical variables
1307     (progv (list name) (list value) (read-it))
1308     (read-it))))
1309     (t value)))
1310    
1311    
1312     ;;; CHECK-TYPE is written this way, to call CHECK-TYPE-ERROR, because of how
1313     ;;; closures are compiled. RESTART-CASE has forms with closures that the
1314     ;;; compiler causes to be generated at the top of any function using
1315     ;;; CHECK-TYPE, regardless of whether they are needed. Because it would be
1316     ;;; nice if this were cheap to use, and some things can't afford this excessive
1317     ;;; consing (e.g., READ-CHAR), we bend backwards a little.
1318     ;;;
1319    
1320     (defmacro check-type (place type &optional type-string)
1321     "Signals an error of type type-error if the contents of place are not of the
1322     specified type. If an error is signaled, this can only return if
1323     STORE-VALUE is invoked. It will store into place and start over."
1324     (let ((place-value (gensym)))
1325     `(loop
1326     (let ((,place-value ,place))
1327     (when (typep ,place-value ',type) (return nil))
1328     (setf ,place
1329     (check-type-error ',place ,place-value ',type ,type-string))))))
1330    
1331     (defun check-type-error (place place-value type type-string)
1332     (restart-case (if type-string
1333     (error 'simple-type-error
1334     :datum place :expected-type type
1335     :format-string
1336     "The value of ~S is ~S, which is not ~A."
1337     :format-arguments
1338     (list place place-value type-string))
1339     (error 'simple-type-error
1340     :datum place :expected-type type
1341     :format-string
1342     "The value of ~S is ~S, which is not of type ~S."
1343     :format-arguments
1344     (list place place-value type)))
1345     (store-value (value)
1346     :report (lambda (stream)
1347     (format stream "Supply a new value of ~S."
1348     place))
1349     :interactive read-evaluated-form
1350     value)))
1351    
1352     ;;; READ-EVALUATED-FORM is used as the interactive method for restart cases
1353     ;;; setup by the Common Lisp "casing" (e.g., CCASE and CTYPECASE) macros
1354     ;;; and by CHECK-TYPE.
1355     ;;;
1356     (defun read-evaluated-form ()
1357     (format *query-io* "~&Type a form to be evaluated:~%")
1358     (list (eval (read *query-io*))))
1359    
1360    
1361     ;;;; With-XXX
1362    
1363     (defmacro with-open-file ((var &rest open-args) &body (forms decls))
1364 ram 1.5 "Bindspec is of the form (Stream File-Name . Options). The file whose
1365     name is File-Name is opened using the Options and bound to the variable
1366     Stream. If the call to open is unsuccessful, the forms are not
1367     evaluated. The Forms are executed, and when they terminate, normally or
1368     otherwise, the file is closed."
1369 ram 1.1 (let ((abortp (gensym)))
1370     `(let ((,var (open ,@open-args))
1371     (,abortp t))
1372     ,@decls
1373 ram 1.5 (when ,var
1374     (unwind-protect
1375     (multiple-value-prog1
1376     (progn ,@forms)
1377     (setq ,abortp nil))
1378 ram 1.1 (close ,var :abort ,abortp))))))
1379    
1380    
1381 ram 1.5
1382 ram 1.1 (defmacro with-open-stream ((var stream) &body (forms decls))
1383     "The form stream should evaluate to a stream. VAR is bound
1384     to the stream and the forms are evaluated as an implicit
1385     progn. The stream is closed upon exit."
1386     (let ((abortp (gensym)))
1387     `(let ((,var ,stream)
1388     (,abortp t))
1389     ,@decls
1390     (unwind-protect
1391     (multiple-value-prog1
1392     (progn ,@forms)
1393     (setq ,abortp nil))
1394     (when ,var
1395     (close ,var :abort ,abortp))))))
1396    
1397    
1398     (defmacro with-input-from-string ((var string &key index start end) &body (forms decls))
1399     "Binds the Var to an input stream that returns characters from String and
1400     executes the body. See manual for details."
1401     `(let ((,var
1402     ,(if end
1403     `(make-string-input-stream ,string ,(or start 0) ,end)
1404     `(make-string-input-stream ,string ,(or start 0)))))
1405     ,@decls
1406     (unwind-protect
1407     (progn ,@forms)
1408     (close ,var)
1409     ,@(if index `((setf ,index (string-input-stream-current ,var)))))))
1410    
1411    
1412     (defmacro with-output-to-string ((var &optional string) &body (forms decls))
1413 ram 1.5 "If *string* is specified, it must be a string with a fill pointer;
1414     the output is incrementally appended to the string (as if by use of
1415     VECTOR-PUSH-EXTEND)."
1416 ram 1.1 (if string
1417     `(let ((,var (make-fill-pointer-output-stream ,string)))
1418     ,@decls
1419     (unwind-protect
1420     (progn ,@forms)
1421     (close ,var)))
1422     `(let ((,var (make-string-output-stream)))
1423     ,@decls
1424     (unwind-protect
1425     (progn ,@forms)
1426     (close ,var))
1427     (get-output-stream-string ,var))))
1428    
1429    
1430     ;;;; Iteration macros:
1431    
1432     (defmacro dotimes ((var count &optional (result nil)) &body body)
1433     (cond ((numberp count)
1434     `(do ((,var 0 (1+ ,var)))
1435     ((>= ,var ,count) ,result)
1436 ram 1.8 (declare (type unsigned-byte ,var))
1437 ram 1.1 ,@body))
1438     (t (let ((v1 (gensym)))
1439     `(do ((,var 0 (1+ ,var)) (,v1 ,count))
1440     ((>= ,var ,v1) ,result)
1441 ram 1.8 (declare (type unsigned-byte ,var))
1442 ram 1.1 ,@body)))))
1443    
1444    
1445     ;;; We repeatedly bind the var instead of setting it so that we never give the
1446     ;;; var a random value such as NIL (which might conflict with a declaration).
1447 ram 1.35 ;;; If there is a result form, we introduce a gratitous binding of the variable
1448     ;;; to NIL w/o the declarations, then evaluate the result form in that
1449     ;;; environment. We spuriously reference the gratuitous variable, since we
1450     ;;; don't want to use IGNORABLE on what might be a special var.
1451 ram 1.1 ;;;
1452     (defmacro dolist ((var list &optional (result nil)) &body body)
1453     (let ((n-list (gensym)))
1454     `(do ((,n-list ,list (cdr ,n-list)))
1455     ((endp ,n-list)
1456 ram 1.35 ,@(if result
1457     `((let ((,var nil))
1458     ,var
1459     ,result))
1460     '(nil)))
1461 ram 1.1 (let ((,var (car ,n-list)))
1462     ,@body))))
1463    
1464    
1465     (defmacro do (varlist endlist &body (body decls))
1466     "DO ({(Var [Init] [Step])}*) (Test Exit-Form*) Declaration* Form*
1467     Iteration construct. Each Var is initialized in parallel to the value of the
1468     specified Init form. On subsequent iterations, the Vars are assigned the
1469     value of the Step form (if any) in paralell. The Test is evaluated before
1470     each evaluation of the body Forms. When the Test is true, the the Exit-Forms
1471     are evaluated as a PROGN, with the result being the value of the DO. A block
1472     named NIL is established around the entire expansion, allowing RETURN to be
1473     used as an laternate exit mechanism."
1474    
1475     (do-do-body varlist endlist body decls 'let 'psetq 'do nil))
1476    
1477    
1478     (defmacro do* (varlist endlist &body (body decls))
1479     "DO* ({(Var [Init] [Step])}*) (Test Exit-Form*) Declaration* Form*
1480     Iteration construct. Each Var is initialized sequentially (like LET*) to the
1481     value of the specified Init form. On subsequent iterations, the Vars are
1482     sequentially assigned the value of the Step form (if any). The Test is
1483     evaluated before each evaluation of the body Forms. When the Test is true,
1484     the the Exit-Forms are evaluated as a PROGN, with the result being the value
1485     of the DO. A block named NIL is established around the entire expansion,
1486     allowing RETURN to be used as an laternate exit mechanism."
1487     (do-do-body varlist endlist body decls 'let* 'setq 'do* nil))
1488    
1489    
1490     ;;;; Miscellaneous macros:
1491    
1492     (defmacro locally (&rest forms)
1493     "A form providing a container for locally-scoped variables."
1494     `(let () ,@forms))
1495    
1496     (defmacro psetq (&rest pairs)
1497     (do ((lets nil)
1498     (setqs nil)
1499     (pairs pairs (cddr pairs)))
1500     ((atom (cdr pairs))
1501     `(let ,(nreverse lets) (setq ,@(nreverse setqs))))
1502     (let ((gen (gensym)))
1503     (push `(,gen ,(cadr pairs)) lets)
1504     (push (car pairs) setqs)
1505     (push gen setqs))))
1506    
1507    
1508     ;;;; With-Compilation-Unit:
1509    
1510     ;;; True if we are within a With-Compilation-Unit form, which normally causes
1511     ;;; nested uses to be NOOPS.
1512     ;;;
1513     (defvar *in-compilation-unit* nil)
1514    
1515     ;;; Count of the number of compilation units dynamically enclosed by the
1516     ;;; current active WITH-COMPILATION-UNIT that were unwound out of.
1517     ;;;
1518     (defvar *aborted-compilation-units*)
1519    
1520 ram 1.21 (declaim (special c::*context-declarations*))
1521    
1522    
1523     ;;; EVALUATE-DECLARATION-CONTEXT -- Internal
1524     ;;;
1525     ;;; Recursively descend the context form, returning true if this subpart
1526     ;;; matches the specified context.
1527     ;;;
1528     (defun evaluate-declaration-context (context name parent)
1529 ram 1.24 (let* ((base (if (and (consp name) (consp (cdr name)))
1530     (cadr name)
1531     name))
1532     (package (and (symbolp base) (symbol-package base))))
1533 ram 1.21 (if (atom context)
1534 ram 1.24 (multiple-value-bind (ignore how)
1535     (if package
1536     (find-symbol (symbol-name base) package)
1537     (values nil nil))
1538     (declare (ignore ignore))
1539     (case context
1540     (:internal (eq how :internal))
1541     (:external (eq how :external))
1542     (:uninterned (and (symbolp base) (not package)))
1543     (:anonymous (not name))
1544     (:macro (eq parent 'defmacro))
1545     (:function (member parent '(defun labels flet function)))
1546     (:global (member parent '(defun defmacro function)))
1547     (:local (member parent '(labels flet)))
1548     (t
1549     (error "Unknown declaration context: ~S." context))))
1550 ram 1.21 (case (first context)
1551     (:or
1552     (loop for x in (rest context)
1553     thereis (evaluate-declaration-context x name parent)))
1554     (:and
1555     (loop for x in (rest context)
1556     always (evaluate-declaration-context x name parent)))
1557     (:not
1558     (evaluate-declaration-context (second context) name parent))
1559     (:member
1560     (member name (rest context) :test #'equal))
1561     (:match
1562     (let ((name (concatenate 'string "$" (string base) "$")))
1563     (loop for x in (rest context)
1564     thereis (search (string x) name))))
1565 ram 1.24 (:package
1566     (and package
1567     (loop for x in (rest context)
1568     thereis (eq (find-package (string x)) package))))
1569 ram 1.21 (t
1570     (error "Unknown declaration context: ~S." context))))))
1571    
1572    
1573     ;;; PROCESS-CONTEXT-DECLARATIONS -- Internal
1574     ;;;
1575     ;;; Given a list of context declaration specs, return a new value for
1576     ;;; C::*CONTEXT-DECLARATIONS*.
1577     ;;;
1578     (defun process-context-declarations (decls)
1579     (append
1580     (mapcar
1581     #'(lambda (decl)
1582     (unless (>= (length decl) 2)
1583     (error "Context declaration spec should have context and at ~
1584     least one DECLARE form:~% ~S" decl))
1585     #'(lambda (name parent)
1586     (when (evaluate-declaration-context (first decl) name parent)
1587     (rest decl))))
1588     decls)
1589     c::*context-declarations*))
1590    
1591    
1592 ram 1.1 ;;; With-Compilation-Unit -- Public
1593     ;;;
1594     (defmacro with-compilation-unit (options &body body)
1595 ram 1.21 "WITH-COMPILATION-UNIT ({Key Value}*) Form*
1596     This form affects compilations that take place within its dynamic extent. It
1597     is intended to be wrapped around the compilation of all files in the same
1598     system. These keywords are defined:
1599     :OVERRIDE Boolean-Form
1600     One of the effects of this form is to delay undefined warnings
1601     until the end of the form, instead of giving them at the end of each
1602     compilation. If OVERRIDE is NIL (the default), then the outermost
1603     WITH-COMPILATION-UNIT form grabs the undefined warnings. Specifying
1604     OVERRIDE true causes that form to grab any enclosed warnings, even if
1605     it is enclosed by another WITH-COMPILATION-UNIT.
1606     :OPTIMIZE Decl-Form
1607     Decl-Form should evaluate to an OPTIMIZE declaration specifier. This
1608     declaration changes the `global' policy for compilations within the
1609     body.
1610     :OPTIMIZE-INTERFACE Decl-Form
1611     Like OPTIMIZE, except that it specifies the value of the CMU extension
1612     OPTIMIZE-INTERFACE policy (which controls argument type and syntax
1613     checking.)
1614     :CONTEXT-DECLARATIONS List-of-Context-Decls-Form
1615     This is a CMU extension which allows compilation to be controlled
1616     by pattern matching on the context in which a definition appears. The
1617     argument should evaluate to a list of lists of the form:
1618     (Context-Spec Declare-Form+)
1619     In the indicated context, the specified declare forms are inserted at
1620     the head of each definition. The declare forms for all contexts that
1621     match are appended together, with earlier declarations getting
1622     predecence over later ones. A simple example:
1623     :context-declarations
1624     '((:external (declare (optimize (safety 2)))))
1625     This will cause all functions that are named by external symbols to be
1626     compiled with SAFETY 2. The full syntax of context specs is:
1627     :INTERNAL, :EXTERNAL
1628     True if the symbols is internal (external) in its home package.
1629     :UNINTERNED
1630     True if the symbol has no home package.
1631     :ANONYMOUS
1632     True if the function doesn't have any interesting name (not
1633     DEFMACRO, DEFUN, LABELS or FLET).
1634     :MACRO, :FUNCTION
1635     :MACRO is a global (DEFMACRO) macro. :FUNCTION is anything else.
1636     :LOCAL, :GLOBAL
1637     :LOCAL is a LABELS or FLET. :GLOBAL is anything else.
1638     (:OR Context-Spec*)
1639     True in any specified context.
1640     (:AND Context-Spec*)
1641     True only when all specs are true.
1642     (:NOT Context-Spec)
1643     True when the spec is false.
1644     (:MEMBER Name*)
1645     True when the name is one of these names (EQUAL test.)
1646     (:MATCH Pattern*)
1647     True when any of the patterns is a substring of the name. The name
1648     is wrapped with $'s, so $FOO matches names beginning with FOO,
1649     etc."
1650     (let ((override nil)
1651     (optimize nil)
1652     (optimize-interface nil)
1653     (context-declarations nil)
1654 ram 1.1 (n-fun (gensym))
1655     (n-abort-p (gensym)))
1656     (when (oddp (length options))
1657     (error "Odd number of key/value pairs: ~S." options))
1658     (do ((opt options (cddr opt)))
1659     ((null opt))
1660     (case (first opt)
1661 ram 1.21 (:override
1662     (setq override (second opt)))
1663     (:optimize
1664     (setq optimize (second opt)))
1665     (:optimize-interface
1666     (setq optimize-interface (second opt)))
1667     (:context-declarations
1668     (setq context-declarations (second opt)))
1669 ram 1.1 (t
1670     (warn "Ignoring unknown option: ~S." (first opt)))))
1671    
1672 ram 1.21 `(flet ((,n-fun ()
1673     (let (,@(when optimize
1674     `((c::*default-cookie*
1675     (c::process-optimize-declaration
1676     ,optimize c::*default-cookie*))))
1677     ,@(when optimize-interface
1678     `((c::*default-interface-cookie*
1679     (c::process-optimize-declaration
1680     ,optimize-interface
1681     c::*default-interface-cookie*))))
1682     ,@(when context-declarations
1683     `((c::*context-declarations*
1684     (process-context-declarations
1685     ,context-declarations)))))
1686     ,@body)))
1687     (if (or ,override (not *in-compilation-unit*))
1688 ram 1.6 (let ((c::*undefined-warnings* nil)
1689 ram 1.1 (c::*compiler-error-count* 0)
1690     (c::*compiler-warning-count* 0)
1691     (c::*compiler-note-count* 0)
1692     (*in-compilation-unit* t)
1693     (*aborted-compilation-units* 0)
1694     (,n-abort-p t))
1695 ram 1.6 (handler-bind ((c::parse-unknown-type
1696     #'(lambda (c)
1697     (c::note-undefined-reference
1698     (c::parse-unknown-type-specifier c)
1699     :type))))
1700     (unwind-protect
1701     (multiple-value-prog1
1702     (,n-fun)
1703     (setq ,n-abort-p nil))
1704     (c::print-summary ,n-abort-p *aborted-compilation-units*))))
1705 ram 1.1 (let ((,n-abort-p t))
1706     (unwind-protect
1707     (multiple-value-prog1
1708     (,n-fun)
1709     (setq ,n-abort-p nil))
1710     (when ,n-abort-p
1711     (incf *aborted-compilation-units*))))))))

  ViewVC Help
Powered by ViewVC 1.1.5