* lisp/emacs-lisp/eieio.el (eieio-oset-default, eieio-oset, oset-default)
(oset): Move uses of object-class-fast macro after its definition.
This commit is contained in:
parent
5046ef67ca
commit
9760c73c66
2 changed files with 68 additions and 65 deletions
|
@ -1,5 +1,8 @@
|
|||
2012-10-14 Stefan Monnier <monnier@iro.umontreal.ca>
|
||||
|
||||
* emacs-lisp/eieio.el (eieio-oset-default, eieio-oset, oset-default)
|
||||
(oset): Move uses of object-class-fast macro after its definition.
|
||||
|
||||
* emacs-lisp/gv.el (if): Don't use closures in non-lexical-binding code.
|
||||
|
||||
2012-10-13 Chong Yidong <cyd@gnu.org>
|
||||
|
|
|
@ -1556,71 +1556,6 @@ Fills in OBJ's SLOT with its default value."
|
|||
;; return it verbatim
|
||||
(t val)))
|
||||
|
||||
;;; Object Set macros
|
||||
;;
|
||||
(defmacro oset (obj slot value)
|
||||
"Set the value in OBJ for slot SLOT to VALUE.
|
||||
SLOT is the slot name as specified in `defclass' or the tag created
|
||||
with in the :initarg slot. VALUE can be any Lisp object."
|
||||
`(eieio-oset ,obj (quote ,slot) ,value))
|
||||
|
||||
(defun eieio-oset (obj slot value)
|
||||
"Do the work for the macro `oset'.
|
||||
Fills in OBJ's SLOT with VALUE."
|
||||
(if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
|
||||
(if (not (symbolp slot)) (signal 'wrong-type-argument (list 'symbolp slot)))
|
||||
(let ((c (eieio-slot-name-index (object-class-fast obj) obj slot)))
|
||||
(if (not c)
|
||||
;; It might be missing because it is a :class allocated slot.
|
||||
;; Let's check that info out.
|
||||
(if (setq c
|
||||
(eieio-class-slot-name-index (aref obj object-class) slot))
|
||||
;; Oset that slot.
|
||||
(progn
|
||||
(eieio-validate-class-slot-value (object-class-fast obj) c value slot)
|
||||
(aset (aref (class-v (aref obj object-class))
|
||||
class-class-allocation-values)
|
||||
c value))
|
||||
;; See oref for comment on `slot-missing'
|
||||
(slot-missing obj slot 'oset value)
|
||||
;;(signal 'invalid-slot-name (list (object-name obj) slot))
|
||||
)
|
||||
(eieio-validate-slot-value (object-class-fast obj) c value slot)
|
||||
(aset obj c value))))
|
||||
|
||||
(defmacro oset-default (class slot value)
|
||||
"Set the default slot in CLASS for SLOT to VALUE.
|
||||
The default value is usually set with the :initform tag during class
|
||||
creation. This allows users to change the default behavior of classes
|
||||
after they are created."
|
||||
`(eieio-oset-default ,class (quote ,slot) ,value))
|
||||
|
||||
(defun eieio-oset-default (class slot value)
|
||||
"Do the work for the macro `oset-default'.
|
||||
Fills in the default value in CLASS' in SLOT with VALUE."
|
||||
(if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class)))
|
||||
(if (not (symbolp slot)) (signal 'wrong-type-argument (list 'symbolp slot)))
|
||||
(let* ((scoped-class class)
|
||||
(c (eieio-slot-name-index class nil slot)))
|
||||
(if (not c)
|
||||
;; It might be missing because it is a :class allocated slot.
|
||||
;; Let's check that info out.
|
||||
(if (setq c (eieio-class-slot-name-index class slot))
|
||||
(progn
|
||||
;; Oref that slot.
|
||||
(eieio-validate-class-slot-value class c value slot)
|
||||
(aset (aref (class-v class) class-class-allocation-values) c
|
||||
value))
|
||||
(signal 'invalid-slot-name (list (class-name class) slot)))
|
||||
(eieio-validate-slot-value class c value slot)
|
||||
;; Set this into the storage for defaults.
|
||||
(setcar (nthcdr (- c 3) (aref (class-v class) class-public-d))
|
||||
value)
|
||||
;; Take the value, and put it into our cache object.
|
||||
(eieio-oset (aref (class-v class) class-default-object-cache)
|
||||
slot value)
|
||||
)))
|
||||
|
||||
;;; Handy CLOS macros
|
||||
;;
|
||||
(defmacro with-slots (spec-list object &rest body)
|
||||
|
@ -1871,6 +1806,71 @@ method invocation orders of the involved classes."
|
|||
(setq ia (cdr ia)))
|
||||
f))
|
||||
|
||||
;;; Object Set macros
|
||||
;;
|
||||
(defmacro oset (obj slot value)
|
||||
"Set the value in OBJ for slot SLOT to VALUE.
|
||||
SLOT is the slot name as specified in `defclass' or the tag created
|
||||
with in the :initarg slot. VALUE can be any Lisp object."
|
||||
`(eieio-oset ,obj (quote ,slot) ,value))
|
||||
|
||||
(defun eieio-oset (obj slot value)
|
||||
"Do the work for the macro `oset'.
|
||||
Fills in OBJ's SLOT with VALUE."
|
||||
(if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
|
||||
(if (not (symbolp slot)) (signal 'wrong-type-argument (list 'symbolp slot)))
|
||||
(let ((c (eieio-slot-name-index (object-class-fast obj) obj slot)))
|
||||
(if (not c)
|
||||
;; It might be missing because it is a :class allocated slot.
|
||||
;; Let's check that info out.
|
||||
(if (setq c
|
||||
(eieio-class-slot-name-index (aref obj object-class) slot))
|
||||
;; Oset that slot.
|
||||
(progn
|
||||
(eieio-validate-class-slot-value (object-class-fast obj) c value slot)
|
||||
(aset (aref (class-v (aref obj object-class))
|
||||
class-class-allocation-values)
|
||||
c value))
|
||||
;; See oref for comment on `slot-missing'
|
||||
(slot-missing obj slot 'oset value)
|
||||
;;(signal 'invalid-slot-name (list (object-name obj) slot))
|
||||
)
|
||||
(eieio-validate-slot-value (object-class-fast obj) c value slot)
|
||||
(aset obj c value))))
|
||||
|
||||
(defmacro oset-default (class slot value)
|
||||
"Set the default slot in CLASS for SLOT to VALUE.
|
||||
The default value is usually set with the :initform tag during class
|
||||
creation. This allows users to change the default behavior of classes
|
||||
after they are created."
|
||||
`(eieio-oset-default ,class (quote ,slot) ,value))
|
||||
|
||||
(defun eieio-oset-default (class slot value)
|
||||
"Do the work for the macro `oset-default'.
|
||||
Fills in the default value in CLASS' in SLOT with VALUE."
|
||||
(if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class)))
|
||||
(if (not (symbolp slot)) (signal 'wrong-type-argument (list 'symbolp slot)))
|
||||
(let* ((scoped-class class)
|
||||
(c (eieio-slot-name-index class nil slot)))
|
||||
(if (not c)
|
||||
;; It might be missing because it is a :class allocated slot.
|
||||
;; Let's check that info out.
|
||||
(if (setq c (eieio-class-slot-name-index class slot))
|
||||
(progn
|
||||
;; Oref that slot.
|
||||
(eieio-validate-class-slot-value class c value slot)
|
||||
(aset (aref (class-v class) class-class-allocation-values) c
|
||||
value))
|
||||
(signal 'invalid-slot-name (list (class-name class) slot)))
|
||||
(eieio-validate-slot-value class c value slot)
|
||||
;; Set this into the storage for defaults.
|
||||
(setcar (nthcdr (- c 3) (aref (class-v class) class-public-d))
|
||||
value)
|
||||
;; Take the value, and put it into our cache object.
|
||||
(eieio-oset (aref (class-v class) class-default-object-cache)
|
||||
slot value)
|
||||
)))
|
||||
|
||||
;;; CLOS queries into classes and slots
|
||||
;;
|
||||
(defun slot-boundp (object slot)
|
||||
|
|
Loading…
Add table
Reference in a new issue