diff options
9 files changed, 494 insertions, 0 deletions
diff --git a/examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj b/examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj new file mode 100644 index 000000000..9133b6917 --- /dev/null +++ b/examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj @@ -0,0 +1,329 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + D531422A15BC8611005EFF20 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D531422915BC8611005EFF20 /* UIKit.framework */; }; + D531422C15BC8611005EFF20 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D531422B15BC8611005EFF20 /* Foundation.framework */; }; + D531422E15BC8611005EFF20 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D531422D15BC8611005EFF20 /* CoreGraphics.framework */; }; + D531424D15BC87B6005EFF20 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D531424A15BC87B6005EFF20 /* AppDelegate.m */; }; + D531424E15BC87B6005EFF20 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D531424B15BC87B6005EFF20 /* main.m */; }; + D531427215BC94B1005EFF20 /* backend.m in Sources */ = {isa = PBXBuildFile; fileRef = D531426F15BC94B1005EFF20 /* backend.m */; }; + D531427415BC94B1005EFF20 /* system.m in Sources */ = {isa = PBXBuildFile; fileRef = D531427115BC94B1005EFF20 /* system.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + D531422515BC8611005EFF20 /* cross-calculator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "cross-calculator.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + D531422915BC8611005EFF20 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + D531422B15BC8611005EFF20 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + D531422D15BC8611005EFF20 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + D531424715BC87A5005EFF20 /* cross-calculator-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "cross-calculator-Info.plist"; path = "resources/plist/cross-calculator-Info.plist"; sourceTree = "<group>"; }; + D531424915BC87B6005EFF20 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = src/AppDelegate.h; sourceTree = "<group>"; }; + D531424A15BC87B6005EFF20 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = src/AppDelegate.m; sourceTree = "<group>"; }; + D531424B15BC87B6005EFF20 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = src/main.m; sourceTree = "<group>"; }; + D531424C15BC87B6005EFF20 /* cross-calculator-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "cross-calculator-Prefix.pch"; path = "src/cross-calculator-Prefix.pch"; sourceTree = "<group>"; }; + D531426715BC91EF005EFF20 /* tags.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; name = tags.sh; path = scripts/tags.sh; sourceTree = "<group>"; }; + D531426815BC91EF005EFF20 /* xcode_prebuild.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; name = xcode_prebuild.sh; path = scripts/xcode_prebuild.sh; sourceTree = "<group>"; }; + D531426F15BC94B1005EFF20 /* backend.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = backend.m; path = build/nimcache/backend.m; sourceTree = "<group>"; }; + D531427115BC94B1005EFF20 /* system.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = system.m; path = build/nimcache/system.m; sourceTree = "<group>"; }; + D592E19015C7120F005258EA /* backend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = backend.h; path = build/nimcache/backend.h; sourceTree = "<group>"; }; + D592E19115C71415005258EA /* nimbase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = nimbase.h; path = build/nimcache/nimbase.h; sourceTree = "<group>"; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + D531422215BC8610005EFF20 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + D531422A15BC8611005EFF20 /* UIKit.framework in Frameworks */, + D531422C15BC8611005EFF20 /* Foundation.framework in Frameworks */, + D531422E15BC8611005EFF20 /* CoreGraphics.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + D531421A15BC8610005EFF20 = { + isa = PBXGroup; + children = ( + D531426A15BC93D5005EFF20 /* build */, + D531424515BC874E005EFF20 /* resources */, + D531426615BC91E1005EFF20 /* scripts */, + D531424815BC87AD005EFF20 /* src */, + D531422815BC8611005EFF20 /* Frameworks */, + D531422615BC8611005EFF20 /* Products */, + ); + sourceTree = "<group>"; + }; + D531422615BC8611005EFF20 /* Products */ = { + isa = PBXGroup; + children = ( + D531422515BC8611005EFF20 /* cross-calculator.app */, + ); + name = Products; + sourceTree = "<group>"; + }; + D531422815BC8611005EFF20 /* Frameworks */ = { + isa = PBXGroup; + children = ( + D531422915BC8611005EFF20 /* UIKit.framework */, + D531422B15BC8611005EFF20 /* Foundation.framework */, + D531422D15BC8611005EFF20 /* CoreGraphics.framework */, + ); + name = Frameworks; + sourceTree = "<group>"; + }; + D531424515BC874E005EFF20 /* resources */ = { + isa = PBXGroup; + children = ( + D531424615BC8756005EFF20 /* plist */, + ); + name = resources; + sourceTree = "<group>"; + }; + D531424615BC8756005EFF20 /* plist */ = { + isa = PBXGroup; + children = ( + D531424715BC87A5005EFF20 /* cross-calculator-Info.plist */, + ); + name = plist; + sourceTree = "<group>"; + }; + D531424815BC87AD005EFF20 /* src */ = { + isa = PBXGroup; + children = ( + D531424915BC87B6005EFF20 /* AppDelegate.h */, + D531424A15BC87B6005EFF20 /* AppDelegate.m */, + D531424B15BC87B6005EFF20 /* main.m */, + D531424C15BC87B6005EFF20 /* cross-calculator-Prefix.pch */, + ); + name = src; + sourceTree = "<group>"; + }; + D531426615BC91E1005EFF20 /* scripts */ = { + isa = PBXGroup; + children = ( + D531426715BC91EF005EFF20 /* tags.sh */, + D531426815BC91EF005EFF20 /* xcode_prebuild.sh */, + ); + name = scripts; + sourceTree = "<group>"; + }; + D531426A15BC93D5005EFF20 /* build */ = { + isa = PBXGroup; + children = ( + D531426E15BC94A6005EFF20 /* nimrod */, + ); + name = build; + sourceTree = "<group>"; + }; + D531426E15BC94A6005EFF20 /* nimrod */ = { + isa = PBXGroup; + children = ( + D592E19015C7120F005258EA /* backend.h */, + D531426F15BC94B1005EFF20 /* backend.m */, + D592E19115C71415005258EA /* nimbase.h */, + D531427115BC94B1005EFF20 /* system.m */, + ); + name = nimrod; + sourceTree = "<group>"; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + D531422415BC8610005EFF20 /* cross-calculator */ = { + isa = PBXNativeTarget; + buildConfigurationList = D531423D15BC8611005EFF20 /* Build configuration list for PBXNativeTarget "cross-calculator" */; + buildPhases = ( + D531426915BC926C005EFF20 /* ShellScript */, + D531422115BC8610005EFF20 /* Sources */, + D531422215BC8610005EFF20 /* Frameworks */, + D531422315BC8610005EFF20 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "cross-calculator"; + productName = "cross-calculator"; + productReference = D531422515BC8611005EFF20 /* cross-calculator.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + D531421C15BC8610005EFF20 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0420; + ORGANIZATIONNAME = "Electric Hands Software"; + }; + buildConfigurationList = D531421F15BC8610005EFF20 /* Build configuration list for PBXProject "cross-calculator" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = D531421A15BC8610005EFF20; + productRefGroup = D531422615BC8611005EFF20 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + D531422415BC8610005EFF20 /* cross-calculator */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + D531422315BC8610005EFF20 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + D531426915BC926C005EFF20 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = scripts/xcode_prebuild.sh; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + D531422115BC8610005EFF20 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + D531424D15BC87B6005EFF20 /* AppDelegate.m in Sources */, + D531424E15BC87B6005EFF20 /* main.m in Sources */, + D531427215BC94B1005EFF20 /* backend.m in Sources */, + D531427415BC94B1005EFF20 /* system.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + D531423B15BC8611005EFF20 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = ( + armv7, + armv6, + ); + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_VERSION = ""; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 3.0; + OTHER_LDFLAGS = ( + "-weak_library", + /usr/lib/libSystem.B.dylib, + ); + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + D531423C15BC8611005EFF20 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = ( + armv7, + armv6, + ); + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_VERSION = ""; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 3.0; + OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; + OTHER_LDFLAGS = ( + "-weak_library", + /usr/lib/libSystem.B.dylib, + ); + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + D531423E15BC8611005EFF20 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "src/cross-calculator-Prefix.pch"; + INFOPLIST_FILE = "resources/plist/cross-calculator-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Debug; + }; + D531423F15BC8611005EFF20 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "src/cross-calculator-Prefix.pch"; + INFOPLIST_FILE = "resources/plist/cross-calculator-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + D531421F15BC8610005EFF20 /* Build configuration list for PBXProject "cross-calculator" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D531423B15BC8611005EFF20 /* Debug */, + D531423C15BC8611005EFF20 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + D531423D15BC8611005EFF20 /* Build configuration list for PBXNativeTarget "cross-calculator" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D531423E15BC8611005EFF20 /* Debug */, + D531423F15BC8611005EFF20 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = D531421C15BC8610005EFF20 /* Project object */; +} diff --git a/examples/cross_calculator/ios/readme.txt b/examples/cross_calculator/ios/readme.txt new file mode 100644 index 000000000..e75db72bf --- /dev/null +++ b/examples/cross_calculator/ios/readme.txt @@ -0,0 +1,17 @@ +In this directory you will find the iOS platform cross-calculator sample. + +The iOS version of the code builds a view controller in charge of displaying +the interface to the user. The nimrod backend code is compiled into C code and +put into build/nimrod as a pre-build phase of the project. + +When the calculate button is used the view controller calls the nimrod code to +delegate the logic of the operation and puts the result in a label for display. +All interface error checks are implemented in the view controller. + +You can use this as a starting point for your project or look at the history of +the github project at https://github.com/gradha/nimrod-on-ios. That repository +documents the individual integration steps you would take for any iOS project. + +This version of the iOS project is known to work with Xcode 4.2 and Xcode +4.4.1. The final binary can be deployed on iOS 3.x to 5.x supporting all iOS +platforms and versions available at the moment. diff --git a/examples/cross_calculator/ios/resources/plist/cross-calculator-Info.plist b/examples/cross_calculator/ios/resources/plist/cross-calculator-Info.plist new file mode 100644 index 000000000..758f20e38 --- /dev/null +++ b/examples/cross_calculator/ios/resources/plist/cross-calculator-Info.plist @@ -0,0 +1,30 @@ +<?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>CFBundleDisplayName</key> + <string>${PRODUCT_NAME}</string> + <key>CFBundleExecutable</key> + <string>${EXECUTABLE_NAME}</string> + <key>CFBundleIconFiles</key> + <array/> + <key>CFBundleIdentifier</key> + <string>com.github.nimrod.${PRODUCT_NAME:rfc1034identifier}</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>${PRODUCT_NAME}</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleVersion</key> + <string>1.0</string> + <key>UIApplicationExitsOnSuspend</key> + <true/> +</dict> +</plist> diff --git a/examples/cross_calculator/ios/scripts/tags.sh b/examples/cross_calculator/ios/scripts/tags.sh new file mode 100755 index 000000000..111e7a1c0 --- /dev/null +++ b/examples/cross_calculator/ios/scripts/tags.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +if [ ! -d src ] +then + cd .. +fi + +if [ -d src ] +then + ~/bin/objctags -R \ + build/nimcache \ + src +fi diff --git a/examples/cross_calculator/ios/scripts/xcode_prebuild.sh b/examples/cross_calculator/ios/scripts/xcode_prebuild.sh new file mode 100755 index 000000000..7626ba0b9 --- /dev/null +++ b/examples/cross_calculator/ios/scripts/xcode_prebuild.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +# Set this to the full path of your nimrod compiler +# since Xcode doesn't inherit your user environment. +PATH_TO_NIMROD=~/project/nimrod/bin/nimrod +# Set this to the location of the nimbase.h file so +# the script can update it if it changes. +PATH_TO_NIMBASE=~/project/nimrod/lib/nimbase.h + +# Force errors to fail script. +set -e + +# If we are running from inside the scripts subdir, get out. +if [ ! -d src ] +then + cd .. +fi + +DEST_NIMBASE=build/nimcache/nimbase.h + +# Ok, are we out now? +if [ -d src ] +then + # You may want to use a wildcard here to compile all nimrod files. + $PATH_TO_NIMROD objc --noMain --app:lib \ + --nimcache:build/nimcache --compileOnly \ + --header --cpu:i386 ../nimrod_backend/backend.nim + if [ "${PATH_TO_NIMBASE}" -nt "${DEST_NIMBASE}" ] + then + echo "Updating nimbase.h" + cp "${PATH_TO_NIMBASE}" "${DEST_NIMBASE}" + fi +else + echo "Uh oh, src directory not found?" + exit 1 +fi diff --git a/examples/cross_calculator/ios/src/AppDelegate.h b/examples/cross_calculator/ios/src/AppDelegate.h new file mode 100644 index 000000000..a5a8b3852 --- /dev/null +++ b/examples/cross_calculator/ios/src/AppDelegate.h @@ -0,0 +1,7 @@ +#import <UIKit/UIKit.h> + +@interface AppDelegate : UIResponder <UIApplicationDelegate> + +@property (strong, nonatomic) UIWindow *window; + +@end diff --git a/examples/cross_calculator/ios/src/AppDelegate.m b/examples/cross_calculator/ios/src/AppDelegate.m new file mode 100644 index 000000000..d39a08b65 --- /dev/null +++ b/examples/cross_calculator/ios/src/AppDelegate.m @@ -0,0 +1,39 @@ +#import "AppDelegate.h" + +#import "backend.h" + +@implementation AppDelegate + +@synthesize window = _window; + +- (void)dealloc +{ + [_window release]; + [super dealloc]; +} + +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] + bounds]] autorelease]; + // Override point for customization after application launch. + self.window.backgroundColor = [UIColor whiteColor]; + [self.window makeKeyAndVisible]; + + // Call nimrod code and store the result. + const int a = 3; + const int b = 12; + const int c = myAdd(a, b); + + // Add a label to show the results of the computation made by nimrod. + UILabel *label = [[UILabel alloc] initWithFrame:self.window.bounds]; + label.textAlignment = UITextAlignmentCenter; + label.text = [NSString stringWithFormat:@"myAdd(%d, %d) = %d", a, b, c]; + [self.window addSubview:label]; + [label release]; + + return YES; +} + +@end diff --git a/examples/cross_calculator/ios/src/cross-calculator-Prefix.pch b/examples/cross_calculator/ios/src/cross-calculator-Prefix.pch new file mode 100644 index 000000000..2f331ed43 --- /dev/null +++ b/examples/cross_calculator/ios/src/cross-calculator-Prefix.pch @@ -0,0 +1,10 @@ +#import <Availability.h> + +#ifndef __IPHONE_3_0 +#warning "This project uses features only available in iOS SDK 3.0 and later." +#endif + +#ifdef __OBJC__ + #import <UIKit/UIKit.h> + #import <Foundation/Foundation.h> +#endif diff --git a/examples/cross_calculator/ios/src/main.m b/examples/cross_calculator/ios/src/main.m new file mode 100644 index 000000000..7866684fe --- /dev/null +++ b/examples/cross_calculator/ios/src/main.m @@ -0,0 +1,13 @@ +#import <UIKit/UIKit.h> + +#import "AppDelegate.h" +#import "backend.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + NimMain(); + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); + } +} |