[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/oclosure fe5457ff75 19/25: oclosure.el (oclosure-lambda): Change
From: |
Stefan Monnier |
Subject: |
scratch/oclosure fe5457ff75 19/25: oclosure.el (oclosure-lambda): Change calling convention |
Date: |
Fri, 31 Dec 2021 15:40:58 -0500 (EST) |
branch: scratch/oclosure
commit fe5457ff757ded7999610917f8f39d28b8908e6f
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
oclosure.el (oclosure-lambda): Change calling convention
* lisp/emacs-lisp/oclosure.el (oclosure-lambda): Change calling convention.
* lisp/emacs-lisp/nadvice.el (advice--where-alist):
* lisp/emacs-lisp/cl-generic.el (cl-generic-call-method):
* lisp/kmacro.el (kmacro-lambda-form): Adjust accordingly.
---
lisp/emacs-lisp/cl-generic.el | 2 +-
lisp/emacs-lisp/nadvice.el | 20 ++++++++++----------
lisp/emacs-lisp/oclosure.el | 29 +++++++++++++++++------------
lisp/kmacro.el | 6 +++---
4 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/lisp/emacs-lisp/cl-generic.el b/lisp/emacs-lisp/cl-generic.el
index 1886f309e3..46fd2de484 100644
--- a/lisp/emacs-lisp/cl-generic.el
+++ b/lisp/emacs-lisp/cl-generic.el
@@ -744,7 +744,7 @@ FUN is the function that should be called when METHOD calls
(if fun
(lambda (&rest cnm-args)
(apply fun (or cnm-args args)))
- (oclosure-lambda cl--generic-nnm () (&rest cnm-args)
+ (oclosure-lambda (cl--generic-nnm) (&rest cnm-args)
(apply #'cl-no-next-method generic method
(or cnm-args args))))
args)))))
diff --git a/lisp/emacs-lisp/nadvice.el b/lisp/emacs-lisp/nadvice.el
index 3a1c4a2a58..d49ac5ae25 100644
--- a/lisp/emacs-lisp/nadvice.el
+++ b/lisp/emacs-lisp/nadvice.el
@@ -48,25 +48,25 @@
;;;; Lightweight advice/hook
(defvar advice--where-alist
- `((:around ,(oclosure-lambda advice ((where :around)) (&rest args)
+ `((:around ,(oclosure-lambda (advice (where :around)) (&rest args)
(apply car cdr args)))
- (:before ,(oclosure-lambda advice ((where :before)) (&rest args)
+ (:before ,(oclosure-lambda (advice (where :before)) (&rest args)
(apply car args) (apply cdr args)))
- (:after ,(oclosure-lambda advice ((where :after)) (&rest args)
+ (:after ,(oclosure-lambda (advice (where :after)) (&rest args)
(apply cdr args) (apply car args)))
- (:override ,(oclosure-lambda advice ((where :override)) (&rest args)
+ (:override ,(oclosure-lambda (advice (where :override)) (&rest args)
(apply car args)))
- (:after-until ,(oclosure-lambda advice ((where :after-until)) (&rest args)
+ (:after-until ,(oclosure-lambda (advice (where :after-until)) (&rest args)
(or (apply cdr args) (apply car args))))
- (:after-while ,(oclosure-lambda advice ((where :after-while)) (&rest args)
+ (:after-while ,(oclosure-lambda (advice (where :after-while)) (&rest args)
(and (apply cdr args) (apply car args))))
- (:before-until ,(oclosure-lambda advice ((where :before-until)) (&rest
args)
+ (:before-until ,(oclosure-lambda (advice (where :before-until)) (&rest
args)
(or (apply car args) (apply cdr args))))
- (:before-while ,(oclosure-lambda advice ((where :before-while)) (&rest
args)
+ (:before-while ,(oclosure-lambda (advice (where :before-while)) (&rest
args)
(and (apply car args) (apply cdr args))))
- (:filter-args ,(oclosure-lambda advice ((where :filter-args)) (&rest args)
+ (:filter-args ,(oclosure-lambda (advice (where :filter-args)) (&rest args)
(apply cdr (funcall car args))))
- (:filter-return ,(oclosure-lambda advice ((where :filter-return)) (&rest
args)
+ (:filter-return ,(oclosure-lambda (advice (where :filter-return)) (&rest
args)
(funcall car (apply cdr args)))))
"List of descriptions of how to add a function.
Each element has the form (WHERE OCL) where OCL is a \"prototype\"
diff --git a/lisp/emacs-lisp/oclosure.el b/lisp/emacs-lisp/oclosure.el
index b88d108853..d957236fa4 100644
--- a/lisp/emacs-lisp/oclosure.el
+++ b/lisp/emacs-lisp/oclosure.el
@@ -25,21 +25,24 @@
;; with a notion of type (e.g. for defmethod dispatch) as well as the
;; ability to have some fields that are accessible from the outside.
-;; Here are some cases of "callable objects" where OClosures might be useful:
+;; Here are some cases of "callable objects" where OClosures are used:
;; - nadvice.el
-;; - iterators (generator.el), thunks (thunk.el), streams (stream.el).
;; - kmacros (for cl-print and for `kmacro-extract-lambda')
+;; - cl-generic: turn `cl--generic-isnot-nnm-p' into a mere type test
+;; (by putting the no-next-methods into their own class).
+;; - OClosure accessor functions, where the type-dispatch is used to
+;; dynamically compute the docstring, and also to pretty them.
+;; Here are other cases of "callable objects" where OClosures could be used:
+;; - iterators (generator.el), thunks (thunk.el), streams (stream.el).
;; - PEG rules: they're currently just functions, but they should carry
;; their original (macro-expanded) definition (and should be printed
;; differently from functions)!
-;; - cl-generic: turn `cl--generic-isnot-nnm-p' into a mere type test
-;; (by putting the no-next-methods into their own class).
;; - documented functions: this could be a subtype of normal functions, which
;; simply has an additional `docstring' slot.
;; - commands: this could be a subtype of documented functions, which simply
;; has an additional `interactive-form' slot.
-;; - auto-generate docstrings for slot accessors instead of storing them
-;; in the accessor itself?
+;; - auto-generate docstrings for cl-defstruct slot accessors instead of
+;; storing them in the accessor itself?
;;; Code:
@@ -251,17 +254,19 @@ No checking is performed,"
(if t nil ,@(mapcar #'car bindings))
,@body)))))
-(defmacro oclosure-lambda (type fields args &rest body)
+(defmacro oclosure-lambda (type-and-slots args &rest body)
"Define anonymous OClosure function.
-TYPE should be an OClosure type.
-FIELDS is a let-style list of bindings for the various slots of TYPE.
-ARGS is and BODY are the same as for `lambda'."
- (declare (indent 3) (debug (sexp (&rest (sexp form)) sexp def-body)))
+TYPE-AND-SLOTS should be of the form (TYPE . SLOTS)
+where TYPE is an OClosure type name and
+SLOTS is a let-style list of bindings for the various slots of TYPE.
+ARGS and BODY are the same as for `lambda'."
+ (declare (indent 2) (debug ((sexp &rest (sexp form)) sexp def-body)))
;; FIXME: Should `oclosure-define' distinguish "optional" from
;; "mandatory" slots, and/or provide default values for slots missing
;; from `fields'?
(pcase-let*
- ((class (cl--find-class type))
+ ((`(,type . ,fields) type-and-slots)
+ (class (cl--find-class type))
(slots (oclosure--class-slots class))
(slotbinds (mapcar (lambda (slot)
(list (cl--slot-descriptor-name slot)))
diff --git a/lisp/kmacro.el b/lisp/kmacro.el
index 93a93a461b..89df60f190 100644
--- a/lisp/kmacro.el
+++ b/lisp/kmacro.el
@@ -823,7 +823,7 @@ If kbd macro currently being defined end it before
activating it."
;; or only `mac' is provided, as a list (MAC COUNTER FORMAT).
;; The first is used from `insert-kbd-macro' and `edmacro-finish-edit',
;; while the second is used from within this file.
- (oclosure-lambda kmacro-function ((mac (if counter (list mac counter format)
mac)))
+ (oclosure-lambda (kmacro-function (mac (if counter (list mac counter format)
mac)))
(&optional arg)
(interactive "p")
(kmacro-exec-ring-item mac arg)))
@@ -842,7 +842,7 @@ If kbd macro currently being defined end it before
activating it."
(cl-typep x 'kmacro-function))
(cl-defmethod cl-print-object ((object kmacro-function) stream)
- (princ "#<kmacro " stream)
+ (princ "#f(kmacro " stream)
(require 'macros)
(declare-function macros--insert-vector-macro "macros" (definition))
(pcase-let ((`(,vecdef ,counter ,format)
@@ -856,7 +856,7 @@ If kbd macro currently being defined end it before
activating it."
(prin1 counter stream)
(princ " " stream)
(prin1 format stream)
- (princ ">" stream)))
+ (princ ")" stream)))
(defun kmacro-bind-to-key (_arg)
"When not defining or executing a macro, offer to bind last macro to a key.
- branch scratch/oclosure created (now de320e2003), Stefan Monnier, 2021/12/31
- scratch/oclosure 5574871ec7 09/25: nadvice.el: Use OClosures rather than handmade bytecodes, Stefan Monnier, 2021/12/31
- scratch/oclosure f11349ed20 03/25: * lisp/emacs-lisp/cl-generic.el: Use OClosure for `cl-next-method-p`, Stefan Monnier, 2021/12/31
- scratch/oclosure 230617c90c 16/25: lisp/emacs-lisp/oclosure.el: Signal errors for invalid code, Stefan Monnier, 2021/12/31
- scratch/oclosure e052bb2770 04/25: * lisp/kmacro.el: Use OClosure instead of messing with internals, Stefan Monnier, 2021/12/31
- scratch/oclosure ae493f3513 01/25: OClosure: Hybrids between functions and defstructs, Stefan Monnier, 2021/12/31
- scratch/oclosure ae0bfc4f75 05/25: * lisp/loadup.el (oclosure): Load before `nadvice`, Stefan Monnier, 2021/12/31
- scratch/oclosure afa68def26 11/25: cl-print.el: Dispatch on `advice` type, Stefan Monnier, 2021/12/31
- scratch/oclosure fe5457ff75 19/25: oclosure.el (oclosure-lambda): Change calling convention,
Stefan Monnier <=
- scratch/oclosure d93b0ad4d4 06/25: (interactive-form, function-docstring): New generic functions, Stefan Monnier, 2021/12/31
- scratch/oclosure a444d85977 08/25: Fix bootstrap problems and various misc issues found along the way, Stefan Monnier, 2021/12/31
- scratch/oclosure f44ee8cd53 17/25: oclosure.el (accessor): New type, Stefan Monnier, 2021/12/31
- scratch/oclosure 55a8e92413 20/25: oclosure.el: Add support for mutable slots, Stefan Monnier, 2021/12/31
- scratch/oclosure bc1d94a0d8 21/25: * lisp/emacs-lisp/oclosure.el (Commentary:): Add a few notes, Stefan Monnier, 2021/12/31
- scratch/oclosure 263172dbfb 02/25: lisp/emacs-lisp/oclosure.el: Make it available to cl-generic, Stefan Monnier, 2021/12/31
- scratch/oclosure 3119e59252 07/25: lisp/emacs-lisp/oclosure.el: Rename `oclosure-make` to `oclosure-lambda`, Stefan Monnier, 2021/12/31
- scratch/oclosure 9465a7e59e 10/25: nadvice.el: Restore interactive-form handling, Stefan Monnier, 2021/12/31
- scratch/oclosure 3c9d64b602 14/25: cl-macs.el (cl--transform-lambda): Fix last change, Stefan Monnier, 2021/12/31
- scratch/oclosure 01002ebba0 18/25: oclosure.el (oclosure-define): Use `oclosure--copy` to define accessors, Stefan Monnier, 2021/12/31