[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/record 8b1b962 03/10: Make EIEIO use records.
From: |
Lars Brinkhoff |
Subject: |
[Emacs-diffs] scratch/record 8b1b962 03/10: Make EIEIO use records. |
Date: |
Fri, 24 Mar 2017 11:51:41 -0400 (EDT) |
branch: scratch/record
commit 8b1b962d1782ccac37b21e71fd898ef7b4fbb6c9
Author: Stefan Monnier <address@hidden>
Commit: Lars Brinkhoff <address@hidden>
Make EIEIO use records.
* lisp/emacs-lisp/eieio-core.el: Use records, and place the class object
directly as tag.
(eieio--object-class): Adjust to new tag representation.
(eieio-object-p): Rewrite.
(eieio-defclass-internal): Use `make-record'.
(eieio--generic-generalizer): Adjust generalizer code accordingly.
* lisp/emacs-lisp/eieio.el (make-instance, clone): Use copy-record.
* lisp/emacs-lisp/pcase.el (pcase-mutually-exclusive-predicates):
Add `recordp'.
* doc/lispref/records.texi, doc/misc/eieio.texi: Update for records.
---
doc/lispref/records.texi | 3 ++-
doc/misc/eieio.texi | 10 +++++-----
lisp/emacs-lisp/eieio-core.el | 28 +++++++---------------------
lisp/emacs-lisp/eieio.el | 6 +++---
lisp/emacs-lisp/pcase.el | 6 ++++++
5 files changed, 23 insertions(+), 30 deletions(-)
diff --git a/doc/lispref/records.texi b/doc/lispref/records.texi
index 63ea5fb..185c41c 100644
--- a/doc/lispref/records.texi
+++ b/doc/lispref/records.texi
@@ -9,7 +9,8 @@
The purpose of records is to allow programmers to create objects
with new types that are not built into Emacs. They are used as the
-underlying representation of @code{cl-defstruct} instances.
+underlying representation of @code{cl-defstruct} and @code{defclass}
+instances.
Internally, a record object is much like a vector; its slots can be
accessed using @code{aref}. However, the first slot is used to hold
diff --git a/doc/misc/eieio.texi b/doc/misc/eieio.texi
index dfae565..b0b7b4d 100644
--- a/doc/misc/eieio.texi
+++ b/doc/misc/eieio.texi
@@ -265,7 +265,7 @@ To create a new class, use the @code{defclass} macro:
@defmac defclass class-name superclass-list slot-list &rest options-and-doc
-Create a new class named @var{class-name}. The class is represented
+Create a new class named @var{class-name}. XXX The class is represented
by a symbol with the name @var{class-name}. @eieio{} stores the structure of
the class as a symbol property of @var{class-name} (@pxref{Symbol
Components,,,elisp,GNU Emacs Lisp Reference Manual}).
@@ -1017,7 +1017,7 @@ If @var{errorp} is address@hidden,
@code{wrong-argument-type} is signaled.
@defun class-p class
@anchor{class-p}
-Return @code{t} if @var{class} is a valid class vector.
+Return @code{t} if @var{class} is a valid class object.
@var{class} is a symbol.
@end defun
@@ -1055,7 +1055,7 @@ Will fetch the documentation string for
@code{eieio-default-superclass}.
Return a string of the form @samp{#<object-class myobjname>} for @var{obj}.
This should look like Lisp symbols from other parts of Emacs such as
buffers and processes, and is shorter and cleaner than printing the
-object's vector. It is more useful to use @code{object-print} to get
+object's record. It is more useful to use @code{object-print} to get
and object's print form, as this allows the object to add extra display
information into the symbol.
@end defun
@@ -1212,7 +1212,7 @@ items defined in this second slot.
Introspection permits a programmer to peek at the contents of a class
without any previous knowledge of that class. While @eieio{} implements
-objects on top of vectors, and thus everything is technically visible,
+objects on top of records, and thus everything is technically visible,
some functions have been provided. None of these functions are a part
of CLOS.
@@ -1525,7 +1525,7 @@ Currently, the default superclass is defined as follows:
nil
"Default parent class for classes with no specified parent class.
Its slots are automatically adopted by classes with no specified
-parents. This class is not stored in the `parent' slot of a class vector."
+parents. This class is not stored in the `parent' slot of a class object."
:abstract t)
@end example
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el
index 5cc6d02..882e7fb 100644
--- a/lisp/emacs-lisp/eieio-core.el
+++ b/lisp/emacs-lisp/eieio-core.el
@@ -122,7 +122,7 @@ Currently under control of this var:
(length (cl-struct-slot-info 'eieio--object))))
(defsubst eieio--object-class (obj)
- (symbol-value (eieio--object-class-tag obj)))
+ (eieio--object-class-tag obj))
;;; Important macros used internally in eieio.
@@ -166,13 +166,7 @@ Return nil if that option doesn't exist."
(defun eieio-object-p (obj)
"Return non-nil if OBJ is an EIEIO object."
- (and (vectorp obj)
- (> (length obj) 0)
- (let ((tag (eieio--object-class-tag obj)))
- (and (symbolp tag)
- ;; (eq (symbol-function tag) :quick-object-witness-check)
- (boundp tag)
- (eieio--class-p (symbol-value tag))))))
+ (eieio--class-p (type-of obj)))
(define-obsolete-function-alias 'object-p 'eieio-object-p "25.1")
@@ -496,18 +490,10 @@ See `defclass' for more information."
(if clearparent (setf (eieio--class-parents newc) nil))
;; Create the cached default object.
- (let ((cache (make-vector (+ (length (eieio--class-slots newc))
+ (let ((cache (make-record newc
+ (+ (length (eieio--class-slots newc))
(eval-when-compile eieio--object-num-slots))
- nil))
- ;; We don't strictly speaking need to use a symbol, but the old
- ;; code used the class's name rather than the class's object, so
- ;; we follow this preference for using a symbol, which is probably
- ;; convenient to keep the printed representation of such Elisp
- ;; objects readable.
- (tag (intern (format "eieio-class-tag--%s" cname))))
- (set tag newc)
- (fset tag :quick-object-witness-check)
- (setf (eieio--object-class-tag cache) tag)
+ nil)))
(let ((eieio-skip-typecheck t))
;; All type-checking has been done to our satisfaction
;; before this call. Don't waste our time in this call..
@@ -1060,9 +1046,9 @@ method invocation orders of the involved classes."
;; part of the dispatch code.
50 #'cl--generic-struct-tag
(lambda (tag &rest _)
- (and (symbolp tag) (boundp tag) (eieio--class-p (symbol-value tag))
+ (and (eieio--class-p tag)
(mapcar #'eieio--class-name
- (eieio--class-precedence-list (symbol-value tag))))))
+ (eieio--class-precedence-list tag)))))
(cl-defmethod cl-generic-generalizers :extra "class" (specializer)
"Support for dispatch on types defined by EIEIO's `defclass'."
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el
index 1a6d5e9..f3530ca 100644
--- a/lisp/emacs-lisp/eieio.el
+++ b/lisp/emacs-lisp/eieio.el
@@ -701,8 +701,8 @@ SLOTS are the initialization slots used by
`initialize-instance'.
This static method is called when an object is constructed.
It allocates the vector used to represent an EIEIO object, and then
calls `initialize-instance' on that object."
- (let* ((new-object (copy-sequence (eieio--class-default-object-cache
- (eieio--class-object class)))))
+ (let* ((new-object (copy-record (eieio--class-default-object-cache
+ (eieio--class-object class)))))
(if (and slots
(let ((x (car slots)))
(or (stringp x) (null x))))
@@ -806,7 +806,7 @@ first and modify the returned object.")
(cl-defmethod clone ((obj eieio-default-superclass) &rest params)
"Make a copy of OBJ, and then apply PARAMS."
- (let ((nobj (copy-sequence obj)))
+ (let ((nobj (copy-record obj)))
(if (stringp (car params))
(funcall (if eieio-backward-compatibility #'ignore #'message)
"Obsolete name %S passed to clone" (pop params)))
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
index 289265a..6c4ac51 100644
--- a/lisp/emacs-lisp/pcase.el
+++ b/lisp/emacs-lisp/pcase.el
@@ -503,24 +503,30 @@ MATCH is the pattern that needs to be matched, of the
form:
(symbolp . vectorp)
(symbolp . stringp)
(symbolp . byte-code-function-p)
+ (symbolp . recordp)
(integerp . consp)
(integerp . arrayp)
(integerp . vectorp)
(integerp . stringp)
(integerp . byte-code-function-p)
+ (integerp . recordp)
(numberp . consp)
(numberp . arrayp)
(numberp . vectorp)
(numberp . stringp)
(numberp . byte-code-function-p)
+ (numberp . recordp)
(consp . arrayp)
(consp . atom)
(consp . vectorp)
(consp . stringp)
(consp . byte-code-function-p)
+ (consp . recordp)
(arrayp . byte-code-function-p)
(vectorp . byte-code-function-p)
+ (vectorp . recordp)
(stringp . vectorp)
+ (stringp . recordp)
(stringp . byte-code-function-p)))
(defun pcase--mutually-exclusive-p (pred1 pred2)
- [Emacs-diffs] branch scratch/record created (now 4ea0d9d), Lars Brinkhoff, 2017/03/24
- [Emacs-diffs] scratch/record b5475b8 07/10: Remove CHECK_RECORD_TYPE., Lars Brinkhoff, 2017/03/24
- [Emacs-diffs] scratch/record 96a0547 08/10: The sky isn't so blue after all., Lars Brinkhoff, 2017/03/24
- [Emacs-diffs] scratch/record 0013635 06/10: Change read/print syntax to use #s., Lars Brinkhoff, 2017/03/24
- [Emacs-diffs] scratch/record 3cda36e 05/10: Backward compatibility with pre-existing struct instances., Lars Brinkhoff, 2017/03/24
- [Emacs-diffs] scratch/record 584c08c 04/10: Make the URL library use records., Lars Brinkhoff, 2017/03/24
- [Emacs-diffs] scratch/record 8b1b962 03/10: Make EIEIO use records.,
Lars Brinkhoff <=
- [Emacs-diffs] scratch/record 6d6b9b1 01/10: Add record objects with user-defined types., Lars Brinkhoff, 2017/03/24
- [Emacs-diffs] scratch/record 603f016 02/10: Make cl-defstruct use records., Lars Brinkhoff, 2017/03/24
- [Emacs-diffs] scratch/record 7dbb1dc 09/10: * src/data.c (Ftype_of): Return type name, if record's type holds class., Lars Brinkhoff, 2017/03/24
- [Emacs-diffs] scratch/record 4ea0d9d 10/10: Make type-of return the type, even for old-style structs, Lars Brinkhoff, 2017/03/24