diff options
| author | Stefan Monnier | 2011-05-05 00:42:09 -0300 |
|---|---|---|
| committer | Stefan Monnier | 2011-05-05 00:42:09 -0300 |
| commit | 9869b3ae6b4dc59d522f80b405250139e49cc9b9 (patch) | |
| tree | 979d481cb613659af94dfb604c552ede25289bc9 | |
| parent | 773233f8c325184da4305fc00645e061d481f182 (diff) | |
| download | emacs-9869b3ae6b4dc59d522f80b405250139e49cc9b9.tar.gz emacs-9869b3ae6b4dc59d522f80b405250139e49cc9b9.zip | |
Fix earlier half-done eieio-defmethod change.
* lisp/emacs-lisp/eieio.el (eieio--defmethod): Rename from eieio-defmethod.
Streamline and change calling convention.
(defmethod): Adjust accordingly and simplify.
(eieio-defclass): Fix broken calls to eieio-defmethod and redirect to
new eieio--defmethod.
(slot-boundp): Minor CSE simplification.
Fixes: debbugs:8338
| -rw-r--r-- | lisp/ChangeLog | 14 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio.el | 124 |
2 files changed, 56 insertions, 82 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a862509a6e9..7a491bd8fa0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2011-05-05 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | Fix earlier half-done eieio-defmethod change (bug#8338). | ||
| 4 | * emacs-lisp/eieio.el (eieio--defmethod): Rename from eieio-defmethod. | ||
| 5 | Streamline and change calling convention. | ||
| 6 | (defmethod): Adjust accordingly and simplify. | ||
| 7 | (eieio-defclass): Fix broken calls to eieio-defmethod and redirect to | ||
| 8 | new eieio--defmethod. | ||
| 9 | (slot-boundp): Minor CSE simplification. | ||
| 10 | |||
| 1 | 2011-05-05 Milan Zamazal <pdm@zamazal.org> | 11 | 2011-05-05 Milan Zamazal <pdm@zamazal.org> |
| 2 | 12 | ||
| 3 | * progmodes/glasses.el (glasses-separate-capital-groups): New option. | 13 | * progmodes/glasses.el (glasses-separate-capital-groups): New option. |
| @@ -15,8 +25,8 @@ | |||
| 15 | (autoload-find-generated-file): New function. | 25 | (autoload-find-generated-file): New function. |
| 16 | (generate-file-autoloads): Bind generated-autoload-file to | 26 | (generate-file-autoloads): Bind generated-autoload-file to |
| 17 | buffer-file-name. | 27 | buffer-file-name. |
| 18 | (update-file-autoloads, update-directory-autoloads): Use | 28 | (update-file-autoloads, update-directory-autoloads): |
| 19 | autoload-find-generated-file. If called interactively, prompt for | 29 | Use autoload-find-generated-file. If called interactively, prompt for |
| 20 | output file (Bug#7989). | 30 | output file (Bug#7989). |
| 21 | (batch-update-autoloads): Doc fix. | 31 | (batch-update-autoloads): Doc fix. |
| 22 | 32 | ||
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index 7a119e6bbc0..268698e4128 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el | |||
| @@ -656,14 +656,14 @@ See `defclass' for more information." | |||
| 656 | ;; so that users can `setf' the space returned by this function | 656 | ;; so that users can `setf' the space returned by this function |
| 657 | (if acces | 657 | (if acces |
| 658 | (progn | 658 | (progn |
| 659 | (eieio-defmethod acces | 659 | (eieio--defmethod |
| 660 | (list (if (eq alloc :class) :static :primary) | 660 | acces (if (eq alloc :class) :static :primary) cname |
| 661 | (list (list 'this cname)) | 661 | `(lambda (this) |
| 662 | (format | 662 | ,(format |
| 663 | "Retrieves the slot `%s' from an object of class `%s'" | 663 | "Retrieves the slot `%s' from an object of class `%s'" |
| 664 | name cname) | 664 | name cname) |
| 665 | (list 'if (list 'slot-boundp 'this (list 'quote name)) | 665 | (if (slot-boundp this ',name) |
| 666 | (list 'eieio-oref 'this (list 'quote name)) | 666 | (eieio-oref this ',name) |
| 667 | ;; Else - Some error? nil? | 667 | ;; Else - Some error? nil? |
| 668 | nil))) | 668 | nil))) |
| 669 | 669 | ||
| @@ -683,22 +683,21 @@ See `defclass' for more information." | |||
| 683 | ;; If a writer is defined, then create a generic method of that | 683 | ;; If a writer is defined, then create a generic method of that |
| 684 | ;; name whose purpose is to set the value of the slot. | 684 | ;; name whose purpose is to set the value of the slot. |
| 685 | (if writer | 685 | (if writer |
| 686 | (progn | 686 | (eieio--defmethod |
| 687 | (eieio-defmethod writer | 687 | writer nil cname |
| 688 | (list (list (list 'this cname) 'value) | 688 | `(lambda (this value) |
| 689 | (format "Set the slot `%s' of an object of class `%s'" | 689 | ,(format "Set the slot `%s' of an object of class `%s'" |
| 690 | name cname) | 690 | name cname) |
| 691 | `(setf (slot-value this ',name) value))) | 691 | (setf (slot-value this ',name) value)))) |
| 692 | )) | ||
| 693 | ;; If a reader is defined, then create a generic method | 692 | ;; If a reader is defined, then create a generic method |
| 694 | ;; of that name whose purpose is to access this slot value. | 693 | ;; of that name whose purpose is to access this slot value. |
| 695 | (if reader | 694 | (if reader |
| 696 | (progn | 695 | (eieio--defmethod |
| 697 | (eieio-defmethod reader | 696 | reader nil cname |
| 698 | (list (list (list 'this cname)) | 697 | `(lambda (this) |
| 699 | (format "Access the slot `%s' from object of class `%s'" | 698 | ,(format "Access the slot `%s' from object of class `%s'" |
| 700 | name cname) | 699 | name cname) |
| 701 | `(slot-value this ',name))))) | 700 | (slot-value this ',name)))) |
| 702 | ) | 701 | ) |
| 703 | (setq slots (cdr slots))) | 702 | (setq slots (cdr slots))) |
| 704 | 703 | ||
| @@ -1290,83 +1289,48 @@ Summary: | |||
| 1290 | ((typearg class-name) arg2 &optional opt &rest rest) | 1289 | ((typearg class-name) arg2 &optional opt &rest rest) |
| 1291 | \"doc-string\" | 1290 | \"doc-string\" |
| 1292 | body)" | 1291 | body)" |
| 1293 | (let* ((key (cond ((or (eq ':BEFORE (car args)) | 1292 | (let* ((key (if (keywordp (car args)) (pop args))) |
| 1294 | (eq ':before (car args))) | ||
| 1295 | (setq args (cdr args)) | ||
| 1296 | :before) | ||
| 1297 | ((or (eq ':AFTER (car args)) | ||
| 1298 | (eq ':after (car args))) | ||
| 1299 | (setq args (cdr args)) | ||
| 1300 | :after) | ||
| 1301 | ((or (eq ':PRIMARY (car args)) | ||
| 1302 | (eq ':primary (car args))) | ||
| 1303 | (setq args (cdr args)) | ||
| 1304 | :primary) | ||
| 1305 | ((or (eq ':STATIC (car args)) | ||
| 1306 | (eq ':static (car args))) | ||
| 1307 | (setq args (cdr args)) | ||
| 1308 | :static) | ||
| 1309 | (t nil))) | ||
| 1310 | (params (car args)) | 1293 | (params (car args)) |
| 1311 | (lamparams | ||
| 1312 | (mapcar (lambda (param) (if (listp param) (car param) param)) | ||
| 1313 | params)) | ||
| 1314 | (arg1 (car params)) | 1294 | (arg1 (car params)) |
| 1315 | (class (if (listp arg1) (nth 1 arg1) nil))) | 1295 | (class (if (consp arg1) (nth 1 arg1)))) |
| 1316 | `(eieio-defmethod ',method | 1296 | `(eieio--defmethod ',method ',key ',class |
| 1317 | '(,@(if key (list key)) | 1297 | (lambda ,(if (consp arg1) |
| 1318 | ,params) | 1298 | (cons (car arg1) (cdr params)) |
| 1319 | (lambda ,lamparams ,@(cdr args))))) | 1299 | params) |
| 1320 | 1300 | ,@(cdr args))))) | |
| 1321 | (defun eieio-defmethod (method args &optional code) | 1301 | |
| 1302 | (defun eieio--defmethod (method kind argclass code) | ||
| 1322 | "Work part of the `defmethod' macro defining METHOD with ARGS." | 1303 | "Work part of the `defmethod' macro defining METHOD with ARGS." |
| 1323 | (let ((key nil) (body nil) (firstarg nil) (argfix nil) (argclass nil) loopa) | 1304 | (let ((key |
| 1324 | ;; find optional keys | 1305 | ;; find optional keys |
| 1325 | (setq key | 1306 | (cond ((or (eq ':BEFORE kind) |
| 1326 | (cond ((or (eq ':BEFORE (car args)) | 1307 | (eq ':before kind)) |
| 1327 | (eq ':before (car args))) | ||
| 1328 | (setq args (cdr args)) | ||
| 1329 | method-before) | 1308 | method-before) |
| 1330 | ((or (eq ':AFTER (car args)) | 1309 | ((or (eq ':AFTER kind) |
| 1331 | (eq ':after (car args))) | 1310 | (eq ':after kind)) |
| 1332 | (setq args (cdr args)) | ||
| 1333 | method-after) | 1311 | method-after) |
| 1334 | ((or (eq ':PRIMARY (car args)) | 1312 | ((or (eq ':PRIMARY kind) |
| 1335 | (eq ':primary (car args))) | 1313 | (eq ':primary kind)) |
| 1336 | (setq args (cdr args)) | ||
| 1337 | method-primary) | 1314 | method-primary) |
| 1338 | ((or (eq ':STATIC (car args)) | 1315 | ((or (eq ':STATIC kind) |
| 1339 | (eq ':static (car args))) | 1316 | (eq ':static kind)) |
| 1340 | (setq args (cdr args)) | ||
| 1341 | method-static) | 1317 | method-static) |
| 1342 | ;; Primary key | 1318 | ;; Primary key |
| 1343 | (t method-primary))) | 1319 | (t method-primary)))) |
| 1344 | ;; get body, and fix contents of args to be the arguments of the fn. | ||
| 1345 | (setq body (cdr args) | ||
| 1346 | args (car args)) | ||
| 1347 | (setq loopa args) | ||
| 1348 | ;; Create a fixed version of the arguments | ||
| 1349 | (while loopa | ||
| 1350 | (setq argfix (cons (if (listp (car loopa)) (car (car loopa)) (car loopa)) | ||
| 1351 | argfix)) | ||
| 1352 | (setq loopa (cdr loopa))) | ||
| 1353 | ;; make sure there is a generic | 1320 | ;; make sure there is a generic |
| 1354 | (eieio-defgeneric | 1321 | (eieio-defgeneric |
| 1355 | method | 1322 | method |
| 1356 | (if (stringp (car body)) | 1323 | (or (documentation code) |
| 1357 | (car body) (format "Generically created method `%s'." method))) | 1324 | (format "Generically created method `%s'." method))) |
| 1358 | ;; create symbol for property to bind to. If the first arg is of | 1325 | ;; create symbol for property to bind to. If the first arg is of |
| 1359 | ;; the form (varname vartype) and `vartype' is a class, then | 1326 | ;; the form (varname vartype) and `vartype' is a class, then |
| 1360 | ;; that class will be the type symbol. If not, then it will fall | 1327 | ;; that class will be the type symbol. If not, then it will fall |
| 1361 | ;; under the type `primary' which is a non-specific calling of the | 1328 | ;; under the type `primary' which is a non-specific calling of the |
| 1362 | ;; function. | 1329 | ;; function. |
| 1363 | (setq firstarg (car args)) | 1330 | (if argclass |
| 1364 | (if (listp firstarg) | ||
| 1365 | (progn | ||
| 1366 | (setq argclass (nth 1 firstarg)) | ||
| 1367 | (if (not (class-p argclass)) | 1331 | (if (not (class-p argclass)) |
| 1368 | (error "Unknown class type %s in method parameters" | 1332 | (error "Unknown class type %s in method parameters" |
| 1369 | (nth 1 firstarg)))) | 1333 | argclass)) |
| 1370 | (if (= key -1) | 1334 | (if (= key -1) |
| 1371 | (signal 'wrong-type-argument (list :static 'non-class-arg))) | 1335 | (signal 'wrong-type-argument (list :static 'non-class-arg))) |
| 1372 | ;; generics are higher | 1336 | ;; generics are higher |
| @@ -1884,11 +1848,11 @@ OBJECT can be an instance or a class." | |||
| 1884 | ;; Skip typechecking while retrieving this value. | 1848 | ;; Skip typechecking while retrieving this value. |
| 1885 | (let ((eieio-skip-typecheck t)) | 1849 | (let ((eieio-skip-typecheck t)) |
| 1886 | ;; Return nil if the magic symbol is in there. | 1850 | ;; Return nil if the magic symbol is in there. |
| 1887 | (if (eieio-object-p object) | 1851 | (not (eq (cond |
| 1888 | (if (eq (eieio-oref object slot) eieio-unbound) nil t) | 1852 | ((eieio-object-p object) (eieio-oref object slot)) |
| 1889 | (if (class-p object) | 1853 | ((class-p object) (eieio-oref-default object slot)) |
| 1890 | (if (eq (eieio-oref-default object slot) eieio-unbound) nil t) | 1854 | (t (signal 'wrong-type-argument (list 'eieio-object-p object)))) |
| 1891 | (signal 'wrong-type-argument (list 'eieio-object-p object)))))) | 1855 | eieio-unbound)))) |
| 1892 | 1856 | ||
| 1893 | (defun slot-makeunbound (object slot) | 1857 | (defun slot-makeunbound (object slot) |
| 1894 | "In OBJECT, make SLOT unbound." | 1858 | "In OBJECT, make SLOT unbound." |