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

Diff of /src/code/macros.lisp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.103.2.1 by rtoy, Mon Dec 19 01:09:51 2005 UTC revision 1.120 by rtoy, Tue May 25 20:04:33 2010 UTC
# Line 16  Line 16 
16  ;;; Modified by Bill Chiles to adhere to the wall.  ;;; Modified by Bill Chiles to adhere to the wall.
17  ;;;  ;;;
18  (in-package "LISP")  (in-package "LISP")
19    (intl:textdomain "cmucl")
20    
21  (export '(defvar defparameter defconstant when unless setf  (export '(defvar defparameter defconstant when unless setf
22            defsetf psetf shiftf rotatef push pushnew pop            defsetf psetf shiftf rotatef push pushnew pop
23            incf decf remf case typecase with-open-file            incf decf remf case typecase with-open-file
# Line 85  Line 87 
87              (restart-case              (restart-case
88                  (error 'lisp::package-locked-error                  (error 'lisp::package-locked-error
89                         :package package                         :package package
90                         :format-control "defining macro ~A"                         :format-control (intl:gettext "defining macro ~A")
91                         :format-arguments (list name))                         :format-arguments (list name))
92                (continue ()                (continue ()
93                  :report "Ignore the lock and continue")                  :report (lambda (stream)
94                              (write-string (intl:gettext "Ignore the lock and continue") stream)))
95                (unlock-package ()                (unlock-package ()
96                  :report "Disable the package's definition-lock then continue"                  :report (lambda (stream)
97                              (write-string (intl:gettext "Disable the package's definition-lock then continue") stream))
98                  (setf (ext:package-definition-lock package) nil))                  (setf (ext:package-definition-lock package) nil))
99                (unlock-all ()                (unlock-all ()
100                  :report "Unlock all packages, then continue"                  :report (lambda (stream)
101                              (write-string (intl:gettext "Unlock all packages, then continue") stream))
102                  (lisp::unlock-all-packages))))))))                  (lisp::unlock-all-packages))))))))
103    (let ((whole (gensym "WHOLE-"))    (let ((whole (gensym "WHOLE-"))
104          (environment (gensym "ENV-")))          (environment (gensym "ENV-")))
# Line 101  Line 106 
106          (body local-decs doc)          (body local-decs doc)
107          (parse-defmacro lambda-list whole body name 'defmacro          (parse-defmacro lambda-list whole body name 'defmacro
108                          :environment environment)                          :environment environment)
109          (when doc
110            (intl::note-translatable intl::*default-domain* doc))
111        (let ((def `(lambda (,whole ,environment)        (let ((def `(lambda (,whole ,environment)
112                      ,@local-decs                      ,@local-decs
113                      (block ,name                      (block ,name
# Line 143  Line 150 
150    "Define a compiler-macro for NAME."    "Define a compiler-macro for NAME."
151    (let ((whole (gensym "WHOLE-"))    (let ((whole (gensym "WHOLE-"))
152          (environment (gensym "ENV-")))          (environment (gensym "ENV-")))
153      (multiple-value-bind      (multiple-value-bind (validp block-name)
154          (body local-decs doc)          (valid-function-name-p name)
155          (parse-defmacro lambda-list whole body name 'define-compiler-macro        (unless validp
156                          :environment environment)          (simple-program-error (intl:gettext "~S is not a valid function name.") name))
157        (let ((def `(lambda (,whole ,environment)        (multiple-value-bind
158                      ,@local-decs              (body local-decs doc)
159                      (block ,name            (parse-defmacro lambda-list whole body name 'define-compiler-macro
160                        ,body))))                            :environment environment)
161          `(progn          (when doc
162             (eval-when (:compile-toplevel)            (intl::note-translatable intl::*default-domain* doc))
163               (c::do-compiler-macro-compile-time ',name #',def))          (let ((def `(lambda (,whole ,environment)
164             (eval-when (:load-toplevel :execute)                        ,@local-decs
165               (c::%define-compiler-macro ',name #',def ',lambda-list ,doc)))))))                        (block ,block-name
166                            ,body))))
167              `(progn
168                 (eval-when (:compile-toplevel)
169                   (c::do-compiler-macro-compile-time ',name #',def))
170                 (eval-when (:load-toplevel :execute)
171                   (c::%define-compiler-macro ',name #',def ',lambda-list ,doc))))))))
172    
173    
174  (defun c::%define-compiler-macro (name definition lambda-list doc)  (defun c::%define-compiler-macro (name definition lambda-list doc)
# Line 184  Line 197 
197  (defun %define-symbol-macro (name expansion)  (defun %define-symbol-macro (name expansion)
198    (unless (symbolp name)    (unless (symbolp name)
199      (error 'simple-type-error :datum name :expected-type 'symbol      (error 'simple-type-error :datum name :expected-type 'symbol
200             :format-control "Symbol macro name is not a symbol: ~S."             :format-control (intl:gettext "Symbol macro name is not a symbol: ~S.")
201             :format-arguments (list name)))             :format-arguments (list name)))
202    (ecase (info variable kind name)    (ecase (info variable kind name)
203      ((:macro :global nil)      ((:macro :global nil)
# Line 192  Line 205 
205       (setf (info variable macro-expansion name) expansion))       (setf (info variable macro-expansion name) expansion))
206      (:special      (:special
207       (error 'simple-program-error       (error 'simple-program-error
208              :format-control "Symbol macro name already declared special: ~S."              :format-control (intl:gettext "Symbol macro name already declared special: ~S.")
209              :format-arguments (list name)))              :format-arguments (list name)))
210      (:constant      (:constant
211       (error 'simple-program-error       (error 'simple-program-error
212              :format-control "Symbol macro name already declared constant: ~S."              :format-control (intl:gettext "Symbol macro name already declared constant: ~S.")
213              :format-arguments (list name))))              :format-arguments (list name))))
214    name)    name)
215    
# Line 206  Line 219 
219  (defmacro deftype (name arglist &body body)  (defmacro deftype (name arglist &body body)
220    "Syntax like DEFMACRO, but defines a new type."    "Syntax like DEFMACRO, but defines a new type."
221    (unless (symbolp name)    (unless (symbolp name)
222      (simple-program-error "~S -- Type name not a symbol." name))      (simple-program-error (intl:gettext "~S -- Type name not a symbol.") name))
223    (and lisp::*enable-package-locked-errors*    (and lisp::*enable-package-locked-errors*
224         (symbol-package name)         (symbol-package name)
225         (ext:package-definition-lock (symbol-package name))         (ext:package-definition-lock (symbol-package name))
226         (restart-case         (restart-case
227             (error 'lisp::package-locked-error             (error 'lisp::package-locked-error
228                    :package (symbol-package name)                    :package (symbol-package name)
229                    :format-control "defining type ~A"                    :format-control (intl:gettext "defining type ~A")
230                    :format-arguments (list name))                    :format-arguments (list name))
231           (continue ()           (continue ()
232             :report "Ignore the lock and continue")             :report (lambda (stream)
233                         (write-string (intl:gettext "Ignore the lock and continue") stream)))
234           (unlock-package ()           (unlock-package ()
235             :report "Disable package's definition-lock then continue"             :report (lambda (stream)
236                         (write-string (intl:gettext "Disable package's definition-lock then continue") stream))
237             (setf (ext:package-definition-lock (symbol-package name)) nil))             (setf (ext:package-definition-lock (symbol-package name)) nil))
238           (unlock-all ()           (unlock-all ()
239             :report "Unlock all packages, then continue"             :report (lambda (stream)
240                         (write-string (intl:gettext "Unlock all packages, then continue") stream))
241             (lisp::unlock-all-packages))))             (lisp::unlock-all-packages))))
242    (let ((whole (gensym "WHOLE-")))    (let ((whole (gensym "WHOLE-")))
243      (multiple-value-bind (body local-decs doc)      (multiple-value-bind (body local-decs doc)
244                           (parse-defmacro arglist whole body name 'deftype                           (parse-defmacro arglist whole body name 'deftype
245                                           :default-default ''*)                                           :default-default ''*)
246          (when doc
247            (intl::note-translatable intl::*default-domain* doc))
248        `(eval-when (:compile-toplevel :load-toplevel :execute)        `(eval-when (:compile-toplevel :load-toplevel :execute)
249             (set-defvar-source-location ',name (c::source-location))
250           (%deftype ',name           (%deftype ',name
251                     #'(lambda (,whole)                     #'(lambda (,whole)
252                         ,@local-decs                         ,@local-decs
# Line 236  Line 255 
255  ;;;  ;;;
256  (defun %deftype (name expander &optional doc)  (defun %deftype (name expander &optional doc)
257    (when (info declaration recognized name)    (when (info declaration recognized name)
258      (error "Deftype already names a declaration: ~S." name))      (error (intl:gettext "Deftype already names a declaration: ~S.") name))
259    (ecase (info type kind name)    (ecase (info type kind name)
260      (:primitive      (:primitive
261       (when *type-system-initialized*       (when *type-system-initialized*
262         (error "Illegal to redefine standard type: ~S." name)))         (error (intl:gettext "Illegal to redefine standard type: ~S.") name)))
263      (:instance      (:instance
264       (warn "Redefining class ~S to be a DEFTYPE." name)       (warn (intl:gettext "Redefining class ~S to be a DEFTYPE.") name)
265       (undefine-structure (layout-info (%class-layout (kernel::find-class name))))       (undefine-structure (layout-info (%class-layout (kernel::find-class name))))
266       (setf (class-cell-class (find-class-cell name)) nil)       (setf (class-cell-class (find-class-cell name)) nil)
267       (setf (info type compiler-layout name) nil)       (setf (info type compiler-layout name) nil)
# Line 269  Line 288 
288    "Syntax like DEFMACRO, but creates a Setf-Expansion generator.  The body    "Syntax like DEFMACRO, but creates a Setf-Expansion generator.  The body
289    must be a form that returns the five magical values."    must be a form that returns the five magical values."
290    (unless (symbolp access-fn)    (unless (symbolp access-fn)
291      (simple-program-error "~S -- Access-function name not a symbol in DEFINE-SETF-EXPANDER."      (simple-program-error (intl:gettext "~S -- Access-function name not a symbol in DEFINE-SETF-EXPANDER.")
292             access-fn))             access-fn))
293    
294    (let ((whole (gensym "WHOLE-"))    (let ((whole (gensym "WHOLE-"))
# Line 278  Line 297 
297                           (parse-defmacro lambda-list whole body access-fn                           (parse-defmacro lambda-list whole body access-fn
298                                           'define-setf-expander                                           'define-setf-expander
299                                           :environment environment)                                           :environment environment)
300          (when doc
301            (intl::note-translatable intl::*default-domain* doc))
302        `(eval-when (:compile-toplevel :load-toplevel :execute)        `(eval-when (:compile-toplevel :load-toplevel :execute)
303           (%define-setf-macro           (%define-setf-macro
304            ',access-fn            ',access-fn
# Line 299  Line 320 
320  (defun %define-setf-macro (name expander inverse doc)  (defun %define-setf-macro (name expander inverse doc)
321    (cond ((not (fboundp `(setf ,name))))    (cond ((not (fboundp `(setf ,name))))
322          ((info function accessor-for name)          ((info function accessor-for name)
323           (warn "Defining setf macro for destruct slot accessor; redefining as ~           (warn (intl:gettext "Defining setf macro for destruct slot accessor; redefining as ~
324                  a normal function:~%  ~S"                  a normal function:~%  ~S")
325                 name)                 name)
326           (c::define-function-name name))           (c::define-function-name name))
327          ((not (eq (symbol-package name) (symbol-package 'aref)))          ((not (eq (symbol-package name) (symbol-package 'aref)))
328           (warn "Defining setf macro for ~S, but ~S is fbound."           (warn (intl:gettext "Defining setf macro for ~S, but ~S is fbound.")
329                 name `(setf ,name))))                 name `(setf ,name))))
330    (when (or inverse (info setf inverse name))    (when (or inverse (info setf inverse name))
331      (setf (info setf inverse name) inverse))      (setf (info setf inverse name) inverse))
# Line 340  Line 361 
361    (multiple-value-bind (valid block-name)    (multiple-value-bind (valid block-name)
362        (valid-function-name-p name)        (valid-function-name-p name)
363      (declare (ignore valid))      (declare (ignore valid))
364        (when doc
365          (intl::note-translatable intl::*default-domain* doc))
366      (let ((def `(lambda ,lambda-list      (let ((def `(lambda ,lambda-list
367                    ,@decls                    ,@decls
368                    (block ,block-name ,@body))))                    (block ,block-name ,@body))))
# Line 351  Line 374 
374  ;;;    Similar to %Defmacro, ...  ;;;    Similar to %Defmacro, ...
375  ;;;  ;;;
376  (defun c::%%defun (name def doc &optional inline-expansion)  (defun c::%%defun (name def doc &optional inline-expansion)
377      (c::define-function-name name)
378    (setf (fdefinition name) def)    (setf (fdefinition name) def)
379    (when doc    (when doc
380      (if (and (consp name) (eq (first name) 'setf))      (if (and (consp name) (eq (first name) 'setf))
381          (setf (documentation (second name) 'setf) doc)          (setf (documentation (second name) 'setf) doc)
382          (setf (documentation name 'function) doc)))          (setf (documentation name 'function) doc)))
   (c::define-function-name name)  
383    (when (eq (info function where-from name) :assumed)    (when (eq (info function where-from name) :assumed)
384      (setf (info function where-from name) :defined)      (setf (info function where-from name) :defined)
385      (when (info function assumed-type name)      (when (info function assumed-type name)
# Line 378  Line 401 
401            (setq inline-expansion lambda-expression))))            (setq inline-expansion lambda-expression))))
402      (c::%%defun name def doc inline-expansion)))      (c::%%defun name def doc inline-expansion)))
403    
404    (defun set-defvar-textdomain (name domain)
405      (setf (c::info variable textdomain name) domain))
406    
407  ;;; DEFCONSTANT  --  Public  ;;; DEFCONSTANT  --  Public
408  ;;;  ;;;
409  (defmacro defconstant (var val &optional doc)  (defmacro defconstant (var val &optional doc)
# Line 385  Line 411 
411    value is constant and may be compiled into code.  If the variable already has    value is constant and may be compiled into code.  If the variable already has
412    a value, and this is not equal to the init, an error is signalled.  The third    a value, and this is not equal to the init, an error is signalled.  The third
413    argument is an optional documentation string for the variable."    argument is an optional documentation string for the variable."
414      (when doc
415        (intl::note-translatable intl::*default-domain* doc))
416    `(progn    `(progn
417       (eval-when (:compile-toplevel)       (eval-when (:compile-toplevel)
418         (c::do-defconstant-compile-time ',var ,val ',doc))         (c::do-defconstant-compile-time ',var ,val ',doc))
419       (eval-when (:load-toplevel :execute)       (eval-when (:load-toplevel :execute)
420           (set-defvar-textdomain ',var ,intl::*default-domain*)
421         (c::%%defconstant ',var ,val ',doc (c::source-location)))))         (c::%%defconstant ',var ,val ',doc (c::source-location)))))
422    
423  (defun set-defvar-source-location (name source-location)  (defun set-defvar-source-location (name source-location)
# Line 408  Line 437 
437      (setf (documentation name 'variable) doc))      (setf (documentation name 'variable) doc))
438    (when (boundp name)    (when (boundp name)
439      (unless (equalp (symbol-value name) value)      (unless (equalp (symbol-value name) value)
440        (cerror "Go ahead and change the value."        (cerror (intl:gettext "Go ahead and change the value.")
441                "Constant ~S being redefined." name)))                (intl:gettext "Constant ~S being redefined.") name)))
442    (setf (symbol-value name) value)    (setf (symbol-value name) value)
443    (setf (info variable kind name) :constant)    (setf (info variable kind name) :constant)
444    (clear-info variable constant-value name)    (clear-info variable constant-value name)
445    (set-defvar-source-location name source-location)    (set-defvar-source-location name source-location)
446    name)    name)
447    
   
448  (defmacro defvar (var &optional (val nil valp) (doc nil docp))  (defmacro defvar (var &optional (val nil valp) (doc nil docp))
449    "For defining global variables at top level.  Declares the variable    "For defining global variables at top level.  Declares the variable
450    SPECIAL and, optionally, initializes it.  If the variable already has a    SPECIAL and, optionally, initializes it.  If the variable already has a
451    value, the old value is not clobbered.  The third argument is an optional    value, the old value is not clobbered.  The third argument is an optional
452    documentation string for the variable."    documentation string for the variable."
453      (when docp
454        (intl::note-translatable intl::*default-domain* doc))
455    `(progn    `(progn
456      (declaim (special ,var))      (declaim (special ,var))
457       ,@(when valp       ,@(when valp
458           `((unless (boundp ',var)           `((unless (boundp ',var)
459               (setq ,var ,val))))               (setq ,var ,val))))
460      ,@(when docp      ,@(when docp
461          `((setf (documentation ',var 'variable) ',doc)))          `((setf (documentation ',var 'variable) ',doc)
462              (eval-when (:load-toplevel :execute)
463                (set-defvar-textdomain ',var ,intl::*default-domain*))))
464      (set-defvar-source-location ',var (c::source-location))      (set-defvar-source-location ',var (c::source-location))
465      ',var))      ',var))
466    
# Line 437  Line 469 
469    but that may be changed without causing an error.  Declares the    but that may be changed without causing an error.  Declares the
470    variable special and sets its value to VAL.  The third argument is    variable special and sets its value to VAL.  The third argument is
471    an optional documentation string for the parameter."    an optional documentation string for the parameter."
472      (when docp
473        (intl::note-translatable intl::*default-domain* doc))
474    `(progn    `(progn
475      (declaim (special ,var))      (declaim (special ,var))
476      (setq ,var ,val)      (setq ,var ,val)
477      ,@(when docp      ,@(when docp
478          `((setf (documentation ',var 'variable) ',doc)))          `((setf (documentation ',var 'variable) ',doc)
479              (eval-when (:load-toplevel :execute)
480                (set-defvar-textdomain ',var ,intl::*default-domain*))))
481      (set-defvar-source-location ',var (c::source-location))      (set-defvar-source-location ',var (c::source-location))
482      ',var))      ',var))
483    
# Line 522  Line 558 
558        nil        nil
559        (let ((clause (first clauses)))        (let ((clause (first clauses)))
560          (when (atom clause)          (when (atom clause)
561            (error "Cond clause is not a list: ~S." clause))            (error (intl:gettext "Cond clause is not a list: ~S.") clause))
562          (let ((test (first clause))          (let ((test (first clause))
563                (forms (rest clause)))                (forms (rest clause)))
564            (if (endp forms)            (if (endp forms)
# Line 545  Line 581 
581  ;;;  ;;;
582  (defmacro multiple-value-setq (varlist value-form)  (defmacro multiple-value-setq (varlist value-form)
583    (unless (and (listp varlist) (every #'symbolp varlist))    (unless (and (listp varlist) (every #'symbolp varlist))
584      (simple-program-error "Varlist is not a list of symbols: ~S." varlist))      (simple-program-error (intl:gettext "Varlist is not a list of symbols: ~S.") varlist))
585    (if varlist    (if varlist
586        `(values (setf (values ,@varlist) ,value-form))        `(values (setf (values ,@varlist) ,value-form))
587        `(values ,value-form)))        `(values ,value-form)))
# Line 553  Line 589 
589  ;;;  ;;;
590  (defmacro multiple-value-bind (varlist value-form &body body)  (defmacro multiple-value-bind (varlist value-form &body body)
591    (unless (and (listp varlist) (every #'symbolp varlist))    (unless (and (listp varlist) (every #'symbolp varlist))
592      (simple-program-error  "Varlist is not a list of symbols: ~S." varlist))      (simple-program-error  (intl:gettext "Varlist is not a list of symbols: ~S.") varlist))
593    (if (= (length varlist) 1)    (if (= (length varlist) 1)
594        `(let ((,(car varlist) ,value-form))        `(let ((,(car varlist) ,value-form))
595           ,@body)           ,@body)
# Line 679  Line 715 
715        (temps value-forms store-vars store-form access-form)        (temps value-forms store-vars store-form access-form)
716        (get-setf-expansion form environment)        (get-setf-expansion form environment)
717      (when (cdr store-vars)      (when (cdr store-vars)
718        (error "GET-SETF-METHOD used for a form with multiple store ~        (error (intl:gettext "GET-SETF-METHOD used for a form with multiple store ~
719                variables:~%  ~S" form))                variables:~%  ~S") form))
720      (values temps value-forms store-vars store-form access-form)))      (values temps value-forms store-vars store-form access-form)))
721    
722    
# Line 691  Line 727 
727      (multiple-value-bind      (multiple-value-bind
728          (body local-decs doc)          (body local-decs doc)
729          (parse-defmacro arglist arglist-var (cddr rest) fn 'defsetf)          (parse-defmacro arglist arglist-var (cddr rest) fn 'defsetf)
730          (when doc
731            (intl::note-translatable intl::*default-domain* doc))
732        (values        (values
733         `(lambda (,arglist-var ,new-var)         `(lambda (,arglist-var ,new-var)
734            ,@local-decs            ,@local-decs
# Line 719  Line 757 
757                   (parse-defmacro `(,lambda-list ,@store-variables)                   (parse-defmacro `(,lambda-list ,@store-variables)
758                                   arglist-var body access-fn 'defsetf                                   arglist-var body access-fn 'defsetf
759                                   :annonymousp t)                                   :annonymousp t)
760                   (when doc
761                     (intl::note-translatable intl::*default-domain* doc))
762                 `(eval-when (load compile eval)                 `(eval-when (load compile eval)
763                    (%define-setf-macro                    (%define-setf-macro
764                     ',access-fn                     ',access-fn
# Line 732  Line 772 
772                     nil                     nil
773                     ',doc))))))                     ',doc))))))
774          (t          (t
775           (error "Ill-formed DEFSETF for ~S." access-fn))))           (error (intl:gettext "Ill-formed DEFSETF for ~S.") access-fn))))
776    
777  (defun %defsetf (orig-access-form num-store-vars expander)  (defun %defsetf (orig-access-form num-store-vars expander)
778    (collect ((subforms) (subform-vars) (subform-exprs) (store-vars))    (collect ((subforms) (subform-vars) (subform-exprs) (store-vars))
# Line 782  Line 822 
822                         (multiple-value-bind ,newval ,value-form                         (multiple-value-bind ,newval ,value-form
823                           ,setter))))))))                           ,setter))))))))
824       ((oddp nargs)       ((oddp nargs)
825        (error "Odd number of args to SETF."))        (error (intl:gettext "Odd number of args to SETF.")))
826       (t       (t
827        (do ((a args (cddr a)) (l nil))        (do ((a args (cddr a)) (l nil))
828            ((null a) `(progn ,@(nreverse l)))            ((null a) `(progn ,@(nreverse l)))
# Line 797  Line 837 
837      (do ((a args (cddr a)))      (do ((a args (cddr a)))
838          ((endp a))          ((endp a))
839        (if (endp (cdr a))        (if (endp (cdr a))
840            (simple-program-error "Odd number of args to PSETF."))            (simple-program-error (intl:gettext "Odd number of args to PSETF.")))
841        (multiple-value-bind        (multiple-value-bind
842            (dummies vals newval setter getter)            (dummies vals newval setter getter)
843            (get-setf-expansion (car a) env)            (get-setf-expansion (car a) env)
# Line 887  Line 927 
927    "Creates a new read-modify-write macro like PUSH or INCF."    "Creates a new read-modify-write macro like PUSH or INCF."
928    (let ((other-args nil)    (let ((other-args nil)
929          (rest-arg nil)          (rest-arg nil)
930          (env (gensym))          (env (gensym "ENV-"))
931          (reference (gensym)))          (reference (gensym "PLACE-")))
932    
933      ;; Parse out the variable names and rest arg from the lambda list.      ;; Parse out the variable names and rest arg from the lambda list.
934      (do ((ll lambda-list (cdr ll))      (do ((ll lambda-list (cdr ll))
# Line 899  Line 939 
939              ((eq arg '&rest)              ((eq arg '&rest)
940               (if (symbolp (cadr ll))               (if (symbolp (cadr ll))
941                   (setq rest-arg (cadr ll))                   (setq rest-arg (cadr ll))
942                   (error "Non-symbol &rest arg in definition of ~S." name))                   (error (intl:gettext "Non-symbol &rest arg in definition of ~S.") name))
943               (if (null (cddr ll))               (if (null (cddr ll))
944                   (return nil)                   (return nil)
945                   (error "Illegal stuff after &rest arg in Define-Modify-Macro.")))                   (error (intl:gettext "Illegal stuff after &rest arg in Define-Modify-Macro."))))
946              ((memq arg '(&key &allow-other-keys &aux))              ((memq arg '(&key &allow-other-keys &aux))
947               (error "~S not allowed in Define-Modify-Macro lambda list." arg))               (error (intl:gettext "~S not allowed in Define-Modify-Macro lambda list.") arg))
948              ((symbolp arg)              ((symbolp arg)
949               (push arg other-args))               (push arg other-args))
950              ((and (listp arg) (symbolp (car arg)))              ((and (listp arg) (symbolp (car arg)))
951               (push (car arg) other-args))               (push (car arg) other-args))
952              (t (error "Illegal stuff in lambda list of Define-Modify-Macro."))))              (t (error (intl:gettext "Illegal stuff in lambda list of Define-Modify-Macro.")))))
953      (setq other-args (nreverse other-args))      (setq other-args (nreverse other-args))
954      `(defmacro ,name (,reference ,@lambda-list &environment ,env)      `(defmacro ,name (,reference ,@lambda-list &environment ,env)
955         ,doc-string         ,doc-string
# Line 1060  Line 1100 
1100                    (,local2 nil ,local1))                    (,local2 nil ,local1))
1101                   ((atom ,local1) nil)                   ((atom ,local1) nil)
1102                 (cond ((atom (cdr ,local1))                 (cond ((atom (cdr ,local1))
1103                        (error "Odd-length property list in REMF."))                        (error (intl:gettext "Odd-length property list in REMF.")))
1104                       ((eq (car ,local1) ,ind-temp)                       ((eq (car ,local1) ,ind-temp)
1105                        (cond (,local2                        (cond (,local2
1106                               (rplacd (cdr ,local2) (cddr ,local1))                               (rplacd (cdr ,local2) (cddr ,local1))
# Line 1144  Line 1184 
1184  (defsetf sap-ref-sap %set-sap-ref-sap)  (defsetf sap-ref-sap %set-sap-ref-sap)
1185  (defsetf sap-ref-single %set-sap-ref-single)  (defsetf sap-ref-single %set-sap-ref-single)
1186  (defsetf sap-ref-double %set-sap-ref-double)  (defsetf sap-ref-double %set-sap-ref-double)
1187  #+long-float  #+(or x86 long-float)
1188  (defsetf sap-ref-long %set-sap-ref-long)  (defsetf sap-ref-long %set-sap-ref-long)
1189    
1190  (define-setf-expander getf (place prop &optional default &environment env)  (define-setf-expander getf (place prop &optional default &environment env)
# Line 1198  Line 1238 
1238                 (= (list-length function) 2)                 (= (list-length function) 2)
1239                 (eq (first function) 'function)                 (eq (first function) 'function)
1240                 (symbolp (second function)))                 (symbolp (second function)))
1241      (error "Setf of Apply is only defined for function args like #'symbol."))      (error (intl:gettext "Setf of Apply is only defined for function args like #'symbol.")))
1242    (let ((function (second function))    (let ((function (second function))
1243          (new-var (gensym))          (new-var (gensym))
1244          (vars nil))          (vars nil))
# Line 1314  Line 1354 
1354            (case (first case-list) (first case-list)))            (case (first case-list) (first case-list)))
1355           ((null case-list))           ((null case-list))
1356        (cond ((atom case)        (cond ((atom case)
1357               (error "~S -- Bad clause in ~S." case name))               (error (intl:gettext "~S -- Bad clause in ~S.") case name))
1358              ((and (not allow-otherwise)              ((and (not allow-otherwise)
1359                    (memq (car case) '(t otherwise)))                    (memq (car case) '(t otherwise)))
1360               (cond ((null (cdr case-list))               (cond ((null (cdr case-list))
# Line 1322  Line 1362 
1362                      ;; only if it's the last case.  Otherwise, it's just a                      ;; only if it's the last case.  Otherwise, it's just a
1363                      ;; normal clause.                      ;; normal clause.
1364                      (if errorp                      (if errorp
1365                          (error "No default clause allowed in ~S: ~S" name case)                          (error (intl:gettext "No default clause allowed in ~S: ~S") name case)
1366                          (push `(t nil ,@(rest case)) clauses)))                          (push `(t nil ,@(rest case)) clauses)))
1367                     ((and (eq name 'case))                     ((and (eq name 'case))
1368                      (error "T and OTHERWISE may not be used as key designators for ~A" name))                      (error (intl:gettext "T and OTHERWISE may not be used as key designators for ~A") name))
1369                     ((eq (first case) t)                     ((eq (first case) t)
1370                      ;; The key T is normal clause, because it's not                      ;; The key T is normal clause, because it's not
1371                      ;; the last clause.                      ;; the last clause.
# Line 1342  Line 1382 
1382              (t              (t
1383               (when (and allow-otherwise               (when (and allow-otherwise
1384                          (memq (car case) '(t otherwise)))                          (memq (car case) '(t otherwise)))
1385                 (warn "Bad style to use T or OTHERWISE in ECASE or CCASE"))                 (warn (intl:gettext "Bad style to use T or OTHERWISE in ECASE or CCASE")))
1386               (push (first case) keys)               (push (first case) keys)
1387               (push `((,test ,keyform-value               (push `((,test ,keyform-value
1388                              ',(first case)) nil ,@(rest case)) clauses))))                              ',(first case)) nil ,@(rest case)) clauses))))
# Line 1398  Line 1438 
1438               :possibilities keys)               :possibilities keys)
1439      (store-value (value)      (store-value (value)
1440        :report (lambda (stream)        :report (lambda (stream)
1441                  (format stream "Supply a new value for ~S." keyform))                  (format stream (intl:gettext "Supply a new value for ~S.") keyform))
1442        :interactive read-evaluated-form        :interactive read-evaluated-form
1443        value)))        value)))
1444    
1445    
1446  (defmacro case (keyform &body cases)  (defmacro case (keyform &body cases)
1447    "CASE Keyform {({(Key*) | Key} Form*)}*    "CASE Keyform {({(Key*) | Key} Form*)}*
1448    Evaluates the Forms in the first clause with a Key EQL to the value of    Evaluates the Forms in the first clause with a Key EQL to the value
1449    Keyform.  If a singleton key is T then the clause is a default clause."    of Keyform.  If a singleton key is T or Otherwise then the clause is
1450      a default clause."
1451    (case-body 'case keyform cases t 'eql nil nil))    (case-body 'case keyform cases t 'eql nil nil))
1452    
1453  (defmacro ccase (keyform &body cases)  (defmacro ccase (keyform &body cases)
# Line 1424  Line 1465 
1465    
1466  (defmacro typecase (keyform &body cases)  (defmacro typecase (keyform &body cases)
1467    "TYPECASE Keyform {(Type Form*)}*    "TYPECASE Keyform {(Type Form*)}*
1468    Evaluates the Forms in the first clause for which TYPEP of Keyform and Type    Evaluates the Forms in the first clause for which TYPEP of Keyform
1469    is true."    and Type is true.  If a singleton key is T or Otherwise then the
1470      clause is a default clause."
1471    (case-body 'typecase keyform cases nil 'typep nil nil))    (case-body 'typecase keyform cases nil 'typep nil nil))
1472    
1473  (defmacro ctypecase (keyform &body cases)  (defmacro ctypecase (keyform &body cases)
# Line 1465  Line 1507 
1507                     datum arguments                     datum arguments
1508                     'simple-error 'error)                     'simple-error 'error)
1509                    (make-condition 'simple-error                    (make-condition 'simple-error
1510                                    :format-control "The assertion ~S failed."                                    :format-control (intl:gettext "The assertion ~S failed.")
1511                                    :format-arguments (list assertion)))))                                    :format-arguments (list assertion)))))
1512    (restart-case (error cond)    (restart-case (error cond)
1513      (continue ()      (continue ()
# Line 1474  Line 1516 
1516    
1517    
1518  (defun assert-report (names stream)  (defun assert-report (names stream)
1519    (format stream "Retry assertion")    (format stream (intl:gettext "Retry assertion"))
1520    (if names    (if names
1521        (format stream " with new value~P for ~{~S~^, ~}."        (format stream (intl:ngettext " with new value for ~{~S~^, ~}."
1522                (length names) names)                                      " with new values for ~{~S~^, ~}."
1523                                        (length names))
1524                  names)
1525        (format stream ".")))        (format stream ".")))
1526    
1527  (defun assert-prompt (name value)  (defun assert-prompt (name value)
1528    (cond ((y-or-n-p "The old value of ~S is ~S.~    (cond ((y-or-n-p (intl:gettext "The old value of ~S is ~S.~
1529                    ~%Do you want to supply a new value? "                    ~%Do you want to supply a new value? ")
1530                     name value)                     name value)
1531           (format *query-io* "~&Type a form to be evaluated:~%")           (format *query-io* (intl:gettext "~&Type a form to be evaluated:~%"))
1532           (flet ((read-it () (eval (read *query-io*))))           (flet ((read-it () (eval (read *query-io*))))
1533             (if (symbolp name) ;help user debug lexical variables             (if (symbolp name) ;help user debug lexical variables
1534                 (progv (list name) (list value) (read-it))                 (progv (list name) (list value) (read-it))
# Line 1516  Line 1560 
1560                    (make-condition 'simple-type-error                    (make-condition 'simple-type-error
1561                                    :datum place-value :expected-type type                                    :datum place-value :expected-type type
1562                                    :format-control                                    :format-control
1563                                    "The value of ~S is ~S, which is not ~A."                                    (intl:gettext "The value of ~S is ~S, which is not ~A.")
1564                                    :format-arguments                                    :format-arguments
1565                                    (list place place-value type-string))                                    (list place place-value type-string))
1566                    (make-condition 'simple-type-error                    (make-condition 'simple-type-error
1567                                    :datum place-value :expected-type type                                    :datum place-value :expected-type type
1568                                    :format-control                                    :format-control
1569                                    "The value of ~S is ~S, which is not of type ~S."                                    (intl:gettext "The value of ~S is ~S, which is not of type ~S.")
1570                                    :format-arguments                                    :format-arguments
1571                                    (list place place-value type)))))                                    (list place place-value type)))))
1572      (restart-case (error cond)      (restart-case (error cond)
1573        (store-value (value)        (store-value (value)
1574          :report (lambda (stream)          :report (lambda (stream)
1575                    (format stream "Supply a new value of ~S."                    (format stream (intl:gettext "Supply a new value of ~S.")
1576                            place))                            place))
1577          :interactive read-evaluated-form          :interactive read-evaluated-form
1578          value))))          value))))
# Line 1538  Line 1582 
1582  ;;; and by CHECK-TYPE.  ;;; and by CHECK-TYPE.
1583  ;;;  ;;;
1584  (defun read-evaluated-form ()  (defun read-evaluated-form ()
1585    (format *query-io* "~&Type a form to be evaluated:~%")    (format *query-io* (intl:gettext "~&Type a form to be evaluated:~%"))
1586    (list (eval (read *query-io*))))    (list (eval (read *query-io*))))
1587    
1588    
1589  ;;;; With-XXX  ;;;; With-XXX
1590  (defmacro with-open-file ((var &rest open-args) &parse-body (forms decls))  (defmacro with-open-file ((var filespec &rest open-args) &parse-body (forms decls))
1591    "Bindspec is of the form (Stream File-Name . Options).  The file whose    "The file whose name is Filespec is opened using the Open-args and
1592     name is File-Name is opened using the Options and bound to the variable    bound to the variable Var. If the call to open is unsuccessful, the
1593     Stream. If the call to open is unsuccessful, the forms are not    forms are not evaluated.  The Forms are executed, and when they
1594     evaluated.  The Forms are executed, and when they    terminate, normally or otherwise, the file is closed."
    terminate, normally or otherwise, the file is closed."  
1595    (let ((abortp (gensym)))    (let ((abortp (gensym)))
1596      `(let ((,var (open ,@open-args))      `(let ((,var (open ,filespec ,@open-args))
1597             (,abortp t))             (,abortp t))
1598         ,@decls         ,@decls
1599         (unwind-protect         (unwind-protect
1600             (multiple-value-prog1              (multiple-value-prog1
1601                 (progn ,@forms)                  (progn ,@forms)
1602               (setq ,abortp nil))                (setq ,abortp nil))
1603           (when ,var           (when ,var
1604             (close ,var :abort ,abortp))))))             (close ,var :abort ,abortp))))))
1605    
# Line 1571  Line 1614 
1614         ,@decls         ,@decls
1615         (unwind-protect         (unwind-protect
1616           (multiple-value-prog1           (multiple-value-prog1
1617            (progn ,@forms)              (progn ,@forms)
1618            (setq ,abortp nil))            (setq ,abortp nil))
1619           (when ,var           (when ,var
1620             (close ,var :abort ,abortp))))))             (close ,var :abort ,abortp))))))
# Line 1623  Line 1666 
1666    
1667  ;;;; Iteration macros:  ;;;; Iteration macros:
1668    
1669    ;; Helper for dotimes.  Extract any declarations for the dotimes
1670    ;; counter and create a similar declaration for our dummy loop
1671    ;; counter.  Skip over special declarations, though, because we don't
1672    ;; want to make the dummy counter special.
1673    ;;
1674    ;; Returns two values:
1675    ;; 1.  Set of declarations for the dotimes loop counter that would be
1676    ;;     suitable for use in the result-form of the loop,
1677    ;; 2.  Declarations suitable for the dummy loop counter.
1678    (defun dotimes-extract-var-decls (var counter count decls)
1679      (let (var-decls counter-decls)
1680        (dolist (decl decls)
1681          (dolist (d (cdr decl))
1682            (when (member var (cdr d))
1683              (cond ((eq (car d) 'type)
1684                     (push `(type ,(second d) ,var) var-decls)
1685                     (push `(type ,(second d) ,counter) counter-decls))
1686                    ((eq (car d) 'special)
1687                     ;; Declare var special, but not the counter
1688                     (push `(,(car d) ,var) var-decls))
1689                    (t
1690                     (push `(,(car d) ,var) var-decls)
1691                     (push `(,(car d) ,counter) counter-decls))))))
1692        (unless counter-decls
1693          (setf counter-decls (if (numberp count)
1694                                  `((type (integer 0 ,count) ,counter))
1695                                  `((type unsigned-byte ,counter)))))
1696        (values (if var-decls
1697                    `((declare ,@(nreverse var-decls)))
1698                    nil)
1699                `((declare ,@(nreverse counter-decls))))))
1700    
1701    
1702  ;;; Make sure we iterate the given number of times, independent of  ;;; Make sure we iterate the given number of times, independent of
1703  ;;; what the body might do to the index variable.  We do this by  ;;; what the body might do to the index variable.  We do this by
1704  ;;; repeatedly binding the var in the body and also in the result  ;;; repeatedly binding the var in the body and also in the result
# Line 1633  Line 1709 
1709    (let ((count-var (gensym "CTR-")))    (let ((count-var (gensym "CTR-")))
1710      (multiple-value-bind (forms decls)      (multiple-value-bind (forms decls)
1711          (parse-body body nil nil)          (parse-body body nil nil)
1712        (cond ((numberp count)        (multiple-value-bind (var-decls ctr-decls)
1713               `(do ((,count-var 0 (1+ ,count-var)))            (dotimes-extract-var-decls var count-var count decls)
1714                    ((>= ,count-var ,count)          (cond ((numberp count)
1715                     (let ((,var ,count-var))                 `(do ((,count-var 0 (1+ ,count-var)))
1716                       ,var                      ((>= ,count-var ,count)
1717                       ,result))                       (let ((,var ,count-var))
1718                  (declare (type (integer 0 ,count) ,count-var))                         ,@var-decls
1719                  (let ((,var ,count-var))                         ,var
1720                    ,@decls                         ,result))
1721                    ,var                    ,@ctr-decls
1722                    (tagbody                    (let ((,var ,count-var))
1723                       ,@forms))))                      ,@decls
1724              (t (let ((v1 (gensym)))                      ,var
1725                   `(do ((,count-var 0 (1+ ,count-var))                      (tagbody
1726                         (,v1 ,count))                         ,@forms))))
1727                        ((>= ,count-var ,v1)                (t (let ((v1 (gensym)))
1728                         (let ((,var ,count-var))                     `(do ((,count-var 0 (1+ ,count-var))
1729                           ,var                           (,v1 ,count))
1730                           ,result))                          ((>= ,count-var ,v1)
1731                      (declare (type unsigned-byte ,count-var))                           (let ((,var ,count-var))
1732                      (let ((,var ,count-var))                             ,@var-decls
1733                        ,@decls                             ,var
1734                        ,var                             ,result))
1735                        (tagbody                        ,@ctr-decls
1736                           ,@forms)))))))))                        (let ((,var ,count-var))
1737                            ,@decls
1738                            ,var
1739                            (tagbody
1740                               ,@forms))))))))))
1741    
1742    
1743  ;;; We repeatedly bind the var instead of setting it so that we never give the  ;;; We repeatedly bind the var instead of setting it so that we never give the
# Line 1724  Line 1804 
1804        ((endp pair) `(psetf ,@pairs))        ((endp pair) `(psetf ,@pairs))
1805      (unless (symbolp (car pair))      (unless (symbolp (car pair))
1806        (error 'simple-program-error        (error 'simple-program-error
1807               :format-control "variable ~S in PSETQ is not a SYMBOL"               :format-control (intl:gettext "variable ~S in PSETQ is not a SYMBOL")
1808               :format-arguments (list (car pair))))))               :format-arguments (list (car pair))))))
1809    
1810    
# Line 1776  Line 1856 
1856                (:global (member parent '(defun defmacro function)))                (:global (member parent '(defun defmacro function)))
1857                (:local (member parent '(labels flet)))                (:local (member parent '(labels flet)))
1858                (t                (t
1859                 (error "Unknown declaration context: ~S." context))))                 (error (intl:gettext "Unknown declaration context: ~S.") context))))
1860            (case (first context)            (case (first context)
1861              (:or              (:or
1862               (loop for x in (rest context)               (loop for x in (rest context)
# Line 1797  Line 1877 
1877                    (loop for x in (rest context)                    (loop for x in (rest context)
1878                          thereis (eq (find-package (string x)) package))))                          thereis (eq (find-package (string x)) package))))
1879              (t              (t
1880               (error "Unknown declaration context: ~S." context)))))))               (error (intl:gettext "Unknown declaration context: ~S.") context)))))))
1881    
1882    
1883  ;;; PROCESS-CONTEXT-DECLARATIONS  --  Internal  ;;; PROCESS-CONTEXT-DECLARATIONS  --  Internal
# Line 1810  Line 1890 
1890     (mapcar     (mapcar
1891      #'(lambda (decl)      #'(lambda (decl)
1892          (unless (>= (length decl) 2)          (unless (>= (length decl) 2)
1893            (error "Context declaration spec should have context and at ~            (error (intl:gettext "Context declaration spec should have context and at ~
1894            least one DECLARE form:~%  ~S" decl))            least one DECLARE form:~%  ~S") decl))
1895          #'(lambda (name parent)          #'(lambda (name parent)
1896              (when (evaluate-declaration-context (first decl) name parent)              (when (evaluate-declaration-context (first decl) name parent)
1897                (rest decl))))                (rest decl))))
# Line 1884  Line 1964 
1964          (n-fun (gensym))          (n-fun (gensym))
1965          (n-abort-p (gensym)))          (n-abort-p (gensym)))
1966      (when (oddp (length options))      (when (oddp (length options))
1967        (error "Odd number of key/value pairs: ~S." options))        (error (intl:gettext "Odd number of key/value pairs: ~S.") options))
1968      (do ((opt options (cddr opt)))      (do ((opt options (cddr opt)))
1969          ((null opt))          ((null opt))
1970        (case (first opt)        (case (first opt)
# Line 1897  Line 1977 
1977          (:context-declarations          (:context-declarations
1978           (setq context-declarations (second opt)))           (setq context-declarations (second opt)))
1979          (t          (t
1980           (warn "Ignoring unknown option: ~S." (first opt)))))           (warn (intl:gettext "Ignoring unknown option: ~S.") (first opt)))))
1981    
1982      `(flet ((,n-fun ()      `(flet ((,n-fun ()
1983                (let (,@(when optimize                (let (,@(when optimize

Legend:
Removed from v.1.103.2.1  
changed lines
  Added in v.1.120

  ViewVC Help
Powered by ViewVC 1.1.5