mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-03-10 23:20:23 -07:00
clos: replace macros by functions in with-early-accessors
Accessors are fuctions not macros. While using macros is fine in most cases, we can't use them for example in higher-order functions. The only reason this worked in the first place is due to our compiler allowing expressions such as `(macrolet ((x (...) ...)) (funcall #'x ...)) even though this is invalid.
This commit is contained in:
parent
62d1bb1203
commit
9e204464ea
1 changed files with 13 additions and 10 deletions
|
|
@ -61,16 +61,19 @@
|
|||
;;;
|
||||
(eval-when (:compile-toplevel :execute)
|
||||
(defmacro with-early-accessors ((&rest slot-definitions) &rest body)
|
||||
`(macrolet
|
||||
,(loop for slots in slot-definitions
|
||||
nconc (loop for (name . slotd) in (if (symbolp slots)
|
||||
(symbol-value slots)
|
||||
slots)
|
||||
for index from 0
|
||||
for accessor = (getf slotd :accessor)
|
||||
when accessor
|
||||
collect `(,accessor (object) `(si::instance-ref ,object ,,index))))
|
||||
,@body)))
|
||||
(let (functions)
|
||||
(loop for slots in slot-definitions
|
||||
do (loop for (name . slotd) in (if (symbolp slots)
|
||||
(symbol-value slots)
|
||||
slots)
|
||||
for index from 0
|
||||
for accessor = (getf slotd :accessor)
|
||||
when (and accessor (not (member accessor functions :key #'first)))
|
||||
do (push `(,accessor (object) (si::instance-ref object ,index)) functions)
|
||||
(push `((setf ,accessor) (value object) (si::instance-set object ,index value)) functions)))
|
||||
`(flet ,functions
|
||||
(declare (inline ,@(mapcar #'first functions)))
|
||||
,@body))))
|
||||
|
||||
;;;
|
||||
;;; The following macro is also used at bootstap for instantiating
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue