mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-09 02:33:14 -08:00
Dummy implementation of MAKE-LOAD-FORM and MAKE-LOAD-FORM-SAVING-SLOTS. Supports for normal lisp objects and structures is missing.
This commit is contained in:
parent
b30b43ce17
commit
b8d27be483
6 changed files with 53 additions and 8 deletions
|
|
@ -118,7 +118,7 @@
|
|||
(if index
|
||||
(si:sl-boundp (si:instance-ref self (the fixnum index)))
|
||||
(slot-missing (si:instance-class class) class slot-name
|
||||
'SLOT-VALUE)))))
|
||||
'SLOT-BOUNDP)))))
|
||||
|
||||
(defmethod (setf slot-value) (val (self class) slot-name)
|
||||
(ensure-up-to-date-instance self)
|
||||
|
|
@ -128,7 +128,7 @@
|
|||
(if index
|
||||
(si:instance-set self (the fixnum index) val)
|
||||
(slot-missing (si:instance-class self) self slot-name
|
||||
'SLOT-VALUE)))
|
||||
'SETF val)))
|
||||
val)
|
||||
|
||||
(defmethod slot-missing ((class t) object slot-name operation
|
||||
|
|
|
|||
|
|
@ -129,6 +129,9 @@
|
|||
(defclass structure-object (t) ()
|
||||
(:metaclass structure-class))
|
||||
|
||||
(defmethod make-load-form ((object structure-object) &optional environment)
|
||||
(make-load-form-saving-slots object))
|
||||
|
||||
(defmethod print-object ((obj structure-object) stream)
|
||||
(let* ((class (si:instance-class obj))
|
||||
(slotds (class-slots class)))
|
||||
|
|
|
|||
|
|
@ -95,9 +95,20 @@
|
|||
;;; ENSURE-CLASS
|
||||
;;;
|
||||
(defun ensure-class (name &rest initargs)
|
||||
(let ((class (apply #'ensure-class-using-class (find-class name nil) name
|
||||
initargs)))
|
||||
(when name (setf (find-class name) class))))
|
||||
(let* ((old-class nil)
|
||||
new-class)
|
||||
;; Only classes which have a PROPER name are redefined. If a class
|
||||
;; with the same name is register, but the name of the class does not
|
||||
;; correspond to the registered name, a new class is returned.
|
||||
;; [Hyperspec 7.7 for DEFCLASS]
|
||||
(when name
|
||||
(when (and (setf old-class (find-class name nil))
|
||||
(not (eq (class-name old-class) name)))
|
||||
(setf old-class nil)))
|
||||
(setf new-class (apply #'ensure-class-using-class old-class name initargs))
|
||||
(when name (setf (find-class name) new-class))
|
||||
new-class))
|
||||
|
||||
(eval-when (compile)
|
||||
(defun ensure-class (name &rest initargs)
|
||||
(warn "Ignoring definition for class ~S" name)))
|
||||
|
|
|
|||
|
|
@ -735,7 +735,7 @@
|
|||
(setf (symbol-function 'SLOT-INDEX) (symbol-function 'GETHASH))
|
||||
(put-sysprop 'SLOT-INDEX ':INLINE-ALWAYS
|
||||
'(((T T) FIXNUM NIL NIL "fix(gethash(#0,#1))")
|
||||
((T T) T NIL NIL "(gethash(#0,#1))")))
|
||||
((T T) T NIL NIL "gethash_safe(#0,#1,Cnil)")))
|
||||
|
||||
(defun reduce-constant (old)
|
||||
(let ((new (eval old)))
|
||||
|
|
|
|||
|
|
@ -9,6 +9,37 @@
|
|||
|
||||
(in-package "CLOS")
|
||||
|
||||
;;; ----------------------------------------------------------------------
|
||||
;;; Load forms
|
||||
;;;
|
||||
|
||||
(defun make-load-form-saving-slots (object &key slot-names environment)
|
||||
(declare (ignore environment))
|
||||
(do* ((class (class-of object))
|
||||
(initialization (list 'progn))
|
||||
(slots (class-slots class) (cdr slots)))
|
||||
((endp slots)
|
||||
(values `(allocate-instance ,class) (nreverse initialization)))
|
||||
(let* ((slot (first slots))
|
||||
(slot-name (slotd-name slot)))
|
||||
(when (or (and (null slot-names)
|
||||
(eq (slotd-allocation slot) :instance))
|
||||
(member slot-name slot-names))
|
||||
(push (if (slot-boundp object slot-name)
|
||||
`(setf (slot-value ,object ',slot-name)
|
||||
',(slot-value object slot-name))
|
||||
`(slot-makunbound ,object ',slot-name))
|
||||
initialization)))))
|
||||
|
||||
(defmethod make-load-form ((object standard-object) &optional environment)
|
||||
(make-load-form-saving-slots object))
|
||||
|
||||
(defmethod make-load-form ((class class) &optional environment)
|
||||
(let ((name (class-name class)))
|
||||
(if (and name (eq (find-class name) class))
|
||||
`(find-class ',name)
|
||||
(error "Cannot externalize anonymous class ~A" class))))
|
||||
|
||||
;;; ----------------------------------------------------------------------
|
||||
;;; Printing
|
||||
;;; ----------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ because it contains a reference to the undefined class~% ~A"
|
|||
(let ((value (si:instance-ref self index)))
|
||||
(if (si:sl-boundp value)
|
||||
value
|
||||
(slot-unbound self slot-name))))
|
||||
(values (slot-unbound (class-of self) self slot-name)))))
|
||||
setter #'(lambda (value self)
|
||||
(si:instance-set self index value))
|
||||
i (1+ i))
|
||||
|
|
@ -517,7 +517,7 @@ because it contains a reference to the undefined class~% ~A"
|
|||
;; else it is a shared slot
|
||||
(setf (svref (class-shared-slots (car index)) (cdr index)) val))
|
||||
(slot-missing (si:instance-class instance) instance slot-name
|
||||
'SLOT-VALUE))
|
||||
'SETF val))
|
||||
val))
|
||||
|
||||
;;; ----------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue