\f
;;; Get/Set slots in an object.
+(eval-and-compile
+ (defun eieio--check-slot-name (exp _obj slot &rest _)
+ (pcase slot
+ ((and (or `',name (and name (pred keywordp)))
+ (guard (not (eieio--known-slot-name-p name))))
+ (macroexp-warn-and-return
+ (format-message "Unknown slot `%S'" name)
+ exp nil 'compile-only name))
+ (_ exp))))
+
(defun eieio-oref (obj slot)
"Return the value in OBJ at SLOT in the object vector."
- (declare (compiler-macro
- (lambda (exp)
- (ignore obj)
- (pcase slot
- ((and (or `',name (and name (pred keywordp)))
- (guard (not (eieio--known-slot-name-p name))))
- (macroexp-warn-and-return
- (format-message "Unknown slot `%S'" name)
- exp nil 'compile-only name))
- (_ exp))))
+ (declare (compiler-macro eieio--check-slot-name)
;; FIXME: Make it a gv-expander such that the hash-table lookup is
;; only performed once when used in `push' and friends?
(gv-setter eieio-oset))
(defun eieio-oset (obj slot value)
"Do the work for the macro `oset'.
Fills in OBJ's SLOT with VALUE."
+ (declare (compiler-macro eieio--check-slot-name))
(cl-check-type slot symbol)
(cond
((cl-typep obj '(or eieio-object cl-structure-object))
;; but hide it so we don't trigger indefinitely.
`(,(car whole) (identity ,(car slots))
,@(cdr slots))
- nil nil (car slots))))
+ '(obsolete eieio-constructor-name-arg) nil (car slots))))
;;; Get/Set slots in an object.
;;
Setting a slot's value makes it bound. Calling `slot-makeunbound' will
make a slot unbound.
OBJECT can be an instance or a class."
+ (declare (compiler-macro eieio--check-slot-name))
;; Skip typechecking while retrieving this value.
(let ((eieio-skip-typecheck t))
;; Return nil if the magic symbol is in there.
(make-instance \\='foo :slot1 value1 :slotN valueN)")
+(put 'make-instance 'compiler-macro
+ (lambda (whole class &rest slots)
+ (if (or (null slots) (keywordp (car slots))
+ ;; Detect the second pass!
+ (eq 'identity (car-safe (car slots))))
+ whole
+ (macroexp-warn-and-return
+ (format "Obsolete name arg %S to `make-instance'" (car slots))
+ ;; Keep the name arg, for backward compatibility,
+ ;; but hide it so we don't trigger indefinitely.
+ `(,(car whole) ,class (identity ,(car slots))
+ ,@(cdr slots))
+ '(obsolete eieio-constructor-name-arg) nil (car slots)))))
+
(define-obsolete-function-alias 'constructor #'make-instance "25.1")
(cl-defmethod make-instance