From c9590d2560f9dfce731088d1b8311cc56cef2f81 Mon Sep 17 00:00:00 2001 From: slava Date: Thu, 6 Jul 2006 20:24:09 +0000 Subject: [PATCH] More Mac Intel ABI fixes -- and fuck Apple for screwing up the Objective C ABI even further --- library/bootstrap/boot-stage2.factor | 1 + library/compiler/alien/objc/load.factor | 14 +++++++++++++ .../alien/objc}/runtime.factor | 0 .../alien/objc}/subclassing.factor | 2 +- .../alien/objc}/utilities.factor | 2 +- library/compiler/ppc/objc.factor | 7 +++++++ library/compiler/x86/objc.factor | 20 +++++++++++++++++++ library/ui/cocoa/load.factor | 3 --- 8 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 library/compiler/alien/objc/load.factor rename library/{ui/cocoa => compiler/alien/objc}/runtime.factor (100%) rename library/{ui/cocoa => compiler/alien/objc}/subclassing.factor (98%) rename library/{ui/cocoa => compiler/alien/objc}/utilities.factor (99%) create mode 100644 library/compiler/ppc/objc.factor create mode 100644 library/compiler/x86/objc.factor diff --git a/library/bootstrap/boot-stage2.factor b/library/bootstrap/boot-stage2.factor index 5e64d44ead..9b98964333 100644 --- a/library/bootstrap/boot-stage2.factor +++ b/library/bootstrap/boot-stage2.factor @@ -50,6 +50,7 @@ parser sequences sequences-internals words ; "native-io" get [ init-io ] when "cocoa" get [ + "/library/compiler/alien/objc/load.factor" run-resource "/library/ui/cocoa/load.factor" run-resource ] when diff --git a/library/compiler/alien/objc/load.factor b/library/compiler/alien/objc/load.factor new file mode 100644 index 0000000000..df04705ac5 --- /dev/null +++ b/library/compiler/alien/objc/load.factor @@ -0,0 +1,14 @@ +USING: kernel parser sequences ; + +{ + { [ cpu "x86" = ] [ "/library/compiler/x86/objc.factor" ] } + { [ cpu "ppc" = ] [ "/library/compiler/ppc/objc.factor" ] } +} cond run-resource + +{ + "/library/compiler/alien/objc/runtime.factor" + "/library/compiler/alien/objc/utilities.factor" + "/library/compiler/alien/objc/subclassing.factor" +} [ + run-resource +] each diff --git a/library/ui/cocoa/runtime.factor b/library/compiler/alien/objc/runtime.factor similarity index 100% rename from library/ui/cocoa/runtime.factor rename to library/compiler/alien/objc/runtime.factor diff --git a/library/ui/cocoa/subclassing.factor b/library/compiler/alien/objc/subclassing.factor similarity index 98% rename from library/ui/cocoa/subclassing.factor rename to library/compiler/alien/objc/subclassing.factor index 927984a152..d7e1f74b3e 100644 --- a/library/ui/cocoa/subclassing.factor +++ b/library/compiler/alien/objc/subclassing.factor @@ -66,7 +66,7 @@ libc math namespaces sequences strings words ; : struct-return ( ret types quot -- ret types quot ) pick c-struct? [ - pick c-size [ memcpy ] curry append + pick c-size [ memcpy (pre-stret) ] curry append >r { "void*" } swap append >r drop "void" r> r> ] when ; diff --git a/library/ui/cocoa/utilities.factor b/library/compiler/alien/objc/utilities.factor similarity index 99% rename from library/ui/cocoa/utilities.factor rename to library/compiler/alien/objc/utilities.factor index a593d15a71..66dde73418 100644 --- a/library/ui/cocoa/utilities.factor +++ b/library/compiler/alien/objc/utilities.factor @@ -14,7 +14,7 @@ kernel libc math namespaces parser sequences strings words ; [ "void" f ] % "_stret" append , { "void*" } swap second append , - ] make-alien-invoke ; + ] make-alien-invoke \ (post-stret) add ; : use-stret? ( type -- ? ) #! We use the objc_msgSend_stret form in either of the diff --git a/library/compiler/ppc/objc.factor b/library/compiler/ppc/objc.factor new file mode 100644 index 0000000000..2295d15f6f --- /dev/null +++ b/library/compiler/ppc/objc.factor @@ -0,0 +1,7 @@ +! Copyright (C) 2006 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +IN: objc + +: (post-stret) ; inline + +: (pre-stret) ; inline diff --git a/library/compiler/x86/objc.factor b/library/compiler/x86/objc.factor new file mode 100644 index 0000000000..4a5ffcd53d --- /dev/null +++ b/library/compiler/x86/objc.factor @@ -0,0 +1,20 @@ +! Copyright (C) 2006 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +IN: objc + +! In their infinite wisdom, Apple's struct-returning Objective C +! messages do not use their own documented ABI; instead they +! pop one of the input parameters off the stack. We compensate +! for that here. + +! when calling an stret via objc_msgSend_stret, it pops the +! struct off the stack for us! +: (post-stret) ; + +\ (post-stret) [ EAX PUSH ] H{ } define-intrinsic + +! when an _stret is being called, we must pop the struct off +! the stack before returning +: (pre-stret) ; + +\ (pre-stret) [ EAX POP ECX POP EAX PUSH ] H{ } define-intrinsic diff --git a/library/ui/cocoa/load.factor b/library/ui/cocoa/load.factor index aa89d9c43e..5eb4c75c42 100644 --- a/library/ui/cocoa/load.factor +++ b/library/ui/cocoa/load.factor @@ -1,9 +1,6 @@ USING: compiler io parser sequences words ; { - "/library/ui/cocoa/runtime.factor" - "/library/ui/cocoa/utilities.factor" - "/library/ui/cocoa/subclassing.factor" "/library/ui/cocoa/core-foundation.factor" "/library/ui/cocoa/types.factor" "/library/ui/cocoa/init-cocoa.factor"