summaryrefslogtreecommitdiff
path: root/Lisp
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2008-02-03 09:46:55 +0100
committerMatthias Benkard <code@mail.matthias.benkard.de>2008-02-03 09:46:55 +0100
commite93416cc05a38b34956e88b9516af5b910d5df19 (patch)
tree866e963d0e339601bc308dd39d2486a095e1ddee /Lisp
parentafc1b0855e777332ff9331c70dad9d22b9d4ebfc (diff)
Add a compiler macro for SELECTOR.
darcs-hash:4e7f3cf6846d15869487905f52589ee8250bcf5d
Diffstat (limited to 'Lisp')
-rw-r--r--Lisp/compiler-macros.lisp20
-rw-r--r--Lisp/method-invocation.lisp12
2 files changed, 32 insertions, 0 deletions
diff --git a/Lisp/compiler-macros.lisp b/Lisp/compiler-macros.lisp
index 72471d5..79fd0a6 100644
--- a/Lisp/compiler-macros.lisp
+++ b/Lisp/compiler-macros.lisp
@@ -66,6 +66,26 @@
form))
+;; Optimise all (SELECTOR ...) forms. This is important in order to
+;; make (FUNCALL (SELECTOR ...) ...) efficient.
+(define-compiler-macro selector (&whole form method-name)
+ (if (and (constantp method-name)
+ (not (and (listp method-name)
+ (eq 'load-time-value (car method-name)))))
+ `(load-time-value (handler-case
+ (find-selector ,method-name)
+ (serious-condition ()
+ (warn
+ (make-condition 'simple-style-warning
+ :format-control
+ "~S designates an unknown ~
+ method selector."
+ :format-arguments
+ (list ,method-name)))
+ ,method-name)))
+ form))
+
+
;; This compiler macro is a bit more complicated than the preceding
;; ones.
(define-compiler-macro invoke (receiver message-start &rest message-components)
diff --git a/Lisp/method-invocation.lisp b/Lisp/method-invocation.lisp
index 92a9c92..c0bad01 100644
--- a/Lisp/method-invocation.lisp
+++ b/Lisp/method-invocation.lisp
@@ -156,6 +156,18 @@ call to __invoke__, or an object of *type* __selector__, to *receiver*.
;=> #<GSCBufferString `Mulk.' {5B36087}>
+## Note:
+
+__selector__ objects are funcallable. Therefore, the following calls
+are all equivalent:
+
+ (invoke-by-name instance \"stringWithCString:encoding:\" \"Mulk.\" 4)
+ (invoke instance :string-with-c-string \"Mulk.\" :encoding 4)
+ (funcall (selector \"stringWithCString:encoding:\") instance \"Mulk.\" 4)
+
+In fact, using __invoke-by-name__ is discouraged in favour of the latter
+form.
+
## Rationale:
Whereas __invoke__ tries to make writing as well as reading method