summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2008-02-20 17:32:08 +0100
committerMatthias Benkard <code@mail.matthias.benkard.de>2008-02-20 17:32:08 +0100
commitf2927707a802a4518e86ea1f561373a87a0f4f7d (patch)
treef7eddeefdb340ce4174360c4b830d105c96d5dcd
parente647d39511c3e3e158e3046ea3292aaa9145952b (diff)
Collect and register all known Objective-C classes at load time.
darcs-hash:13dc5d5f8a456e4603e7ced00cf52b3e01e273c2
-rw-r--r--Lisp/class-definition.lisp8
-rw-r--r--Lisp/libobjcl.lisp1
-rw-r--r--Lisp/method-invocation.lisp25
-rw-r--r--Lisp/post-init.lisp23
-rw-r--r--Lisp/type-conversion.lisp43
-rw-r--r--objective-cl.asd20
6 files changed, 89 insertions, 31 deletions
diff --git a/Lisp/class-definition.lisp b/Lisp/class-definition.lisp
index 938cf50..51bb12d 100644
--- a/Lisp/class-definition.lisp
+++ b/Lisp/class-definition.lisp
@@ -341,6 +341,14 @@
class)
+(defcallback collect-class :void ((class :pointer))
+ (find-objc-class (%objcl-class-name class)))
+
+
+(defun collect-classes ()
+ (%objcl-for-each-class-do (callback collect-class)))
+
+
;;;; (@* "Quick tests")
#+(or)
(make-instance 'objective-c-class :wrapped-foreign-class "NSString")
diff --git a/Lisp/libobjcl.lisp b/Lisp/libobjcl.lisp
index a42300e..e6b1b9a 100644
--- a/Lisp/libobjcl.lisp
+++ b/Lisp/libobjcl.lisp
@@ -351,7 +351,6 @@ conventional case for namespace identifiers in Objective-C."
(find-objc-meta-class
class-name-string))
:pointer class-ptr
- :wrapped-foreign-class class-name-string
;; FIXME: It might be desirable to do
;; set the list of direct superclasses
;; to something like the following:
diff --git a/Lisp/method-invocation.lisp b/Lisp/method-invocation.lisp
index d1412bf..03e2ab7 100644
--- a/Lisp/method-invocation.lisp
+++ b/Lisp/method-invocation.lisp
@@ -453,31 +453,6 @@ easier to use with __apply__.
selector)))))))
-(defun convert-from-foreign-value (foreign-value-cell typespec
- skip-retaining-p char-is-bool-p)
- (let ((c-type (typespec->c-type typespec)))
- (case (or (typespec-nominal-type typespec)
- (typespec-primary-type typespec))
- ((id objective-c-class exception selector)
- (let ((*skip-retaining*
- skip-retaining-p))
- (intern-pointer-wrapper (car typespec)
- :pointer (cffi:mem-ref foreign-value-cell
- c-type))))
- ((:char :unsigned-char)
- ;; FIXME? This is non-trivial. See policy.lisp for
- ;; details.
- (objc-char->lisp-value (cffi:mem-ref foreign-value-cell c-type)
- char-is-bool-p))
- ((struct union)
- ;; The caller is responsible for preventing the return
- ;; value from being garbage-collected by setting
- ;; FOREIGN-VALUE-LISP-MANAGED-P to false.
- (make-struct-wrapper foreign-value-cell typespec t))
- ((:void) (values))
- (otherwise (cffi:mem-ref foreign-value-cell c-type)))))
-
-
;;; (@* "Helper functions")
(defun constructor-name-p (method-name)
(flet ((method-name-starts-with (prefix)
diff --git a/Lisp/post-init.lisp b/Lisp/post-init.lisp
new file mode 100644
index 0000000..6585bb9
--- /dev/null
+++ b/Lisp/post-init.lisp
@@ -0,0 +1,23 @@
+;;;; Objective-CL, an Objective-C bridge for Common Lisp.
+;;;; Copyright (C) 2007 Matthias Andreas Benkard.
+;;;;
+;;;; This program is free software: you can redistribute it and/or
+;;;; modify it under the terms of the GNU Lesser General Public License
+;;;; as published by the Free Software Foundation, either version 3 of
+;;;; the License, or (at your option) any later version.
+;;;;
+;;;; This program is distributed in the hope that it will be useful, but
+;;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;;; Lesser General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU Lesser General Public
+;;;; License along with this program. If not, see
+;;;; <http://www.gnu.org/licenses/>.
+
+(in-package #:mulk.objective-cl)
+
+(eval-when (:load-toplevel)
+ (format t "~&Collecting Objective-C classes.")
+ (collect-classes)
+ (format t "~&All Objective-C classes collected."))
diff --git a/Lisp/type-conversion.lisp b/Lisp/type-conversion.lisp
new file mode 100644
index 0000000..6eca43b
--- /dev/null
+++ b/Lisp/type-conversion.lisp
@@ -0,0 +1,43 @@
+;;;; Objective-CL, an Objective-C bridge for Common Lisp.
+;;;; Copyright (C) 2007, 2008 Matthias Andreas Benkard.
+;;;;
+;;;; This program is free software: you can redistribute it and/or
+;;;; modify it under the terms of the GNU Lesser General Public License
+;;;; as published by the Free Software Foundation, either version 3 of
+;;;; the License, or (at your option) any later version.
+;;;;
+;;;; This program is distributed in the hope that it will be useful, but
+;;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;;; Lesser General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU Lesser General Public
+;;;; License along with this program. If not, see
+;;;; <http://www.gnu.org/licenses/>.
+
+(in-package #:mulk.objective-cl)
+
+
+(defun convert-from-foreign-value (foreign-value-cell typespec
+ skip-retaining-p char-is-bool-p)
+ (let ((c-type (typespec->c-type typespec)))
+ (case (or (typespec-nominal-type typespec)
+ (typespec-primary-type typespec))
+ ((id objective-c-class exception selector)
+ (let ((*skip-retaining*
+ skip-retaining-p))
+ (intern-pointer-wrapper (car typespec)
+ :pointer (cffi:mem-ref foreign-value-cell
+ c-type))))
+ ((:char :unsigned-char)
+ ;; FIXME? This is non-trivial. See policy.lisp for
+ ;; details.
+ (objc-char->lisp-value (cffi:mem-ref foreign-value-cell c-type)
+ char-is-bool-p))
+ ((struct union)
+ ;; The caller is responsible for preventing the return
+ ;; value from being garbage-collected by setting
+ ;; FOREIGN-VALUE-LISP-MANAGED-P to false.
+ (make-struct-wrapper foreign-value-cell typespec t))
+ ((:void) (values))
+ (otherwise (cffi:mem-ref foreign-value-cell c-type))))) \ No newline at end of file
diff --git a/objective-cl.asd b/objective-cl.asd
index d595746..0f9dc2f 100644
--- a/objective-cl.asd
+++ b/objective-cl.asd
@@ -51,6 +51,12 @@
"memory-management"))
(:file "init" :depends-on ("defpackage"
"libobjcl"))
+ (:file "type-conversion" :depends-on ("defpackage"
+ "memory-management"
+ "data-types"
+ "type-handling"
+ "policy"
+ "data-types"))
(:file "type-handling" :depends-on ("defpackage"
"libobjcl"
"init"))
@@ -59,6 +65,7 @@
"parameters"
"conditions"))
(:file "method-invocation" :depends-on ("defpackage"
+ "type-conversion"
"type-handling"
"name-conversion"
"data-types"
@@ -67,8 +74,7 @@
"parameters"
"init"
"conditions"
- "memory-management"
- "policy"))
+ "memory-management"))
(:file "reader-syntax" :depends-on ("defpackage"
"method-invocation"))
(:file "utilities" :depends-on ("init"
@@ -77,8 +83,8 @@
"data-types"))
(:file "class-definition" :depends-on ("defpackage"
"libobjcl"
- "init"
- "method-invocation"
+ "type-conversion"
+ "type-handling"
"data-types"))
(:file "instance-management" :depends-on ("defpackage"
"libobjcl"
@@ -86,5 +92,9 @@
"method-invocation"))
(:file "compiler-macros" :depends-on ("defpackage"
"method-invocation"
- "conditions")))))
+ "conditions"))
+ (:file "post-init" :depends-on ("defpackage"
+ "libobjcl"
+ "init"
+ "class-definition")))))
:serial t)