0.pre7.50:
[sbcl.git] / src / code / early-setf.lisp
1 ;;;; SETF and friends (except for stuff defined with COLLECT, which
2 ;;;; comes later)
3 ;;;;
4 ;;;; Note: The expansions for SETF and friends sometimes create
5 ;;;; needless LET-bindings of argument values. The compiler will
6 ;;;; remove most of these spurious bindings, so SETF doesn't worry too
7 ;;;; much about creating them.
8
9 ;;;; This software is part of the SBCL system. See the README file for
10 ;;;; more information.
11 ;;;;
12 ;;;; This software is derived from the CMU CL system, which was
13 ;;;; written at Carnegie Mellon University and released into the
14 ;;;; public domain. The software is in the public domain and is
15 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
16 ;;;; files for more information.
17
18 (in-package "SB!IMPL")
19
20 ;;; The inverse for a generalized-variable reference function is stored in
21 ;;; one of two ways:
22 ;;;
23 ;;; A SETF inverse property corresponds to the short form of DEFSETF. It is
24 ;;; the name of a function takes the same args as the reference form, plus a
25 ;;; new-value arg at the end.
26 ;;;
27 ;;; A SETF method expander is created by the long form of DEFSETF or
28 ;;; by DEFINE-SETF-EXPANDER. It is a function that is called on the reference
29 ;;; form and that produces five values: a list of temporary variables, a list
30 ;;; of value forms, a list of the single store-value form, a storing function,
31 ;;; and an accessing function.
32 (declaim (ftype (function (t &optional (or null sb!c::lexenv))) sb!xc:get-setf-expansion))
33 (defun sb!xc:get-setf-expansion (form &optional environment)
34   #!+sb-doc
35   "Return five values needed by the SETF machinery: a list of temporary
36    variables, a list of values with which to fill them, a list of temporaries
37    for the new values, the setting function, and the accessing function."
38   (let (temp)
39     (cond ((symbolp form)
40            (multiple-value-bind (expansion expanded)
41                (sb!xc:macroexpand-1 form environment)
42              (if expanded
43                  (sb!xc:get-setf-expansion expansion environment)
44                  (let ((new-var (gensym)))
45                    (values nil nil (list new-var)
46                            `(setq ,form ,new-var) form)))))
47           ;; Local functions inhibit global SETF methods.
48           ((and environment
49                 (let ((name (car form)))
50                   (dolist (x (sb!c::lexenv-functions environment))
51                     (when (and (eq (car x) name)
52                                (not (sb!c::defined-function-p (cdr x))))
53                       (return t)))))
54            (expand-or-get-setf-inverse form environment))
55           ((setq temp (info :setf :inverse (car form)))
56            (get-setf-method-inverse form `(,temp) nil))
57           ((setq temp (info :setf :expander (car form)))
58            ;; KLUDGE: It may seem as though this should go through
59            ;; *MACROEXPAND-HOOK*, but the ANSI spec seems fairly explicit
60            ;; that *MACROEXPAND-HOOK* is a hook for MACROEXPAND-1, not
61            ;; for macroexpansion in general. -- WHN 19991128
62            (funcall temp
63                     form
64                     ;; As near as I can tell from the ANSI spec,
65                     ;; macroexpanders have a right to expect an actual
66                     ;; lexical environment, not just a NIL which is to
67                     ;; be interpreted as a null lexical environment.
68                     ;; -- WHN 19991128
69                     (coerce-to-lexenv environment)))
70           (t
71            (expand-or-get-setf-inverse form environment)))))
72
73 ;;; GET-SETF-METHOD existed in pre-ANSI Common Lisp, and various code inherited
74 ;;; from CMU CL uses it repeatedly, so rather than rewrite a lot of code to not
75 ;;; use it, we just define it in terms of ANSI's GET-SETF-EXPANSION (or
76 ;;; actually, the cross-compiler version of that, i.e.
77 ;;; SB!XC:GET-SETF-EXPANSION).
78 (declaim (ftype (function (t &optional (or null sb!c::lexenv))) get-setf-method))
79 (defun get-setf-method (form &optional environment)
80   #!+sb-doc
81   "This is a specialized-for-one-value version of GET-SETF-EXPANSION (and
82 a relic from pre-ANSI Common Lisp). Portable ANSI code should use
83 GET-SETF-EXPANSION directly."
84   (multiple-value-bind (temps value-forms store-vars store-form access-form)
85       (sb!xc:get-setf-expansion form environment)
86     (when (cdr store-vars)
87       (error "GET-SETF-METHOD used for a form with multiple store ~
88               variables:~%  ~S"
89              form))
90     (values temps value-forms store-vars store-form access-form)))
91
92 ;;; If a macro, expand one level and try again. If not, go for the
93 ;;; SETF function.
94 (declaim (ftype (function (t sb!c::lexenv)) expand-or-get-setf-inverse))
95 (defun expand-or-get-setf-inverse (form environment)
96   (multiple-value-bind (expansion expanded)
97       (sb!xc:macroexpand-1 form environment)
98     (if expanded
99         (sb!xc:get-setf-expansion expansion environment)
100         (get-setf-method-inverse form
101                                  `(funcall #'(setf ,(car form)))
102                                  t))))
103
104 (defun get-setf-method-inverse (form inverse setf-function)
105   (let ((new-var (gensym))
106         (vars nil)
107         (vals nil))
108     (dolist (x (cdr form))
109       (push (gensym) vars)
110       (push x vals))
111     (setq vals (nreverse vals))
112     (values vars vals (list new-var)
113             (if setf-function
114                 `(,@inverse ,new-var ,@vars)
115                 `(,@inverse ,@vars ,new-var))
116             `(,(car form) ,@vars))))
117 \f
118 ;;;; SETF itself
119
120 ;;; Except for atoms, we always call GET-SETF-EXPANSION, since it has some
121 ;;; non-trivial semantics. But when there is a setf inverse, and G-S-E uses
122 ;;; it, then we return a call to the inverse, rather than returning a hairy let
123 ;;; form. This is probably important mainly as a convenience in allowing the
124 ;;; use of SETF inverses without the full interpreter.
125 (defmacro-mundanely setf (&rest args &environment env)
126   #!+sb-doc
127   "Takes pairs of arguments like SETQ. The first is a place and the second
128   is the value that is supposed to go into that place. Returns the last
129   value. The place argument may be any of the access forms for which SETF
130   knows a corresponding setting form."
131   (let ((nargs (length args)))
132     (cond
133      ((= nargs 2)
134       (let ((place (first args))
135             (value-form (second args)))
136         (if (atom place)
137           `(setq ,place ,value-form)
138           (multiple-value-bind (dummies vals newval setter getter)
139               (sb!xc:get-setf-expansion place env)
140             (declare (ignore getter))
141             (let ((inverse (info :setf :inverse (car place))))
142               (if (and inverse (eq inverse (car setter)))
143                 `(,inverse ,@(cdr place) ,value-form)
144                 `(let* (,@(mapcar #'list dummies vals))
145                    (multiple-value-bind ,newval ,value-form
146                      ,setter))))))))
147      ((oddp nargs)
148       (error "odd number of args to SETF"))
149      (t
150       (do ((a args (cddr a))
151            (reversed-setfs nil))
152           ((null a)
153            `(progn ,@(nreverse reversed-setfs)))
154         (push (list 'setf (car a) (cadr a)) reversed-setfs))))))
155 \f
156 ;;;; various SETF-related macros
157
158 (defmacro-mundanely shiftf (&whole form &rest args &environment env)
159   #!+sb-doc
160   "One or more SETF-style place expressions, followed by a single
161    value expression. Evaluates all of the expressions in turn, then
162    assigns the value of each expression to the place on its left,
163    returning the value of the leftmost."
164   (when (< (length args) 2)
165     (error "~S called with too few arguments: ~S" 'shiftf form))
166   (let ((resultvar (gensym)))
167     (do ((arglist args (cdr arglist))
168          (bindlist nil)
169          (storelist nil)
170          (lastvar resultvar))
171         ((atom (cdr arglist))
172          (push `(,lastvar ,(first arglist)) bindlist)
173          `(let* ,(nreverse bindlist) ,@(nreverse storelist) ,resultvar))
174       (multiple-value-bind (sm1 sm2 sm3 sm4 sm5)
175           (get-setf-method (first arglist) env)
176         (mapc #'(lambda (var val)
177                   (push `(,var ,val) bindlist))
178               sm1
179               sm2)
180         (push `(,lastvar ,sm5) bindlist)
181         (push sm4 storelist)
182         (setq lastvar (first sm3))))))
183
184 (defmacro-mundanely push (obj place &environment env)
185   #!+sb-doc
186   "Takes an object and a location holding a list. Conses the object onto
187   the list, returning the modified list. OBJ is evaluated before PLACE."
188   (if (symbolp place)
189       `(setq ,place (cons ,obj ,place))
190       (multiple-value-bind
191           (dummies vals newval setter getter)
192           (get-setf-method place env)
193         (let ((g (gensym)))
194           `(let* ((,g ,obj)
195                   ,@(mapcar #'list dummies vals)
196                   (,(car newval) (cons ,g ,getter)))
197             ,setter)))))
198
199 (defmacro-mundanely pushnew (obj place &rest keys &environment env)
200   #!+sb-doc
201   "Takes an object and a location holding a list. If the object is already
202   in the list, does nothing. Else, conses the object onto the list. Returns
203   NIL. If there is a :TEST keyword, this is used for the comparison."
204   (if (symbolp place)
205       `(setq ,place (adjoin ,obj ,place ,@keys))
206       (multiple-value-bind (dummies vals newval setter getter)
207           (get-setf-method place env)
208         (do* ((d dummies (cdr d))
209               (v vals (cdr v))
210               (let-list nil))
211              ((null d)
212               (push (list (car newval) `(adjoin ,obj ,getter ,@keys))
213                     let-list)
214               `(let* ,(nreverse let-list)
215                  ,setter))
216           (push (list (car d) (car v)) let-list)))))
217
218 (defmacro-mundanely pop (place &environment env)
219   #!+sb-doc
220   "The argument is a location holding a list. Pops one item off the front
221   of the list and returns it."
222   (if (symbolp place)
223       `(prog1 (car ,place) (setq ,place (cdr ,place)))
224       (multiple-value-bind (dummies vals newval setter getter)
225           (get-setf-method place env)
226         (do* ((d dummies (cdr d))
227               (v vals (cdr v))
228               (let-list nil))
229              ((null d)
230               (push (list (car newval) getter) let-list)
231               `(let* ,(nreverse let-list)
232                  (prog1 (car ,(car newval))
233                         (setq ,(car newval) (cdr ,(car newval)))
234                         ,setter)))
235           (push (list (car d) (car v)) let-list)))))
236
237 (defmacro-mundanely remf (place indicator &environment env)
238   #!+sb-doc
239   "Place may be any place expression acceptable to SETF, and is expected
240   to hold a property list or (). This list is destructively altered to
241   remove the property specified by the indicator. Returns T if such a
242   property was present, NIL if not."
243   (multiple-value-bind (dummies vals newval setter getter)
244       (get-setf-method place env)
245     (do* ((d dummies (cdr d))
246           (v vals (cdr v))
247           (let-list nil)
248           (ind-temp (gensym))
249           (local1 (gensym))
250           (local2 (gensym)))
251          ((null d)
252           (push (list (car newval) getter) let-list)
253           (push (list ind-temp indicator) let-list)
254           `(let* ,(nreverse let-list)
255              (do ((,local1 ,(car newval) (cddr ,local1))
256                   (,local2 nil ,local1))
257                  ((atom ,local1) nil)
258                (cond ((atom (cdr ,local1))
259                       (error "Odd-length property list in REMF."))
260                      ((eq (car ,local1) ,ind-temp)
261                       (cond (,local2
262                              (rplacd (cdr ,local2) (cddr ,local1))
263                              (return t))
264                             (t (setq ,(car newval) (cddr ,(car newval)))
265                                ,setter
266                                (return t))))))))
267       (push (list (car d) (car v)) let-list))))
268 \f
269 ;;;; DEFINE-MODIFY-MACRO stuff
270
271 (def!macro sb!xc:define-modify-macro (name lambda-list function &optional doc-string)
272   #!+sb-doc
273   "Creates a new read-modify-write macro like PUSH or INCF."
274   (let ((other-args nil)
275         (rest-arg nil)
276         (env (gensym))
277         (reference (gensym)))
278     ;; Parse out the variable names and &REST arg from the lambda list.
279     (do ((ll lambda-list (cdr ll))
280          (arg nil))
281         ((null ll))
282       (setq arg (car ll))
283       (cond ((eq arg '&optional))
284             ((eq arg '&rest)
285              (if (symbolp (cadr ll))
286                (setq rest-arg (cadr ll))
287                (error "Non-symbol &REST argument in definition of ~S." name))
288              (if (null (cddr ll))
289                (return nil)
290                (error "Illegal stuff after &REST argument.")))
291             ((memq arg '(&key &allow-other-keys &aux))
292              (error "~S not allowed in DEFINE-MODIFY-MACRO lambda list." arg))
293             ((symbolp arg)
294              (push arg other-args))
295             ((and (listp arg) (symbolp (car arg)))
296              (push (car arg) other-args))
297             (t (error "Illegal stuff in lambda list."))))
298     (setq other-args (nreverse other-args))
299     `(#-sb-xc-host sb!xc:defmacro
300       #+sb-xc-host defmacro-mundanely
301          ,name (,reference ,@lambda-list &environment ,env)
302        ,doc-string
303        (multiple-value-bind (dummies vals newval setter getter)
304            (get-setf-method ,reference ,env)
305          (do ((d dummies (cdr d))
306               (v vals (cdr v))
307               (let-list nil (cons (list (car d) (car v)) let-list)))
308              ((null d)
309               (push (list (car newval)
310                           ,(if rest-arg
311                              `(list* ',function getter ,@other-args ,rest-arg)
312                              `(list ',function getter ,@other-args)))
313                     let-list)
314               `(let* ,(nreverse let-list)
315                  ,setter)))))))
316
317 (sb!xc:define-modify-macro incf (&optional (delta 1)) +
318   #!+sb-doc
319   "The first argument is some location holding a number. This number is
320   incremented by the second argument, DELTA, which defaults to 1.")
321
322 (sb!xc:define-modify-macro decf (&optional (delta 1)) -
323   #!+sb-doc
324   "The first argument is some location holding a number. This number is
325   decremented by the second argument, DELTA, which defaults to 1.")
326 \f
327 ;;;; DEFSETF
328
329 (eval-when (#-sb-xc :compile-toplevel :load-toplevel :execute)
330   ;;; Assign SETF macro information for NAME, making all appropriate checks.
331   (defun assign-setf-macro (name expander inverse doc)
332     (cond ((gethash name sb!c:*setf-assumed-fboundp*)
333            (warn
334             "defining setf macro for ~S when ~S was previously ~
335              treated as a function"
336             name
337             `(setf ,name)))
338           ((not (fboundp `(setf ,name)))
339            ;; All is well, we don't need any warnings.
340            (values))
341           ((info :function :accessor-for name)
342            (warn "defining SETF macro for DEFSTRUCT slot ~
343                  accessor; redefining as a normal function: ~S"
344                  name)
345            (proclaim-as-function-name name))
346           ((not (eq (symbol-package name) (symbol-package 'aref)))
347            (style-warn "defining setf macro for ~S when ~S is fbound"
348                        name `(setf ,name))))
349     (remhash name sb!c:*setf-assumed-fboundp*)
350     ;; FIXME: It's probably possible to join these checks into one form which
351     ;; is appropriate both on the cross-compilation host and on the target.
352     (when (or inverse (info :setf :inverse name))
353       (setf (info :setf :inverse name) inverse))
354     (when (or expander (info :setf :expander name))
355       (setf (info :setf :expander name) expander))
356     (when doc
357       (setf (fdocumentation name 'setf) doc))
358     name))
359
360 (def!macro sb!xc:defsetf (access-fn &rest rest)
361   #!+sb-doc
362   "Associates a SETF update function or macro with the specified access
363   function or macro. The format is complex. See the manual for details."
364   (cond ((not (listp (car rest)))
365          `(eval-when (:load-toplevel :compile-toplevel :execute)
366             (assign-setf-macro ',access-fn
367                                nil
368                                ',(car rest)
369                                 ,(when (and (car rest) (stringp (cadr rest)))
370                                    `',(cadr rest)))))
371         ((and (cdr rest) (listp (cadr rest)))
372          (destructuring-bind
373              (lambda-list (&rest store-variables) &body body)
374              rest
375            (let ((arglist-var (gensym "ARGS-"))
376                  (access-form-var (gensym "ACCESS-FORM-"))
377                  (env-var (gensym "ENVIRONMENT-")))
378              (multiple-value-bind (body local-decs doc)
379                  (parse-defmacro `(,lambda-list ,@store-variables)
380                                  arglist-var body access-fn 'defsetf
381                                  :anonymousp t)
382                `(eval-when (:compile-toplevel :load-toplevel :execute)
383                   (assign-setf-macro
384                    ',access-fn
385                    #'(lambda (,access-form-var ,env-var)
386                        (declare (ignore ,env-var))
387                        (%defsetf ,access-form-var ,(length store-variables)
388                                  #'(lambda (,arglist-var)
389                                      ,@local-decs
390                                      (block ,access-fn
391                                        ,body))))
392                    nil
393                    ',doc))))))
394         (t
395          (error "ill-formed DEFSETF for ~S" access-fn))))
396
397 (defun %defsetf (orig-access-form num-store-vars expander)
398   (let (subforms
399         subform-vars
400         subform-exprs
401         store-vars)
402     (dolist (subform (cdr orig-access-form))
403       (if (constantp subform)
404         (push subform subforms)
405         (let ((var (gensym)))
406           (push var subforms)
407           (push var subform-vars)
408           (push subform subform-exprs))))
409     (dotimes (i num-store-vars)
410       (push (gensym) store-vars))
411     (let ((r-subforms (nreverse subforms))
412           (r-subform-vars (nreverse subform-vars))
413           (r-subform-exprs (nreverse subform-exprs))
414           (r-store-vars (nreverse store-vars)))
415       (values r-subform-vars
416               r-subform-exprs
417               r-store-vars
418               (funcall expander (cons r-subforms r-store-vars))
419               `(,(car orig-access-form) ,@r-subforms)))))
420 \f
421 ;;;; DEFMACRO DEFINE-SETF-EXPANDER and various DEFINE-SETF-EXPANDERs
422
423 ;;; DEFINE-SETF-EXPANDER is a lot like DEFMACRO.
424 (def!macro sb!xc:define-setf-expander (access-fn lambda-list &body body)
425   #!+sb-doc
426   "Syntax like DEFMACRO, but creates a Setf-Method generator. The body
427   must be a form that returns the five magical values."
428   (unless (symbolp access-fn)
429     (error "DEFINE-SETF-EXPANDER access-function name ~S is not a symbol."
430            access-fn))
431   (let ((whole (gensym "WHOLE-"))
432         (environment (gensym "ENV-")))
433     (multiple-value-bind (body local-decs doc)
434         (parse-defmacro lambda-list whole body access-fn
435                         'sb!xc:define-setf-expander
436                         :environment environment)
437       `(eval-when (:compile-toplevel :load-toplevel :execute)
438          (assign-setf-macro ',access-fn
439                             #'(lambda (,whole ,environment)
440                                 ,@local-decs
441                                 (block ,access-fn ,body))
442                             nil
443                             ',doc)))))
444
445 (sb!xc:define-setf-expander getf (place prop
446                                   &optional default
447                                   &environment env)
448   (declare (type sb!c::lexenv env))
449   (multiple-value-bind (temps values stores set get)
450       (get-setf-method place env)
451     (let ((newval (gensym))
452           (ptemp (gensym))
453           (def-temp (if default (gensym))))
454       (values `(,@temps ,ptemp ,@(if default `(,def-temp)))
455               `(,@values ,prop ,@(if default `(,default)))
456               `(,newval)
457               `(let ((,(car stores) (%putf ,get ,ptemp ,newval)))
458                  ,set
459                  ,newval)
460               `(getf ,get ,ptemp ,@(if default `(,def-temp)))))))
461
462 (sb!xc:define-setf-expander get (symbol prop &optional default)
463   (let ((symbol-temp (gensym))
464         (prop-temp (gensym))
465         (def-temp (gensym))
466         (newval (gensym)))
467     (values `(,symbol-temp ,prop-temp ,@(if default `(,def-temp)))
468             `(,symbol ,prop ,@(if default `(,default)))
469             (list newval)
470             `(%put ,symbol-temp ,prop-temp ,newval)
471             `(get ,symbol-temp ,prop-temp ,@(if default `(,def-temp))))))
472
473 (sb!xc:define-setf-expander gethash (key hashtable &optional default)
474   (let ((key-temp (gensym))
475         (hashtable-temp (gensym))
476         (default-temp (gensym))
477         (new-value-temp (gensym)))
478     (values
479      `(,key-temp ,hashtable-temp ,@(if default `(,default-temp)))
480      `(,key ,hashtable ,@(if default `(,default)))
481      `(,new-value-temp)
482      `(%puthash ,key-temp ,hashtable-temp ,new-value-temp)
483      `(gethash ,key-temp ,hashtable-temp ,@(if default `(,default-temp))))))
484
485 (sb!xc:define-setf-expander logbitp (index int &environment env)
486   (declare (type sb!c::lexenv env))
487   (multiple-value-bind (temps vals stores store-form access-form)
488       (get-setf-method int env)
489     (let ((ind (gensym))
490           (store (gensym))
491           (stemp (first stores)))
492       (values `(,ind ,@temps)
493               `(,index
494                 ,@vals)
495               (list store)
496               `(let ((,stemp
497                       (dpb (if ,store 1 0) (byte 1 ,ind) ,access-form)))
498                  ,store-form
499                  ,store)
500               `(logbitp ,ind ,access-form)))))
501
502 ;;; CMU CL had a comment here that:
503 ;;;   Evil hack invented by the gnomes of Vassar Street (though not as evil as
504 ;;;   it used to be.)  The function arg must be constant, and is converted to
505 ;;;   an APPLY of the SETF function, which ought to exist.
506 ;;;
507 ;;; It may not be clear (wasn't to me..) that this is a standard thing, but See
508 ;;; "5.1.2.5 APPLY Forms as Places" in the ANSI spec. I haven't actually
509 ;;; verified that this code has any correspondence to that code, but at least
510 ;;; ANSI has some place for SETF APPLY. -- WHN 19990604
511 (sb!xc:define-setf-expander apply (functionoid &rest args)
512   (unless (and (listp functionoid)
513                (= (length functionoid) 2)
514                (eq (first functionoid) 'function)
515                (symbolp (second functionoid)))
516     (error "SETF of APPLY is only defined for function args like #'SYMBOL."))
517   (let ((function (second functionoid))
518         (new-var (gensym))
519         (vars (make-gensym-list (length args))))
520     (values vars args (list new-var)
521             `(apply #'(setf ,function) ,new-var ,@vars)
522             `(apply #',function ,@vars))))
523
524 ;;; Special-case a BYTE bytespec so that the compiler can recognize it.
525 (sb!xc:define-setf-expander ldb (bytespec place &environment env)
526   #!+sb-doc
527   "The first argument is a byte specifier. The second is any place form
528   acceptable to SETF. Replace the specified byte of the number in this
529   place with bits from the low-order end of the new value."
530   (declare (type sb!c::lexenv env))
531   (multiple-value-bind (dummies vals newval setter getter)
532       (get-setf-method place env)
533     (if (and (consp bytespec) (eq (car bytespec) 'byte))
534         (let ((n-size (gensym))
535               (n-pos (gensym))
536               (n-new (gensym)))
537           (values (list* n-size n-pos dummies)
538                   (list* (second bytespec) (third bytespec) vals)
539                   (list n-new)
540                   `(let ((,(car newval) (dpb ,n-new (byte ,n-size ,n-pos)
541                                              ,getter)))
542                      ,setter
543                      ,n-new)
544                   `(ldb (byte ,n-size ,n-pos) ,getter)))
545         (let ((btemp (gensym))
546               (gnuval (gensym)))
547           (values (cons btemp dummies)
548                   (cons bytespec vals)
549                   (list gnuval)
550                   `(let ((,(car newval) (dpb ,gnuval ,btemp ,getter)))
551                      ,setter
552                      ,gnuval)
553                   `(ldb ,btemp ,getter))))))
554
555 (sb!xc:define-setf-expander mask-field (bytespec place &environment env)
556   #!+sb-doc
557   "The first argument is a byte specifier. The second is any place form
558   acceptable to SETF. Replaces the specified byte of the number in this place
559   with bits from the corresponding position in the new value."
560   (declare (type sb!c::lexenv env))
561   (multiple-value-bind (dummies vals newval setter getter)
562       (get-setf-method place env)
563     (let ((btemp (gensym))
564           (gnuval (gensym)))
565       (values (cons btemp dummies)
566               (cons bytespec vals)
567               (list gnuval)
568               `(let ((,(car newval) (deposit-field ,gnuval ,btemp ,getter)))
569                  ,setter
570                  ,gnuval)
571               `(mask-field ,btemp ,getter)))))
572
573 (sb!xc:define-setf-expander the (type place &environment env)
574   (declare (type sb!c::lexenv env))
575   (multiple-value-bind (dummies vals newval setter getter)
576       (get-setf-method place env)
577     (values dummies
578               vals
579               newval
580               (subst `(the ,type ,(car newval)) (car newval) setter)
581               `(the ,type ,getter))))