Skip to content
Browse files

Merge branch 'master' into iOSSupport

Conflicts:
	ObjectiveHaskell.xcodeproj/project.pbxproj
	ObjectiveHaskell.xcodeproj/xcshareddata/xcschemes/ObjectiveHaskell Mac.xcscheme
  • Loading branch information...
2 parents d4b766f + 3096e79 commit fd9ba238a698323d314b609085b1c4e9c7ca712d @jspahrsummers committed
View
12 ObjectiveHaskell.xcodeproj/project.pbxproj
@@ -40,12 +40,13 @@
D09061EF15B0DD37001CAC43 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D09061EE15B0DD37001CAC43 /* Cocoa.framework */; };
D090620115B0DD38001CAC43 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D090620015B0DD38001CAC43 /* SenTestingKit.framework */; };
D090620215B0DD38001CAC43 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D09061EE15B0DD37001CAC43 /* Cocoa.framework */; };
- D090620515B0DD38001CAC43 /* libObjectiveHaskell.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D09061EB15B0DD37001CAC43 /* libObjectiveHaskell.a */; };
+ D090620515B0DD38001CAC43 /* libObjectiveHaskell Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D09061EB15B0DD37001CAC43 /* libObjectiveHaskell Mac.a */; };
D090620B15B0DD38001CAC43 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D090620915B0DD38001CAC43 /* InfoPlist.strings */; };
D090620E15B0DD38001CAC43 /* ObjectiveHaskellTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D090620D15B0DD38001CAC43 /* ObjectiveHaskellTests.m */; };
D090624A15B0E4C0001CAC43 /* FibTest.hs in Sources */ = {isa = PBXBuildFile; fileRef = D090624815B0E450001CAC43 /* FibTest.hs */; };
D090625015B0E613001CAC43 /* NSObject+OHInitializationExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = D090624E15B0E613001CAC43 /* NSObject+OHInitializationExtensions.m */; };
D0B232EE15B295380045568B /* libffi.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D0B232EA15B2952B0045568B /* libffi.a */; };
+ D0E61A7C15B4FFF300667D8A /* NSValue.hs in Sources */ = {isa = PBXBuildFile; fileRef = D0E61A6915B4FEDE00667D8A /* NSValue.hs */; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
@@ -172,7 +173,7 @@
D04FC23D15B2AAC300C58F14 /* compileHaskell.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = compileHaskell.sh; sourceTree = "<group>"; };
D04FC25915B2B26000C58F14 /* THUtils.hs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = THUtils.hs; sourceTree = "<group>"; };
D062D78D15B38B80003871F7 /* NSData.hs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NSData.hs; sourceTree = "<group>"; };
- D09061EB15B0DD37001CAC43 /* libObjectiveHaskell.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libObjectiveHaskell.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ D09061EB15B0DD37001CAC43 /* libObjectiveHaskell Mac.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libObjectiveHaskell Mac.a"; sourceTree = BUILT_PRODUCTS_DIR; };
D09061EE15B0DD37001CAC43 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
D09061F115B0DD37001CAC43 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
D09061F215B0DD37001CAC43 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
@@ -208,6 +209,7 @@
D090624E15B0E613001CAC43 /* NSObject+OHInitializationExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+OHInitializationExtensions.m"; sourceTree = "<group>"; };
D0B232DF15B2952B0045568B /* libffi.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = libffi.xcodeproj; path = libffi/libffi.xcodeproj; sourceTree = "<group>"; };
D0E525ED15B1122500C13802 /* MsgSend.hs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MsgSend.hs; sourceTree = "<group>"; };
+ D0E61A6915B4FEDE00667D8A /* NSValue.hs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NSValue.hs; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -245,7 +247,7 @@
files = (
D090620115B0DD38001CAC43 /* SenTestingKit.framework in Frameworks */,
D090620215B0DD38001CAC43 /* Cocoa.framework in Frameworks */,
- D090620515B0DD38001CAC43 /* libObjectiveHaskell.a in Frameworks */,
+ D090620515B0DD38001CAC43 /* libObjectiveHaskell Mac.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -448,6 +450,7 @@
D045A10B15B2794400DE48BF /* NSDictionary.hs */,
D045A10815B2793300DE48BF /* NSObject.hs */,
D045A10F15B27B4900DE48BF /* NSString.hs */,
+ D0E61A6915B4FEDE00667D8A /* NSValue.hs */,
D03E2D2D15B1599200679DB0 /* ObjC.hs */,
D04FC25915B2B26000C58F14 /* THUtils.hs */,
);
@@ -522,7 +525,7 @@
);
name = "ObjectiveHaskell Mac";
productName = ObjectiveHaskell;
- productReference = D09061EB15B0DD37001CAC43 /* libObjectiveHaskell.a */;
+ productReference = D09061EB15B0DD37001CAC43 /* libObjectiveHaskell Mac.a */;
productType = "com.apple.product-type.library.static";
};
D09061FE15B0DD38001CAC43 /* ObjectiveHaskellTests Mac */ = {
@@ -685,6 +688,7 @@
D045A10C15B27AD600DE48BF /* NSArray.hs in Sources */,
D045A11015B2807A00DE48BF /* NSString.hs in Sources */,
D062D78E15B38B90003871F7 /* NSData.hs in Sources */,
+ D0E61A7C15B4FFF300667D8A /* NSValue.hs in Sources */,
D04FC25A15B2B26F00C58F14 /* THUtils.hs in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
View
2 ObjectiveHaskell/NSArray.hs
@@ -12,7 +12,7 @@ import ObjectiveHaskell.NSObject
import ObjectiveHaskell.ObjC
-- NSArray methods
-declMessage "array" [t| Id -> IO Id |] "array"
+declMessage "array" [t| Class -> IO Id |] "array"
declMessage "addObject" [t| Id -> Id -> IO () |] "addObject:"
declMessage "objectAtIndex" [t| NSUInteger -> Id -> IO Id |] "objectAtIndex:"
View
2 ObjectiveHaskell/NSData.hs
@@ -12,7 +12,7 @@ import ObjectiveHaskell.MsgSend
import ObjectiveHaskell.ObjC
-- NSData methods
-declMessage "dataWithBytes" [t| Ptr () -> NSUInteger -> Id -> IO Id |] "dataWithBytes:length:"
+declMessage "dataWithBytes" [t| Ptr () -> NSUInteger -> Class -> IO Id |] "dataWithBytes:length:"
declMessage "objc_length" [t| Id -> IO NSUInteger |] "length"
declMessage "bytes" [t| Id -> IO (Ptr ()) |] "bytes"
View
2 ObjectiveHaskell/NSDictionary.hs
@@ -16,7 +16,7 @@ import ObjectiveHaskell.ObjC
-- NSDictionary methods
declMessage "allKeys" [t| Id -> IO Id |] "allKeys"
-declMessage "dictionary" [t| Id -> IO Id |] "dictionary"
+declMessage "dictionary" [t| Class -> IO Id |] "dictionary"
declMessage "objectForKey" [t| Id -> Id -> IO Id |] "objectForKey:"
declMessage "setObjectForKey" [t| Id -> Id -> Id -> IO () |] "setObject:forKey:"
View
24 ObjectiveHaskell/NSValue.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE FlexibleInstances #-}
+module ObjectiveHaskell.NSValue (
+ fromNSValue, toNSValue
+ ) where
+
+import Foreign.Ptr
+import ObjectiveHaskell.MsgSend
+import ObjectiveHaskell.ObjC
+
+-- NSValue methods
+declMessage "valueWithPointer" [t| Ptr () -> Id -> IO Id |] "valueWithPointer:"
+declMessage "pointerValue" [t| Id -> IO (Ptr ()) |] "pointerValue"
+
+-- Converts a pointer NSValue into a raw Ptr ()
+fromNSValue :: Id -> IO (Ptr ())
+fromNSValue val = val @. pointerValue
+
+-- Converts a Ptr () into an NSValue
+toNSValue :: Ptr () -> IO Id
+toNSValue ptr = getClass "NSValue" >>= valueWithPointer ptr
+
+instance Bridged (Ptr ()) where
+ toObjC = toNSValue
+ fromObjC = fromNSValue
View
11 ObjectiveHaskellTests/CollectionsTest.hs
@@ -1,13 +1,16 @@
module CollectionsTest where
+import Control.Applicative
import Data.ByteString as ByteString
import Data.Map as Map
import Data.Sequence as Seq
import Foreign.C.Types
+import Foreign.Ptr
import ObjectiveHaskell.NSArray
import ObjectiveHaskell.NSData
import ObjectiveHaskell.NSDictionary
import ObjectiveHaskell.NSString
+import ObjectiveHaskell.NSValue
import ObjectiveHaskell.ObjC
appendFoobar' :: Id -> IO Id
@@ -35,7 +38,15 @@ appendByte' nsdata b = do
str <- fromNSData nsdata
toNSData $ snoc str (fromIntegral b)
+nullNSValue' :: IO Id
+nullNSValue' = toNSValue nullPtr
+
+ptrAddress' :: Id -> IO CUIntPtr
+ptrAddress' obj = (fromIntegral . ptrToWordPtr) <$> fromNSValue obj
+
exportFunc "appendFoobar" [t| UnsafeId -> IO UnsafeId |] 'appendFoobar'
exportFunc "addFoobarToArray" [t| UnsafeId -> IO UnsafeId |] 'addFoobarToArray'
exportFunc "setFooToBar" [t| UnsafeId -> IO UnsafeId |] 'setFooToBar'
exportFunc "appendByte" [t| UnsafeId -> CUChar -> IO UnsafeId |] 'appendByte'
+exportFunc "nullNSValue" [t| IO UnsafeId |] 'nullNSValue'
+exportFunc "ptrAddress" [t| UnsafeId -> IO CUIntPtr |] 'ptrAddress'
View
9 ObjectiveHaskellTests/ObjectiveHaskellTests.m
@@ -39,6 +39,15 @@ - (void)testNSDictionaryBridging {
STAssertEqualObjects(dict, expectedDict, @"");
}
+- (void)testNSValueBridging {
+ NSValue *value = nullNSValue();
+ STAssertNotNil(value, @"");
+ STAssertNil(value.pointerValue, @"");
+
+ uintptr_t addr = ptrAddress(value);
+ STAssertEquals(addr, (uintptr_t)0, @"");
+}
+
- (void)testFibonacci {
STAssertEquals(3, fibonacci_hs(4), @"");
STAssertEquals(5, fibonacci_hs(5), @"");

0 comments on commit fd9ba23

Please sign in to comment.
Something went wrong with that request. Please try again.