summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2007-09-21 19:52:30 +0200
committerMatthias Benkard <code@mail.matthias.benkard.de>2007-09-21 19:52:30 +0200
commit7765ad52e00034edd23bb09bade83d8b282f8040 (patch)
tree61f3087a64d9667c80ce4bec853b26f8c858927e
parente8081745f009f2f7c3dc9b46d072094e6bab30d6 (diff)
Objective-C layer: Add functions for determining the Objective-C runtime used and for asking for the size of types by typespec.
darcs-hash:197f36840c1568c5b3431833a0118d06729b9247
-rw-r--r--Lisp/defpackage.lisp8
-rw-r--r--Lisp/init.lisp8
-rw-r--r--Lisp/libobjcl.lisp31
-rw-r--r--Objective-C/libobjcl.h12
-rw-r--r--Objective-C/libobjcl.m38
5 files changed, 96 insertions, 1 deletions
diff --git a/Lisp/defpackage.lisp b/Lisp/defpackage.lisp
index 0de0341..2a04fb6 100644
--- a/Lisp/defpackage.lisp
+++ b/Lisp/defpackage.lisp
@@ -41,4 +41,12 @@
;; Metaclasses
#:objective-c-class))
+
+(defpackage #:mulk.objective-cl-features
+ (:nicknames #:objcl-features #:objective-cl-features #:mulk.objcl-features)
+ (:use)
+ (:export #:gnu-runtime
+ #:next-runtime))
+
+
#-(or cmu sbcl) (declaim (declaration values))
diff --git a/Lisp/init.lisp b/Lisp/init.lisp
index 72d616f..a56d2e2 100644
--- a/Lisp/init.lisp
+++ b/Lisp/init.lisp
@@ -9,4 +9,10 @@
(unless (boundp '+yes+)
(defconstant +yes+ (objcl-get-yes)))
(unless (boundp '+no+)
- (defconstant +no+ (objcl-get-no))))
+ (defconstant +no+ (objcl-get-no)))
+ (unless (boundp '+runtime-type+)
+ (defconstant +runtime-type+ (runtime-type)))
+ (pushnew (case +runtime-type+
+ ((:gnu) 'objcl-features:gnu-runtime)
+ ((:next) 'objcl-features:next-runtime))
+ *features*))
diff --git a/Lisp/libobjcl.lisp b/Lisp/libobjcl.lisp
index 1d14e8b..d2f3e3c 100644
--- a/Lisp/libobjcl.lisp
+++ b/Lisp/libobjcl.lisp
@@ -64,6 +64,17 @@
:pointer
(obj :pointer))
+(defcfun ("objcl_get_runtime_type" %objcl-get-runtime-type) :string)
+
+(defcfun ("objcl_sizeof_type" %objcl-sizeof-type) :long
+ (typespec :string))
+
+(defcfun ("objcl_sizeof_return_type" %objcl-sizeof-return-type) :long
+ (typespec :string))
+
+(defcfun ("objcl_alignof_type" %objcl-alignof-type) :long
+ (typespec :string))
+
(defcfun objcl-get-nil :pointer)
(defcfun objcl-get-yes :long)
(defcfun objcl-get-no :long)
@@ -523,3 +534,23 @@ Returns: (VALUES typespec byte-position string-position)"
byte-position)
#-(or) nil
string-position)))
+
+
+;;;; (@* "Helper functions")
+(defun sizeof (typespec)
+ (%objcl-sizeof-type typespec))
+
+(defun alignof (typespec)
+ (%objcl-alignof-type typespec))
+
+(defun return-type-sizeof (typespec)
+ (%objcl-sizeof-return-type typespec))
+
+(defun runtime-type ()
+ (let ((runtime (%objcl-get-runtime-type)))
+ (assert (member runtime '("GNU" "NeXT") :test #'string=)
+ (runtime)
+ "Unkown Objective-C runtime type ~S. Allowed: (\"GNU\" \"NeXT\")."
+ runtime)
+ (cond ((string= runtime "GNU") :gnu)
+ ((string= runtime "NeXT") :next))))
diff --git a/Objective-C/libobjcl.h b/Objective-C/libobjcl.h
index c84dbb9..2ebea37 100644
--- a/Objective-C/libobjcl.h
+++ b/Objective-C/libobjcl.h
@@ -69,3 +69,15 @@ objcl_get_yes (void);
long
objcl_get_no (void);
+
+const char *
+objcl_get_runtime_type (void);
+
+long
+objcl_sizeof_type (const char *typespec);
+
+long
+objcl_sizeof_return_type (const char *typespec);
+
+long
+objcl_alignof_type (const char *typespec);
diff --git a/Objective-C/libobjcl.m b/Objective-C/libobjcl.m
index 205a998..8c4f3fd 100644
--- a/Objective-C/libobjcl.m
+++ b/Objective-C/libobjcl.m
@@ -248,3 +248,41 @@ objcl_get_no (void)
fprintf (stderr, "WARNING: objcl_get_no: NO might not fit into a long.\n");
return NO;
}
+
+
+const char *
+objcl_get_runtime_type (void)
+{
+#ifdef __NEXT_RUNTIME__
+ return "NeXT";
+#else
+ return "GNU";
+#endif
+}
+
+
+long
+objcl_sizeof_type (const char *typespec)
+{
+ if (sizeof (ssize_t) > sizeof (long))
+ fprintf (stderr, "WARNING: objcl_sizeof_typespec: Size might not fit into a long.\n");
+ return PyObjCRT_SizeOfType (typespec);
+}
+
+
+long
+objcl_sizeof_return_type (const char *typespec)
+{
+ if (sizeof (ssize_t) > sizeof (long))
+ fprintf (stderr, "WARNING: objcl_sizeof_return_typespec: Size might not fit into a long.\n");
+ return PyObjCRT_SizeOfReturnType (typespec);
+}
+
+
+long
+objcl_alignof_type (const char *typespec)
+{
+ if (sizeof (ssize_t) > sizeof (long))
+ fprintf (stderr, "WARNING: objcl_align_typespec: Alignment might not fit into a long.\n");
+ return PyObjCRT_AlignOfType (typespec);
+}