2 Commits
40 changed files with 318 additions and 1471 deletions
+154 -874
View File
File diff suppressed because it is too large Load Diff
-3
View File
@@ -1,3 +0,0 @@
module SwHaLib {
export *
}
-115
View File
@@ -1,115 +0,0 @@
//
// AppDelegate.swift
// SwiftAppLibrary
//
// Created by NanoTech on 2017-02-09.
// Copyright © 2017 nanotech. All rights reserved.
//
import Cocoa
import SwiftHaskell
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var label: NSTextField!
func applicationDidFinishLaunching(_ aNotification: Notification) {
let bytes: [UInt8] = [1, 2, 3, 2, 1, 2]
callbackExample { n in
print(n)
}
var callbackResult: CInt? = nil
contextCallbackExample { n in
callbackResult = n
}
let m = Multiplier(5)
label.stringValue = [
"5^2 = \(square(5))",
"2 occurs \(count(byte: 2, in: bytes)) times in \(bytes)",
"getSequence returned \(getSequence())",
"Context callback returned \(callbackResult)",
"5 * 3 = \(m.multiply(3))",
].joined(separator: "\n")
}
func applicationWillTerminate(_ aNotification: Notification) {
}
}
// Swift to Haskell ByteString Example
func count(byte: UInt8, in bytes: [UInt8]) -> Int {
var r = 0
bytes.withUnsafeBufferPointer { bytesBufPtr in
r = Int(SwiftHaskell.countBytes(byte,
HsPtr(mutating: bytesBufPtr.baseAddress),
HsWord64(bytesBufPtr.count)))
}
return r
}
// Haskell to Swift ByteString Example
func getSequence() -> [UInt8] {
var n = 0
let p = SwiftHaskell.getSequence(&n).assumingMemoryBound(to: UInt8.self)
let a = [UInt8](UnsafeBufferPointer(start: p, count: n))
free(p)
return a
}
// Swift to Haskell Callback Example
func callbackExample(f: (@convention(c) (CInt) -> Void)) {
let hsf = unsafeBitCast(f, to: HsFunPtr.self)
SwiftHaskell.callbackExample(hsf)
}
// Swift to Haskell Callback with Context Example
func contextCallbackExample(f: ((CInt) -> Void)) {
class Wrap<T> {
var inner: T
init(_ inner: T) {
self.inner = inner
}
}
let x = 3
func release(context: HsPtr) {
let _: Wrap<(CInt) -> Void> = Unmanaged.fromOpaque(context).takeRetainedValue()
}
func call(context: HsPtr, value: CInt) {
let wf: Wrap<(CInt) -> Void> = Unmanaged.fromOpaque(context).takeUnretainedValue()
let f = wf.inner
f(value)
}
let release_hs = unsafeBitCast(
release as @convention(c) (HsPtr) -> Void, to: HsFunPtr.self)
let call_hs = unsafeBitCast(
call as @convention(c) (HsPtr, CInt) -> Void, to: HsFunPtr.self)
let ctx = Unmanaged.passRetained(Wrap(f)).toOpaque()
SwiftHaskell.contextCallbackExample(ctx, release_hs, call_hs)
}
// Swift to Haskell Function Example
class Multiplier {
let funPtr: HsFunPtr
init(_ x: CInt) {
self.funPtr = SwiftHaskell.makeMultiplier(x)
}
func multiply(_ y: CInt) -> CInt {
typealias F = @convention(c) (CInt) -> CInt
let f = unsafeBitCast(self.funPtr, to: F.self)
return f(y)
}
deinit {
SwiftHaskell.freeMultiplier(self.funPtr)
}
}
-26
View File
@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017 nanotech. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
-19
View File
@@ -1,19 +0,0 @@
//
// SwiftAppLibrary.h
// SwiftAppLibrary
//
// Created by NanoTech on 2017-02-08.
// Copyright © 2017 nanotech. All rights reserved.
//
#import <Cocoa/Cocoa.h>
//! Project version number for SwiftAppLibrary.
FOUNDATION_EXPORT double SwiftAppLibraryVersionNumber;
//! Project version string for SwiftAppLibrary.
FOUNDATION_EXPORT const unsigned char SwiftAppLibraryVersionString[];
FOUNDATION_EXPORT void runNSApplication(void);
// In this header, you should import all the public headers of your framework using statements like #import <SwiftAppLibrary/PublicHeader.h>
-13
View File
@@ -1,13 +0,0 @@
#import "SwiftAppLibrary.h"
@interface AClassInThisFramework : NSObject @end
@implementation AClassInThisFramework @end
void runNSApplication(void) {
NSApplication *app = [NSApplication sharedApplication];
NSBundle *bundle = [NSBundle bundleForClass:[AClassInThisFramework class]];
NSArray *topObjects;
[[[NSNib alloc] initWithNibNamed:@"MainMenu" bundle:bundle]
instantiateWithOwner:app topLevelObjects:&topObjects];
[app run];
}
+99 -243
View File
@@ -7,187 +7,136 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
BFABC4601E4C1DD1006036C6 /* SwiftAppLibrary.h in Headers */ = {isa = PBXBuildFile; fileRef = BFABC45E1E4C1DD1006036C6 /* SwiftAppLibrary.h */; settings = {ATTRIBUTES = (Public, ); }; }; BFABC4321E4BE794006036C6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFABC4311E4BE794006036C6 /* AppDelegate.swift */; };
BFABC4CD1E4D627E006036C6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFABC4CC1E4D627E006036C6 /* AppDelegate.swift */; }; BFABC4341E4BE794006036C6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BFABC4331E4BE794006036C6 /* Assets.xcassets */; };
BFABC4D21E4D664D006036C6 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = BFABC4D01E4D664D006036C6 /* MainMenu.xib */; }; BFABC4371E4BE794006036C6 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = BFABC4351E4BE794006036C6 /* MainMenu.xib */; };
BFABC4E01E4D781D006036C6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BFABC4DF1E4D781D006036C6 /* Assets.xcassets */; }; BFABC4C31E4C26C8006036C6 /* libswifthaskell.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BFABC4C21E4C26C8006036C6 /* libswifthaskell.dylib */; };
BFABC4ED1E4D78E5006036C6 /* SwiftHaskell in Copy Files */ = {isa = PBXBuildFile; fileRef = BFABC4EA1E4D78D9006036C6 /* SwiftHaskell */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; BFABC4C61E4C26DF006036C6 /* libHSrts_thr-ghc8.0.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BFABC4C51E4C26DF006036C6 /* libHSrts_thr-ghc8.0.1.dylib */; };
BFABC4F01E4D7951006036C6 /* SwiftAppLibrary.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BFABC45B1E4C1DD1006036C6 /* SwiftAppLibrary.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; BFABC4C81E4C26E2006036C6 /* libffi.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BFABC4C71E4C26E2006036C6 /* libffi.dylib */; };
BFE4CC421E55553000F232D6 /* SwiftAppLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = BFE4CC411E55553000F232D6 /* SwiftAppLibrary.m */; }; BFABC4C91E4C2746006036C6 /* libswifthaskell.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = BFABC4C21E4C26C8006036C6 /* libswifthaskell.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
BFABC4CA1E4C2746006036C6 /* libffi.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = BFABC4C71E4C26E2006036C6 /* libffi.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
BFABC4CB1E4C2746006036C6 /* libHSrts_thr-ghc8.0.1.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = BFABC4C51E4C26DF006036C6 /* libHSrts_thr-ghc8.0.1.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
BFABC4E81E4D7842006036C6 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = BFABC4521E4C1DD1006036C6 /* Project object */;
proxyType = 1;
remoteGlobalIDString = BFABC45A1E4C1DD1006036C6;
remoteInfo = SwiftAppLibrary;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
BFABC4EC1E4D78DF006036C6 /* Copy Files */ = { BFABC44B1E4C1BFA006036C6 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 6;
files = (
BFABC4ED1E4D78E5006036C6 /* SwiftHaskell in Copy Files */,
);
name = "Copy Files";
runOnlyForDeploymentPostprocessing = 0;
};
BFABC4EF1E4D7948006036C6 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase; isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
BFABC4F01E4D7951006036C6 /* SwiftAppLibrary.framework in Embed Frameworks */, BFABC4C91E4C2746006036C6 /* libswifthaskell.dylib in CopyFiles */,
BFABC4CA1E4C2746006036C6 /* libffi.dylib in CopyFiles */,
BFABC4CB1E4C2746006036C6 /* libHSrts_thr-ghc8.0.1.dylib in CopyFiles */,
); );
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
BFABC45B1E4C1DD1006036C6 /* SwiftAppLibrary.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftAppLibrary.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BFABC42E1E4BE794006036C6 /* SwiftHaskell.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftHaskell.app; sourceTree = BUILT_PRODUCTS_DIR; };
BFABC45E1E4C1DD1006036C6 /* SwiftAppLibrary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftAppLibrary.h; sourceTree = "<group>"; }; BFABC4311E4BE794006036C6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
BFABC45F1E4C1DD1006036C6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; BFABC4331E4BE794006036C6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
BFABC4CC1E4D627E006036C6 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; BFABC4361E4BE794006036C6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
BFABC4D11E4D664D006036C6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = MainMenu.xib; sourceTree = "<group>"; }; BFABC4381E4BE794006036C6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
BFABC4D71E4D781D006036C6 /* SwiftHaskell.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftHaskell.app; sourceTree = BUILT_PRODUCTS_DIR; }; BFABC4461E4C011B006036C6 /* SwiftHaskell-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SwiftHaskell-Bridging-Header.h"; sourceTree = "<group>"; };
BFABC4DF1E4D781D006036C6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; BFABC4C21E4C26C8006036C6 /* libswifthaskell.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libswifthaskell.dylib; path = build/libswifthaskell.dylib; sourceTree = "<group>"; };
BFABC4E41E4D781D006036C6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; BFABC4C51E4C26DF006036C6 /* libHSrts_thr-ghc8.0.1.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libHSrts_thr-ghc8.0.1.dylib"; path = "build/libHSrts_thr-ghc8.0.1.dylib"; sourceTree = "<group>"; };
BFABC4EA1E4D78D9006036C6 /* SwiftHaskell */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; name = SwiftHaskell; path = build/SwiftHaskell; sourceTree = SOURCE_ROOT; }; BFABC4C71E4C26E2006036C6 /* libffi.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libffi.dylib; path = build/libffi.dylib; sourceTree = "<group>"; };
BFE4CC411E55553000F232D6 /* SwiftAppLibrary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SwiftAppLibrary.m; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
BFABC4571E4C1DD1006036C6 /* Frameworks */ = { BFABC42B1E4BE794006036C6 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
BFABC4C31E4C26C8006036C6 /* libswifthaskell.dylib in Frameworks */,
BFABC4C81E4C26E2006036C6 /* libffi.dylib in Frameworks */,
BFABC4C61E4C26DF006036C6 /* libHSrts_thr-ghc8.0.1.dylib in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
/* End PBXFrameworksBuildPhase section */ /* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
BFABC4511E4C1DD1006036C6 = { BFABC4251E4BE794006036C6 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
BFABC4D81E4D781D006036C6 /* SwiftHaskell */, BFABC4301E4BE794006036C6 /* SwiftHaskell */,
BFABC45D1E4C1DD1006036C6 /* SwiftAppLibrary */, BFABC4C41E4C26CA006036C6 /* Libraries */,
BFABC45C1E4C1DD1006036C6 /* Products */, BFABC42F1E4BE794006036C6 /* Products */,
); );
sourceTree = "<group>"; sourceTree = "<group>";
}; };
BFABC45C1E4C1DD1006036C6 /* Products */ = { BFABC42F1E4BE794006036C6 /* Products */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
BFABC45B1E4C1DD1006036C6 /* SwiftAppLibrary.framework */, BFABC42E1E4BE794006036C6 /* SwiftHaskell.app */,
BFABC4D71E4D781D006036C6 /* SwiftHaskell.app */,
); );
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
BFABC45D1E4C1DD1006036C6 /* SwiftAppLibrary */ = { BFABC4301E4BE794006036C6 /* SwiftHaskell */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
BFABC45E1E4C1DD1006036C6 /* SwiftAppLibrary.h */, BFABC4311E4BE794006036C6 /* AppDelegate.swift */,
BFE4CC411E55553000F232D6 /* SwiftAppLibrary.m */, BFABC4461E4C011B006036C6 /* SwiftHaskell-Bridging-Header.h */,
BFABC4CC1E4D627E006036C6 /* AppDelegate.swift */, BFABC4331E4BE794006036C6 /* Assets.xcassets */,
BFABC4D01E4D664D006036C6 /* MainMenu.xib */, BFABC4351E4BE794006036C6 /* MainMenu.xib */,
BFABC45F1E4C1DD1006036C6 /* Info.plist */, BFABC4381E4BE794006036C6 /* Info.plist */,
);
path = SwiftAppLibrary;
sourceTree = "<group>";
};
BFABC4D81E4D781D006036C6 /* SwiftHaskell */ = {
isa = PBXGroup;
children = (
BFABC4DF1E4D781D006036C6 /* Assets.xcassets */,
BFABC4EA1E4D78D9006036C6 /* SwiftHaskell */,
BFABC4E41E4D781D006036C6 /* Info.plist */,
); );
path = SwiftHaskell; path = SwiftHaskell;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
BFABC4C41E4C26CA006036C6 /* Libraries */ = {
isa = PBXGroup;
children = (
BFABC4C21E4C26C8006036C6 /* libswifthaskell.dylib */,
BFABC4C71E4C26E2006036C6 /* libffi.dylib */,
BFABC4C51E4C26DF006036C6 /* libHSrts_thr-ghc8.0.1.dylib */,
);
name = Libraries;
sourceTree = "<group>";
};
/* End PBXGroup section */ /* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
BFABC4581E4C1DD1006036C6 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
BFABC4601E4C1DD1006036C6 /* SwiftAppLibrary.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */ /* Begin PBXNativeTarget section */
BFABC45A1E4C1DD1006036C6 /* SwiftAppLibrary */ = { BFABC42D1E4BE794006036C6 /* SwiftHaskell */ = {
isa = PBXNativeTarget; isa = PBXNativeTarget;
buildConfigurationList = BFABC4631E4C1DD1006036C6 /* Build configuration list for PBXNativeTarget "SwiftAppLibrary" */; buildConfigurationList = BFABC43B1E4BE794006036C6 /* Build configuration list for PBXNativeTarget "SwiftHaskell" */;
buildPhases = ( buildPhases = (
BF2EA5CA1E5030E100651018 /* stack build and link-deps */, BFABC42A1E4BE794006036C6 /* Sources */,
BFABC4561E4C1DD1006036C6 /* Sources */, BFABC42B1E4BE794006036C6 /* Frameworks */,
BFABC4571E4C1DD1006036C6 /* Frameworks */, BFABC42C1E4BE794006036C6 /* Resources */,
BFABC4581E4C1DD1006036C6 /* Headers */, BFABC44B1E4C1BFA006036C6 /* CopyFiles */,
BFABC4591E4C1DD1006036C6 /* Resources */, BFABC4441E4BFEA3006036C6 /* ShellScript */,
BFABC4CE1E4D6344006036C6 /* Link framework to build */,
); );
buildRules = ( buildRules = (
); );
dependencies = ( dependencies = (
); );
name = SwiftAppLibrary;
productName = SwiftAppLibrary;
productReference = BFABC45B1E4C1DD1006036C6 /* SwiftAppLibrary.framework */;
productType = "com.apple.product-type.framework";
};
BFABC4D61E4D781D006036C6 /* SwiftHaskell */ = {
isa = PBXNativeTarget;
buildConfigurationList = BFABC4E51E4D781D006036C6 /* Build configuration list for PBXNativeTarget "SwiftHaskell" */;
buildPhases = (
BFABC4D51E4D781D006036C6 /* Resources */,
BFABC4EF1E4D7948006036C6 /* Embed Frameworks */,
BFABC4EC1E4D78DF006036C6 /* Copy Files */,
);
buildRules = (
);
dependencies = (
BFABC4E91E4D7842006036C6 /* PBXTargetDependency */,
);
name = SwiftHaskell; name = SwiftHaskell;
productName = SwiftHaskell; productName = SwiftHaskell;
productReference = BFABC4D71E4D781D006036C6 /* SwiftHaskell.app */; productReference = BFABC42E1E4BE794006036C6 /* SwiftHaskell.app */;
productType = "com.apple.product-type.application"; productType = "com.apple.product-type.application";
}; };
/* End PBXNativeTarget section */ /* End PBXNativeTarget section */
/* Begin PBXProject section */ /* Begin PBXProject section */
BFABC4521E4C1DD1006036C6 /* Project object */ = { BFABC4261E4BE794006036C6 /* Project object */ = {
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0820; LastUpgradeCheck = 0820;
ORGANIZATIONNAME = nanotech; ORGANIZATIONNAME = nanotech;
TargetAttributes = { TargetAttributes = {
BFABC45A1E4C1DD1006036C6 = { BFABC42D1E4BE794006036C6 = {
CreatedOnToolsVersion = 8.2;
LastSwiftMigration = 0820;
ProvisioningStyle = Automatic;
};
BFABC4D61E4D781D006036C6 = {
CreatedOnToolsVersion = 8.2; CreatedOnToolsVersion = 8.2;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
}; };
}; };
buildConfigurationList = BFABC4551E4C1DD1006036C6 /* Build configuration list for PBXProject "SwiftHaskell" */; buildConfigurationList = BFABC4291E4BE794006036C6 /* Build configuration list for PBXProject "SwiftHaskell" */;
compatibilityVersion = "Xcode 3.2"; compatibilityVersion = "Xcode 3.2";
developmentRegion = English; developmentRegion = English;
hasScannedForEncodings = 0; hasScannedForEncodings = 0;
@@ -195,108 +144,73 @@
en, en,
Base, Base,
); );
mainGroup = BFABC4511E4C1DD1006036C6; mainGroup = BFABC4251E4BE794006036C6;
productRefGroup = BFABC45C1E4C1DD1006036C6 /* Products */; productRefGroup = BFABC42F1E4BE794006036C6 /* Products */;
projectDirPath = ""; projectDirPath = "";
projectRoot = ""; projectRoot = "";
targets = ( targets = (
BFABC4D61E4D781D006036C6 /* SwiftHaskell */, BFABC42D1E4BE794006036C6 /* SwiftHaskell */,
BFABC45A1E4C1DD1006036C6 /* SwiftAppLibrary */,
); );
}; };
/* End PBXProject section */ /* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */ /* Begin PBXResourcesBuildPhase section */
BFABC4591E4C1DD1006036C6 /* Resources */ = { BFABC42C1E4BE794006036C6 /* Resources */ = {
isa = PBXResourcesBuildPhase; isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
BFABC4D21E4D664D006036C6 /* MainMenu.xib in Resources */, BFABC4341E4BE794006036C6 /* Assets.xcassets in Resources */,
); BFABC4371E4BE794006036C6 /* MainMenu.xib in Resources */,
runOnlyForDeploymentPostprocessing = 0;
};
BFABC4D51E4D781D006036C6 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BFABC4E01E4D781D006036C6 /* Assets.xcassets in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
/* End PBXResourcesBuildPhase section */ /* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */
BF2EA5CA1E5030E100651018 /* stack build and link-deps */ = { BFABC4441E4BFEA3006036C6 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
); );
inputPaths = ( inputPaths = (
"$(PROJECT_DIR)/src/Main.hs", "$(PROJECT_DIR)/src/Lib.hs",
"$(PROJECT_DIR)/SwiftHaskellLibrary.cabal", "$(PROJECT_DIR)/SwiftHaskellLibrary.cabal",
"$(PROJECT_DIR)/stack.yaml", "$(PROJECT_DIR)/stack.yaml",
); );
name = "stack build and link-deps";
outputPaths = ( outputPaths = (
"$(PROJECT_DIR)/build/SwiftHaskell", "$(PROJECT_DIR)/build/libswifthaskell.dylib",
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "stack build\nbash link-deps.sh"; shellScript = "stack build";
showEnvVarsInLog = 0;
};
BFABC4CE1E4D6344006036C6 /* Link framework to build */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"$(BUILT_PRODUCTS_DIR)/$(FULL_PRODUCT_NAME)",
);
name = "Link framework to build";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -u\nln -sf \"${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}\" \"${PROJECT_DIR}/build/\"";
showEnvVarsInLog = 0; showEnvVarsInLog = 0;
}; };
/* End PBXShellScriptBuildPhase section */ /* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */
BFABC4561E4C1DD1006036C6 /* Sources */ = { BFABC42A1E4BE794006036C6 /* Sources */ = {
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
BFABC4CD1E4D627E006036C6 /* AppDelegate.swift in Sources */, BFABC4321E4BE794006036C6 /* AppDelegate.swift in Sources */,
BFE4CC421E55553000F232D6 /* SwiftAppLibrary.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
/* End PBXSourcesBuildPhase section */ /* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
BFABC4E91E4D7842006036C6 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = BFABC45A1E4C1DD1006036C6 /* SwiftAppLibrary */;
targetProxy = BFABC4E81E4D7842006036C6 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */ /* Begin PBXVariantGroup section */
BFABC4D01E4D664D006036C6 /* MainMenu.xib */ = { BFABC4351E4BE794006036C6 /* MainMenu.xib */ = {
isa = PBXVariantGroup; isa = PBXVariantGroup;
children = ( children = (
BFABC4D11E4D664D006036C6 /* Base */, BFABC4361E4BE794006036C6 /* Base */,
); );
name = MainMenu.xib; name = MainMenu.xib;
path = Base.lproj;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
/* End PBXVariantGroup section */ /* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */ /* Begin XCBuildConfiguration section */
BFABC4611E4C1DD1006036C6 /* Debug */ = { BFABC4391E4BE794006036C6 /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
@@ -319,7 +233,6 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf; DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;
@@ -343,12 +256,10 @@
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
}; };
name = Debug; name = Debug;
}; };
BFABC4621E4C1DD1006036C6 /* Release */ = { BFABC43A1E4BE794006036C6 /* Release */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
@@ -371,7 +282,6 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO; ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -387,123 +297,69 @@
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
}; };
name = Release; name = Release;
}; };
BFABC4641E4C1DD1006036C6 /* Debug */ = { BFABC43C1E4BE794006036C6 /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = SwiftAppLibrary/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
OTHER_LDFLAGS = (
"-undefined",
dynamic_lookup,
);
PRODUCT_BUNDLE_IDENTIFIER = net.nanotechcorp.SwiftAppLibrary;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "$(PROJECT_DIR)/SwiftHaskell/include";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/build/ghc/include";
};
name = Debug;
};
BFABC4651E4C1DD1006036C6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = SwiftAppLibrary/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
OTHER_LDFLAGS = (
"-undefined",
dynamic_lookup,
);
PRODUCT_BUNDLE_IDENTIFIER = net.nanotechcorp.SwiftAppLibrary;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "$(PROJECT_DIR)/SwiftHaskell/include";
SWIFT_VERSION = 3.0;
USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/build/ghc/include";
};
name = Release;
};
BFABC4E61E4D781D006036C6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = SwiftHaskell/Info.plist; INFOPLIST_FILE = SwiftHaskell/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/build",
);
PRODUCT_BUNDLE_IDENTIFIER = net.nanotechcorp.SwiftHaskell; PRODUCT_BUNDLE_IDENTIFIER = net.nanotechcorp.SwiftHaskell;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SwiftHaskell/SwiftHaskell-Bridging-Header.h";
SWIFT_VERSION = 3.0;
USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/build $(PROJECT_DIR)/build/include";
}; };
name = Debug; name = Debug;
}; };
BFABC4E71E4D781D006036C6 /* Release */ = { BFABC43D1E4BE794006036C6 /* Release */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = SwiftHaskell/Info.plist; INFOPLIST_FILE = SwiftHaskell/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/build",
);
PRODUCT_BUNDLE_IDENTIFIER = net.nanotechcorp.SwiftHaskell; PRODUCT_BUNDLE_IDENTIFIER = net.nanotechcorp.SwiftHaskell;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SwiftHaskell/SwiftHaskell-Bridging-Header.h";
SWIFT_VERSION = 3.0;
USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/build $(PROJECT_DIR)/build/include";
}; };
name = Release; name = Release;
}; };
/* End XCBuildConfiguration section */ /* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */ /* Begin XCConfigurationList section */
BFABC4551E4C1DD1006036C6 /* Build configuration list for PBXProject "SwiftHaskell" */ = { BFABC4291E4BE794006036C6 /* Build configuration list for PBXProject "SwiftHaskell" */ = {
isa = XCConfigurationList; isa = XCConfigurationList;
buildConfigurations = ( buildConfigurations = (
BFABC4611E4C1DD1006036C6 /* Debug */, BFABC4391E4BE794006036C6 /* Debug */,
BFABC4621E4C1DD1006036C6 /* Release */, BFABC43A1E4BE794006036C6 /* Release */,
); );
defaultConfigurationIsVisible = 0; defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release; defaultConfigurationName = Release;
}; };
BFABC4631E4C1DD1006036C6 /* Build configuration list for PBXNativeTarget "SwiftAppLibrary" */ = { BFABC43B1E4BE794006036C6 /* Build configuration list for PBXNativeTarget "SwiftHaskell" */ = {
isa = XCConfigurationList; isa = XCConfigurationList;
buildConfigurations = ( buildConfigurations = (
BFABC4641E4C1DD1006036C6 /* Debug */, BFABC43C1E4BE794006036C6 /* Debug */,
BFABC4651E4C1DD1006036C6 /* Release */, BFABC43D1E4BE794006036C6 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
BFABC4E51E4D781D006036C6 /* Build configuration list for PBXNativeTarget "SwiftHaskell" */ = {
isa = XCConfigurationList;
buildConfigurations = (
BFABC4E61E4D781D006036C6 /* Debug */,
BFABC4E71E4D781D006036C6 /* Release */,
); );
defaultConfigurationIsVisible = 0; defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release; defaultConfigurationName = Release;
}; };
/* End XCConfigurationList section */ /* End XCConfigurationList section */
}; };
rootObject = BFABC4521E4C1DD1006036C6 /* Project object */; rootObject = BFABC4261E4BE794006036C6 /* Project object */;
} }
+28
View File
@@ -0,0 +1,28 @@
//
// AppDelegate.swift
// SwiftHaskell
//
// Created by NanoTech on 2017-02-08.
// Copyright © 2017 nanotech. All rights reserved.
//
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var label: NSTextField!
func applicationDidFinishLaunching(_ aNotification: Notification) {
var argc = CommandLine.argc
var argv = Optional.some(CommandLine.unsafeArgv)
hs_init(&argc, &argv)
label.stringValue = "\(square(5))"
}
func applicationWillTerminate(_ aNotification: Notification) {
hs_exit()
}
}
@@ -13,7 +13,7 @@
</customObject> </customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/> <customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="SwiftAppLibrary" customModuleProvider="target"> <customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="SwiftHaskell" customModuleProvider="target">
<connections> <connections>
<outlet property="label" destination="drV-ep-pYM" id="xdv-Y5-tR0"/> <outlet property="label" destination="drV-ep-pYM" id="xdv-Y5-tR0"/>
<outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/> <outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
@@ -690,8 +690,9 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="360"/> <rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="drV-ep-pYM"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="drV-ep-pYM">
<rect key="frame" x="18" y="323" width="444" height="17"/> <rect key="frame" x="18" y="323" width="37" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="Wba-z2-8m1"> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="Wba-z2-8m1">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -699,11 +700,6 @@
</textFieldCell> </textFieldCell>
</textField> </textField>
</subviews> </subviews>
<constraints>
<constraint firstItem="drV-ep-pYM" firstAttribute="top" secondItem="EiT-Mj-1SZ" secondAttribute="top" constant="20" id="5eo-Sd-hEH"/>
<constraint firstItem="drV-ep-pYM" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" constant="20" id="OlT-mM-yos"/>
<constraint firstAttribute="trailing" secondItem="drV-ep-pYM" secondAttribute="trailing" constant="20" id="kzO-Mq-rea"/>
</constraints>
</view> </view>
</window> </window>
</objects> </objects>
@@ -0,0 +1,14 @@
//
// SwiftHaskell-Bridging-Header.h
// SwiftHaskell
//
// Created by NanoTech on 2017-02-08.
// Copyright © 2017 nanotech. All rights reserved.
//
#ifndef SwiftHaskell_Bridging_Header_h
#define SwiftHaskell_Bridging_Header_h
#include "Lib_stub.h"
#endif /* SwiftHaskell_Bridging_Header_h */
-16
View File
@@ -1,16 +0,0 @@
#include "HsFFI.h"
#ifdef __cplusplus
extern "C" {
#endif
extern HsInt32 square(HsInt32 a1);
extern HsWord64 countBytes(HsWord8 a1, HsPtr a2, HsWord64 a3);
extern HsPtr getSequence(HsPtr a1);
extern void callbackExample(HsFunPtr a1);
extern void contextCallbackExample(HsPtr a1, HsFunPtr a2, HsFunPtr a3);
extern HsFunPtr makeMultiplier(HsInt32 a1);
extern void freeMultiplier(HsFunPtr a1);
extern HsInt32 Main_d9Dt(StgStablePtr the_stableptr, HsInt32 a1);
#ifdef __cplusplus
}
#endif
-4
View File
@@ -1,4 +0,0 @@
module SwiftHaskell {
header "Main_stub.h"
export *
}
+7 -11
View File
@@ -13,17 +13,13 @@ build-type: Simple
extra-source-files: extra-source-files:
cabal-version: >=1.10 cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: Lib
ghc-options: -threaded -dynamic -shared -fPIC -o build/libswifthaskell.dylib
build-depends: base >= 4.7 && < 5
default-language: Haskell2010
source-repository head source-repository head
type: git type: git
location: https://github.com/nanotech/swift-haskell-tutorial location: https://github.com/nanotech/swift-haskell-tutorial
executable SwiftHaskell
default-language: Haskell2010
hs-source-dirs: src
main-is: Main.hs
ghc-options: -threaded -framework-path build
ld-options: -rpath @executable_path/../Frameworks
frameworks: SwiftAppLibrary
build-depends: base >= 4.7 && < 5
, bytestring >= 0.10 && < 0.11
, text >= 1.2 && < 1.3
-33
View File
@@ -1,33 +0,0 @@
#!/usr/bin/env bash
set -eu
EXECUTABLE_NAME=SwiftHaskell
DIST_DIR="$(stack path --dist-dir)"
GHC_VERSION="$(stack exec -- ghc --numeric-version)"
GHC_LIB_DIR="$(stack path --compiler-bin)/../lib/ghc-$GHC_VERSION"
STUB_BUILD_DIR="${DIST_DIR}/build/${EXECUTABLE_NAME}/${EXECUTABLE_NAME}-tmp"
STUB_MODULE_DIR="${EXECUTABLE_NAME}/include"
STUB_MODULE_MAP="${STUB_MODULE_DIR}/module.modulemap"
# Create a module map from the generated Haskell
# FFI export headers for importing into Swift.
mkdir -p "${STUB_MODULE_DIR}"
NL="
"
module_map="module ${EXECUTABLE_NAME} {${NL}"
for h in $(find "${STUB_BUILD_DIR}" -name '*.h'); do
h_filename="${h/$STUB_BUILD_DIR\//}"
cp "$h" "${STUB_MODULE_DIR}/"
module_map="${module_map} header \"${h_filename}\"${NL}"
done
module_map="${module_map} export *${NL}"
module_map="${module_map}}"
echo "${module_map}" > "${STUB_MODULE_MAP}"
# Symlink to the current GHC's header directory from a more
# convenient place for Xcode to find.
mkdir -p build/ghc
ln -sf "${GHC_LIB_DIR}/include" build/ghc/
# Symlink to the Haskell executable for Xcode.
ln -sf "../${DIST_DIR}/build/${EXECUTABLE_NAME}/${EXECUTABLE_NAME}" build/
-106
View File
@@ -1,106 +0,0 @@
module Main where
import Control.Concurrent (forkIO)
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Unsafe as BU
import qualified Data.Text as T
import Data.Word (Word8)
import Foreign.C (CChar (CChar), CInt (CInt), CSize (CSize))
import Foreign.ForeignPtr (newForeignPtr, withForeignPtr)
import Foreign.Marshal.Array (copyArray, mallocArray)
import Foreign.Ptr (FunPtr, Ptr, freeHaskellFunPtr)
import Foreign.Storable (poke)
foreign export ccall square :: CInt -> CInt
square :: CInt -> CInt
square x = x * x
foreign import ccall "runNSApplication" runNSApplication :: IO ()
main :: IO ()
main = do
putStrLn "hello world"
runNSApplication
-- Examples
-- Swift to Haskell ByteString Example
foreign export ccall countBytes :: Word8 -> Ptr CChar -> CSize -> IO CSize
countBytes :: Word8 -> Ptr CChar -> CSize -> IO CSize
countBytes needle haystack haystackLen = do
s <- B.packCStringLen (haystack, fromIntegral haystackLen)
pure (B.foldl (\count b -> count + if b == needle then 1 else 0) 0 s)
-- Haskell to Swift ByteString Example
mallocCopyByteString :: ByteString -> IO (Ptr CChar, Int)
mallocCopyByteString s =
BU.unsafeUseAsCStringLen s $ \(p, n) -> do
a <- mallocArray n
copyArray a p n
pure (a, n)
foreign export ccall getSequence :: Ptr CSize -> IO (Ptr CChar)
getSequence :: Ptr CSize -> IO (Ptr CChar)
getSequence sizePtr = do
(p, n) <- mallocCopyByteString (B.pack [1..10])
poke sizePtr (fromIntegral n)
pure p
-- Swift to Haskell Callback Example
foreign export ccall callbackExample :: FunPtr (CInt -> IO ()) -> IO ()
foreign import ccall "dynamic" unwrapCallback :: FunPtr (CInt -> IO ()) -> (CInt -> IO ())
callbackExample :: FunPtr (CInt -> IO ()) -> IO ()
callbackExample f = (unwrapCallback f) 3
-- Swift to Haskell Callback with Context Example
foreign export ccall contextCallbackExample
:: Ptr ()
-> FunPtr (Ptr () -> IO ())
-> FunPtr (Ptr () -> CInt -> IO ())
-> IO ()
foreign import ccall "dynamic" unwrapContextCallback
:: FunPtr (Ptr () -> CInt -> IO ())
-> (Ptr () -> CInt -> IO ())
contextCallbackExample
:: Ptr () -- ^ Context pointer
-> FunPtr (Ptr () -> IO ()) -- ^ Context release function
-> FunPtr (Ptr () -> CInt -> IO ()) -- ^ Callback function
-> IO ()
contextCallbackExample ctxp releaseCtx callbackPtr = do
ctxfp <- newForeignPtr releaseCtx ctxp
let callback :: CInt -> IO ()
callback result = withForeignPtr ctxfp $ \ctxp' ->
(unwrapContextCallback callbackPtr) ctxp' result
_ <- forkIO $ do
let result = 3 -- perform your complex computation here
callback result
pure ()
-- Swift to Haskell Function Example
foreign export ccall makeMultiplier :: CInt -> IO (FunPtr (CInt -> CInt))
foreign import ccall "wrapper" wrapMultiplier
:: (CInt -> CInt)
-> IO (FunPtr (CInt -> CInt))
makeMultiplier :: CInt -> IO (FunPtr (CInt -> CInt))
makeMultiplier x = wrapMultiplier (x *)
foreign export ccall freeMultiplier :: FunPtr (CInt -> CInt) -> IO ()
freeMultiplier :: FunPtr (CInt -> CInt) -> IO ()
freeMultiplier = freeHaskellFunPtr
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
set -eux
DIST_DIR="$(stack path --dist-dir)"
GHC_VERSION="$(stack exec -- ghc --numeric-version)"
GHC_LIB_DIR="$(stack path --compiler-bin)/../lib/ghc-$GHC_VERSION"
ln -sf ../"$DIST_DIR"/build/Lib_stub.h build/
ln -sf "$GHC_LIB_DIR"/include build/
ln -sf "$GHC_LIB_DIR"/rts/libHSrts_thr-ghc"$GHC_VERSION".dylib build/
ln -sf "$GHC_LIB_DIR"/rts/libffi.dylib build/
Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB