[cffi-devel] Re: setf-expander of FOREIGN-SLOT-VALUE
Marco Gidde
marco.gidde at tiscali.de
Sat Sep 24 21:26:02 UTC 2005
At least two more expanders should also be corrected:
(define-setf-expander mem-ref (ptr type &optional (offset 0) &environment env)
"SETF expander for MEM-REF that doesn't rebind TYPE.
This is necessary for the compiler macro on MEM-SET to be able
to open-code (SETF MEM-REF) forms."
(multiple-value-bind (temps vals stores store-form access-form)
(get-setf-expansion ptr env)
(declare (ignore store-form stores))
(let ((type-tmp (gensym "TYPE-"))
(offset-tmp (gensym "OFFSET-"))
(store (gensym "STORE-")))
(values
`(,type-tmp ,offset-tmp , at temps)
`(,type ,offset , at vals)
`(,store)
`(progn
(mem-set ,store ,access-form ,type-tmp ,offset-tmp)
,store)
`(mem-ref ,access-form ,type-tmp ,offset-tmp)))))
(define-setf-expander mem-aref (ptr type &optional (index 0) &environment env)
"SETF expander for MEM-AREF."
(multiple-value-bind (temps vals stores store-form access-form)
(get-setf-expansion ptr env)
(declare (ignore store-form stores))
(let ((type-tmp (gensym "TYPE-"))
(index-tmp (gensym "INDEX-"))
(store (gensym "STORE-")))
(values
`(,type-tmp ,index-tmp , at temps)
`(,type ,index , at vals)
`(,store)
`(progn
,(if (constantp type)
(if (constantp index)
`(mem-set ,store ,access-form ,type-tmp
,(* (eval index) (foreign-type-size (eval type))))
`(mem-set ,store ,access-form ,type-tmp
(* ,index-tmp ,(foreign-type-size (eval type)))))
`(mem-set ,store ,access-form ,type-tmp
(* ,index-tmp (foreign-type-size ,type-tmp))))
,store)
`(mem-aref ,access-form ,type-tmp ,index-tmp)))))
I guess the implementation dependend setf-expanders for %mem-ref
should also be adapted. It's quite easy: instead of the first example
in the CLHS take second ;-)
Regards,
Marco Gidde
More information about the cffi-devel
mailing list