Skip to content
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 5ecee24c514d80c1c113df017cde4d6431222add @logancollins committed May 12, 2012
Showing with 3,822 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +586 −0 Mocha.xcodeproj/project.pbxproj
  3. +24 −0 Mocha/BridgeSupport/MOBridgeSupportController.h
  4. +94 −0 Mocha/BridgeSupport/MOBridgeSupportController.m
  5. +29 −0 Mocha/BridgeSupport/MOBridgeSupportLibrary.h
  6. +85 −0 Mocha/BridgeSupport/MOBridgeSupportLibrary.m
  7. +19 −0 Mocha/BridgeSupport/MOBridgeSupportParser.h
  8. +288 −0 Mocha/BridgeSupport/MOBridgeSupportParser.m
  9. +219 −0 Mocha/BridgeSupport/MOBridgeSupportSymbol.h
  10. +335 −0 Mocha/BridgeSupport/MOBridgeSupportSymbol.m
  11. +18 −0 Mocha/Exceptions/MOException.h
  12. +37 −0 Mocha/Exceptions/MOException.m
  13. +21 −0 Mocha/Exceptions/MOException_Private.h
  14. +30 −0 Mocha/Mocha-Info.plist
  15. +7 −0 Mocha/Mocha-Prefix.pch
  16. +13 −0 Mocha/Mocha.h
  17. +10 −0 Mocha/Mocha.m
  18. +12 −0 Mocha/MochaDefines.h
  19. +70 −0 Mocha/MochaRuntime.h
  20. +1,130 −0 Mocha/MochaRuntime.m
  21. +58 −0 Mocha/MochaRuntime_Private.h
  22. +18 −0 Mocha/Objects/MOBox.h
  23. +17 −0 Mocha/Objects/MOBox.m
  24. +21 −0 Mocha/Objects/MOBridgeSupportObject.h
  25. +27 −0 Mocha/Objects/MOBridgeSupportObject.m
  26. +19 −0 Mocha/Objects/MOFunction.h
  27. +25 −0 Mocha/Objects/MOFunction.m
  28. +17 −0 Mocha/Objects/MOFunction_Private.h
  29. +14 −0 Mocha/Objects/MOObject.h
  30. +14 −0 Mocha/Objects/MOObject.m
  31. +23 −0 Mocha/Objects/NSArray+MochaAdditions.h
  32. +32 −0 Mocha/Objects/NSArray+MochaAdditions.m
  33. +23 −0 Mocha/Objects/NSDictionary+MochaAdditions.h
  34. +27 −0 Mocha/Objects/NSDictionary+MochaAdditions.m
  35. +20 −0 Mocha/Utilities/MOUtilities.h
  36. +287 −0 Mocha/Utilities/MOUtilities.m
  37. +2 −0 Mocha/en.lproj/InfoPlist.strings
  38. 0 README.mdown
  39. +17 −0 moc/MOCInterpreter.h
  40. +84 −0 moc/MOCInterpreter.m
  41. +26 −0 moc/main.m
  42. +7 −0 moc/moc-Prefix.pch
17 .gitignore
@@ -0,0 +1,17 @@
+# Xcode
+build
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+*.xcodeproj/project.xcworkspace
+xcuserdata
+profile
+*.moved-aside
+
+# OS files
+.DS_Store
586 Mocha.xcodeproj/project.pbxproj
@@ -0,0 +1,586 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 02112323155D7BD000415471 /* MOUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 02112321155D7BD000415471 /* MOUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 02112324155D7BD000415471 /* MOUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 02112322155D7BD000415471 /* MOUtilities.m */; };
+ 02112327155D973100415471 /* MOBridgeSupportController.h in Headers */ = {isa = PBXBuildFile; fileRef = 02112325155D973100415471 /* MOBridgeSupportController.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 02112328155D973100415471 /* MOBridgeSupportController.m in Sources */ = {isa = PBXBuildFile; fileRef = 02112326155D973100415471 /* MOBridgeSupportController.m */; };
+ 0211232C155D99F600415471 /* MOBridgeSupportSymbol.h in Headers */ = {isa = PBXBuildFile; fileRef = 0211232A155D99F600415471 /* MOBridgeSupportSymbol.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 0211232D155D99F600415471 /* MOBridgeSupportSymbol.m in Sources */ = {isa = PBXBuildFile; fileRef = 0211232B155D99F600415471 /* MOBridgeSupportSymbol.m */; };
+ 0211233E155DB8F800415471 /* MOBridgeSupportLibrary.h in Headers */ = {isa = PBXBuildFile; fileRef = 0211233C155DB8F800415471 /* MOBridgeSupportLibrary.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 0211233F155DB8F800415471 /* MOBridgeSupportLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = 0211233D155DB8F800415471 /* MOBridgeSupportLibrary.m */; };
+ 02112342155DB9A100415471 /* MOBridgeSupportParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 02112340155DB9A100415471 /* MOBridgeSupportParser.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 02112343155DB9A100415471 /* MOBridgeSupportParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 02112341155DB9A100415471 /* MOBridgeSupportParser.m */; };
+ EAA45E11155CE44B00F93E40 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = EAA45E0F155CE44B00F93E40 /* InfoPlist.strings */; };
+ EAA45E15155CE44B00F93E40 /* Mocha.m in Sources */ = {isa = PBXBuildFile; fileRef = EAA45E14155CE44B00F93E40 /* Mocha.m */; };
+ EAA45E1C155CE46000F93E40 /* MochaDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = EAA45E1B155CE46000F93E40 /* MochaDefines.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ EAA45E1D155CE46400F93E40 /* Mocha.h in Headers */ = {isa = PBXBuildFile; fileRef = EAA45E13155CE44B00F93E40 /* Mocha.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ EAA45E1F155CE4CB00F93E40 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA45E1E155CE4CB00F93E40 /* JavaScriptCore.framework */; };
+ EAA45E20155CE4D100F93E40 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA45E0B155CE44B00F93E40 /* Foundation.framework */; };
+ EAA45E24155CE57600F93E40 /* MochaRuntime.h in Headers */ = {isa = PBXBuildFile; fileRef = EAA45E22155CE57600F93E40 /* MochaRuntime.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ EAA45E25155CE57600F93E40 /* MochaRuntime.m in Sources */ = {isa = PBXBuildFile; fileRef = EAA45E23155CE57600F93E40 /* MochaRuntime.m */; };
+ EAA45E27155CE66600F93E40 /* MochaRuntime_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = EAA45E26155CE66600F93E40 /* MochaRuntime_Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ EAA45E30155CF26C00F93E40 /* MOException.h in Headers */ = {isa = PBXBuildFile; fileRef = EAA45E2E155CF26B00F93E40 /* MOException.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ EAA45E31155CF26C00F93E40 /* MOException.m in Sources */ = {isa = PBXBuildFile; fileRef = EAA45E2F155CF26C00F93E40 /* MOException.m */; };
+ EAA45E33155CF2FD00F93E40 /* MOException_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = EAA45E32155CF2FD00F93E40 /* MOException_Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ EAA45E3A155D09A700F93E40 /* MOObject.h in Headers */ = {isa = PBXBuildFile; fileRef = EAA45E38155D09A700F93E40 /* MOObject.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ EAA45E3B155D09A700F93E40 /* MOObject.m in Sources */ = {isa = PBXBuildFile; fileRef = EAA45E39155D09A700F93E40 /* MOObject.m */; };
+ EAA45E73155EE5AF00F93E40 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA45E0B155CE44B00F93E40 /* Foundation.framework */; };
+ EAA45E76155EE5AF00F93E40 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = EAA45E75155EE5AF00F93E40 /* main.m */; };
+ EAA45E7E155EE63700F93E40 /* Mocha.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA45E03155CE44B00F93E40 /* Mocha.framework */; };
+ EAA45E81155EE68000F93E40 /* MOCInterpreter.m in Sources */ = {isa = PBXBuildFile; fileRef = EAA45E80155EE68000F93E40 /* MOCInterpreter.m */; };
+ EAA45E88155EE97200F93E40 /* MOFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = EAA45E86155EE97200F93E40 /* MOFunction.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ EAA45E89155EE97200F93E40 /* MOFunction.m in Sources */ = {isa = PBXBuildFile; fileRef = EAA45E87155EE97200F93E40 /* MOFunction.m */; };
+ EAA45E8B155EEA3000F93E40 /* MOFunction_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = EAA45E8A155EEA2F00F93E40 /* MOFunction_Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ EAA45E90155EEB1900F93E40 /* MOBridgeSupportObject.h in Headers */ = {isa = PBXBuildFile; fileRef = EAA45E8E155EEB1900F93E40 /* MOBridgeSupportObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ EAA45E91155EEB1900F93E40 /* MOBridgeSupportObject.m in Sources */ = {isa = PBXBuildFile; fileRef = EAA45E8F155EEB1900F93E40 /* MOBridgeSupportObject.m */; };
+ EAA45E94155EEB9500F93E40 /* MOBox.h in Headers */ = {isa = PBXBuildFile; fileRef = EAA45E92155EEB9400F93E40 /* MOBox.h */; };
+ EAA45E95155EEB9500F93E40 /* MOBox.m in Sources */ = {isa = PBXBuildFile; fileRef = EAA45E93155EEB9400F93E40 /* MOBox.m */; };
+ EAA45EAB155F0B4600F93E40 /* libreadline.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA45EAA155F0B4600F93E40 /* libreadline.dylib */; };
+ EAA45EAD155F0CC800F93E40 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA45E1E155CE4CB00F93E40 /* JavaScriptCore.framework */; };
+ EAC8BFC4155F3E01003653BA /* NSArray+MochaAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = EAC8BFC2155F3E01003653BA /* NSArray+MochaAdditions.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ EAC8BFC5155F3E01003653BA /* NSArray+MochaAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = EAC8BFC3155F3E01003653BA /* NSArray+MochaAdditions.m */; };
+ EAC8BFC9155F3ECD003653BA /* NSDictionary+MochaAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = EAC8BFC7155F3ECD003653BA /* NSDictionary+MochaAdditions.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ EAC8BFCA155F3ECD003653BA /* NSDictionary+MochaAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = EAC8BFC8155F3ECD003653BA /* NSDictionary+MochaAdditions.m */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXContainerItemProxy section */
+ EAA45EA8155F0B3200F93E40 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = EAA45DF9155CE44B00F93E40 /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = EAA45E02155CE44B00F93E40;
+ remoteInfo = Mocha;
+ };
+/* End PBXContainerItemProxy section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+ EAA45E6F155EE5AF00F93E40 /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = /usr/share/man/man1/;
+ dstSubfolderSpec = 0;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 1;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+ 02112321155D7BD000415471 /* MOUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOUtilities.h; sourceTree = "<group>"; };
+ 02112322155D7BD000415471 /* MOUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MOUtilities.m; sourceTree = "<group>"; usesTabs = 0; };
+ 02112325155D973100415471 /* MOBridgeSupportController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOBridgeSupportController.h; sourceTree = "<group>"; };
+ 02112326155D973100415471 /* MOBridgeSupportController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MOBridgeSupportController.m; sourceTree = "<group>"; };
+ 0211232A155D99F600415471 /* MOBridgeSupportSymbol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOBridgeSupportSymbol.h; sourceTree = "<group>"; };
+ 0211232B155D99F600415471 /* MOBridgeSupportSymbol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MOBridgeSupportSymbol.m; sourceTree = "<group>"; };
+ 0211233C155DB8F800415471 /* MOBridgeSupportLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOBridgeSupportLibrary.h; sourceTree = "<group>"; };
+ 0211233D155DB8F800415471 /* MOBridgeSupportLibrary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MOBridgeSupportLibrary.m; sourceTree = "<group>"; };
+ 02112340155DB9A100415471 /* MOBridgeSupportParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOBridgeSupportParser.h; sourceTree = "<group>"; };
+ 02112341155DB9A100415471 /* MOBridgeSupportParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MOBridgeSupportParser.m; sourceTree = "<group>"; };
+ EAA45E03155CE44B00F93E40 /* Mocha.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Mocha.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ EAA45E0B155CE44B00F93E40 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ EAA45E0E155CE44B00F93E40 /* Mocha-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Mocha-Info.plist"; sourceTree = "<group>"; };
+ EAA45E10155CE44B00F93E40 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+ EAA45E12155CE44B00F93E40 /* Mocha-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Mocha-Prefix.pch"; sourceTree = "<group>"; };
+ EAA45E13155CE44B00F93E40 /* Mocha.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Mocha.h; sourceTree = "<group>"; };
+ EAA45E14155CE44B00F93E40 /* Mocha.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Mocha.m; sourceTree = "<group>"; };
+ EAA45E1B155CE46000F93E40 /* MochaDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MochaDefines.h; sourceTree = "<group>"; };
+ EAA45E1E155CE4CB00F93E40 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
+ EAA45E22155CE57600F93E40 /* MochaRuntime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MochaRuntime.h; sourceTree = "<group>"; };
+ EAA45E23155CE57600F93E40 /* MochaRuntime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MochaRuntime.m; sourceTree = "<group>"; };
+ EAA45E26155CE66600F93E40 /* MochaRuntime_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MochaRuntime_Private.h; sourceTree = "<group>"; };
+ EAA45E2E155CF26B00F93E40 /* MOException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOException.h; sourceTree = "<group>"; };
+ EAA45E2F155CF26C00F93E40 /* MOException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MOException.m; sourceTree = "<group>"; };
+ EAA45E32155CF2FD00F93E40 /* MOException_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOException_Private.h; sourceTree = "<group>"; };
+ EAA45E38155D09A700F93E40 /* MOObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOObject.h; sourceTree = "<group>"; };
+ EAA45E39155D09A700F93E40 /* MOObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MOObject.m; sourceTree = "<group>"; };
+ EAA45E49155E5DB100F93E40 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
+ EAA45E4C155E5DB100F93E40 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
+ EAA45E4D155E5DB100F93E40 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
+ EAA45E4E155E5DB100F93E40 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ EAA45E71155EE5AF00F93E40 /* moc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = moc; sourceTree = BUILT_PRODUCTS_DIR; };
+ EAA45E75155EE5AF00F93E40 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ EAA45E78155EE5AF00F93E40 /* moc-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "moc-Prefix.pch"; sourceTree = "<group>"; };
+ EAA45E7F155EE68000F93E40 /* MOCInterpreter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOCInterpreter.h; sourceTree = "<group>"; };
+ EAA45E80155EE68000F93E40 /* MOCInterpreter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MOCInterpreter.m; sourceTree = "<group>"; };
+ EAA45E86155EE97200F93E40 /* MOFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOFunction.h; sourceTree = "<group>"; };
+ EAA45E87155EE97200F93E40 /* MOFunction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MOFunction.m; sourceTree = "<group>"; };
+ EAA45E8A155EEA2F00F93E40 /* MOFunction_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOFunction_Private.h; sourceTree = "<group>"; };
+ EAA45E8E155EEB1900F93E40 /* MOBridgeSupportObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOBridgeSupportObject.h; sourceTree = "<group>"; };
+ EAA45E8F155EEB1900F93E40 /* MOBridgeSupportObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MOBridgeSupportObject.m; sourceTree = "<group>"; };
+ EAA45E92155EEB9400F93E40 /* MOBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOBox.h; sourceTree = "<group>"; };
+ EAA45E93155EEB9400F93E40 /* MOBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MOBox.m; sourceTree = "<group>"; };
+ EAA45EAA155F0B4600F93E40 /* libreadline.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libreadline.dylib; path = usr/lib/libreadline.dylib; sourceTree = SDKROOT; };
+ EAC8BFC2155F3E01003653BA /* NSArray+MochaAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MochaAdditions.h"; sourceTree = "<group>"; };
+ EAC8BFC3155F3E01003653BA /* NSArray+MochaAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+MochaAdditions.m"; sourceTree = "<group>"; };
+ EAC8BFC7155F3ECD003653BA /* NSDictionary+MochaAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+MochaAdditions.h"; sourceTree = "<group>"; };
+ EAC8BFC8155F3ECD003653BA /* NSDictionary+MochaAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+MochaAdditions.m"; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ EAA45DFF155CE44B00F93E40 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ EAA45E20155CE4D100F93E40 /* Foundation.framework in Frameworks */,
+ EAA45E1F155CE4CB00F93E40 /* JavaScriptCore.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ EAA45E6E155EE5AF00F93E40 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ EAA45E73155EE5AF00F93E40 /* Foundation.framework in Frameworks */,
+ EAA45EAD155F0CC800F93E40 /* JavaScriptCore.framework in Frameworks */,
+ EAA45E7E155EE63700F93E40 /* Mocha.framework in Frameworks */,
+ EAA45EAB155F0B4600F93E40 /* libreadline.dylib in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 0211231E155D7BAE00415471 /* Exceptions */ = {
+ isa = PBXGroup;
+ children = (
+ EAA45E2E155CF26B00F93E40 /* MOException.h */,
+ EAA45E32155CF2FD00F93E40 /* MOException_Private.h */,
+ EAA45E2F155CF26C00F93E40 /* MOException.m */,
+ );
+ path = Exceptions;
+ sourceTree = "<group>";
+ };
+ 02112329155D99CA00415471 /* BridgeSupport */ = {
+ isa = PBXGroup;
+ children = (
+ 02112325155D973100415471 /* MOBridgeSupportController.h */,
+ 02112326155D973100415471 /* MOBridgeSupportController.m */,
+ 02112340155DB9A100415471 /* MOBridgeSupportParser.h */,
+ 02112341155DB9A100415471 /* MOBridgeSupportParser.m */,
+ 0211233C155DB8F800415471 /* MOBridgeSupportLibrary.h */,
+ 0211233D155DB8F800415471 /* MOBridgeSupportLibrary.m */,
+ 0211232A155D99F600415471 /* MOBridgeSupportSymbol.h */,
+ 0211232B155D99F600415471 /* MOBridgeSupportSymbol.m */,
+ );
+ path = BridgeSupport;
+ sourceTree = "<group>";
+ };
+ EAA45DF7155CE44B00F93E40 = {
+ isa = PBXGroup;
+ children = (
+ EAA45E0C155CE44B00F93E40 /* Mocha */,
+ EAA45E74155EE5AF00F93E40 /* moc */,
+ EAA45E05155CE44B00F93E40 /* Frameworks */,
+ EAA45E04155CE44B00F93E40 /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ EAA45E04155CE44B00F93E40 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ EAA45E03155CE44B00F93E40 /* Mocha.framework */,
+ EAA45E71155EE5AF00F93E40 /* moc */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ EAA45E05155CE44B00F93E40 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ EAA45E1E155CE4CB00F93E40 /* JavaScriptCore.framework */,
+ EAA45E0B155CE44B00F93E40 /* Foundation.framework */,
+ EAA45E49155E5DB100F93E40 /* Cocoa.framework */,
+ EAA45EAA155F0B4600F93E40 /* libreadline.dylib */,
+ EAA45E4B155E5DB100F93E40 /* Other Frameworks */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ EAA45E0C155CE44B00F93E40 /* Mocha */ = {
+ isa = PBXGroup;
+ children = (
+ EAA45E13155CE44B00F93E40 /* Mocha.h */,
+ EAA45E14155CE44B00F93E40 /* Mocha.m */,
+ EAA45E1B155CE46000F93E40 /* MochaDefines.h */,
+ EAA45E22155CE57600F93E40 /* MochaRuntime.h */,
+ EAA45E26155CE66600F93E40 /* MochaRuntime_Private.h */,
+ EAA45E23155CE57600F93E40 /* MochaRuntime.m */,
+ EAA45E3C155D09AA00F93E40 /* Objects */,
+ 0211231E155D7BAE00415471 /* Exceptions */,
+ 02112329155D99CA00415471 /* BridgeSupport */,
+ EAA45E68155E5E2200F93E40 /* Utilities */,
+ EAC8BFCB155F42D3003653BA /* Categories */,
+ EAA45E0D155CE44B00F93E40 /* Supporting Files */,
+ );
+ path = Mocha;
+ sourceTree = "<group>";
+ };
+ EAA45E0D155CE44B00F93E40 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ EAA45E0E155CE44B00F93E40 /* Mocha-Info.plist */,
+ EAA45E0F155CE44B00F93E40 /* InfoPlist.strings */,
+ EAA45E12155CE44B00F93E40 /* Mocha-Prefix.pch */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+ EAA45E3C155D09AA00F93E40 /* Objects */ = {
+ isa = PBXGroup;
+ children = (
+ EAA45E92155EEB9400F93E40 /* MOBox.h */,
+ EAA45E93155EEB9400F93E40 /* MOBox.m */,
+ EAA45E38155D09A700F93E40 /* MOObject.h */,
+ EAA45E39155D09A700F93E40 /* MOObject.m */,
+ EAA45E86155EE97200F93E40 /* MOFunction.h */,
+ EAA45E8A155EEA2F00F93E40 /* MOFunction_Private.h */,
+ EAA45E87155EE97200F93E40 /* MOFunction.m */,
+ EAA45E8E155EEB1900F93E40 /* MOBridgeSupportObject.h */,
+ EAA45E8F155EEB1900F93E40 /* MOBridgeSupportObject.m */,
+ );
+ path = Objects;
+ sourceTree = "<group>";
+ };
+ EAA45E4B155E5DB100F93E40 /* Other Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ EAA45E4C155E5DB100F93E40 /* AppKit.framework */,
+ EAA45E4D155E5DB100F93E40 /* CoreData.framework */,
+ EAA45E4E155E5DB100F93E40 /* Foundation.framework */,
+ );
+ name = "Other Frameworks";
+ sourceTree = "<group>";
+ };
+ EAA45E68155E5E2200F93E40 /* Utilities */ = {
+ isa = PBXGroup;
+ children = (
+ 02112321155D7BD000415471 /* MOUtilities.h */,
+ 02112322155D7BD000415471 /* MOUtilities.m */,
+ );
+ path = Utilities;
+ sourceTree = "<group>";
+ };
+ EAA45E74155EE5AF00F93E40 /* moc */ = {
+ isa = PBXGroup;
+ children = (
+ EAA45E75155EE5AF00F93E40 /* main.m */,
+ EAA45E7F155EE68000F93E40 /* MOCInterpreter.h */,
+ EAA45E80155EE68000F93E40 /* MOCInterpreter.m */,
+ EAA45E77155EE5AF00F93E40 /* Supporting Files */,
+ );
+ path = moc;
+ sourceTree = "<group>";
+ };
+ EAA45E77155EE5AF00F93E40 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ EAA45E78155EE5AF00F93E40 /* moc-Prefix.pch */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+ EAC8BFCB155F42D3003653BA /* Categories */ = {
+ isa = PBXGroup;
+ children = (
+ EAC8BFC2155F3E01003653BA /* NSArray+MochaAdditions.h */,
+ EAC8BFC3155F3E01003653BA /* NSArray+MochaAdditions.m */,
+ EAC8BFC7155F3ECD003653BA /* NSDictionary+MochaAdditions.h */,
+ EAC8BFC8155F3ECD003653BA /* NSDictionary+MochaAdditions.m */,
+ );
+ path = Categories;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+ EAA45E00155CE44B00F93E40 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ EAA45E1C155CE46000F93E40 /* MochaDefines.h in Headers */,
+ EAA45E1D155CE46400F93E40 /* Mocha.h in Headers */,
+ EAA45E24155CE57600F93E40 /* MochaRuntime.h in Headers */,
+ EAA45E27155CE66600F93E40 /* MochaRuntime_Private.h in Headers */,
+ EAA45E30155CF26C00F93E40 /* MOException.h in Headers */,
+ EAA45E33155CF2FD00F93E40 /* MOException_Private.h in Headers */,
+ EAA45E3A155D09A700F93E40 /* MOObject.h in Headers */,
+ 02112323155D7BD000415471 /* MOUtilities.h in Headers */,
+ 02112327155D973100415471 /* MOBridgeSupportController.h in Headers */,
+ 0211232C155D99F600415471 /* MOBridgeSupportSymbol.h in Headers */,
+ 0211233E155DB8F800415471 /* MOBridgeSupportLibrary.h in Headers */,
+ 02112342155DB9A100415471 /* MOBridgeSupportParser.h in Headers */,
+ EAA45E88155EE97200F93E40 /* MOFunction.h in Headers */,
+ EAA45E8B155EEA3000F93E40 /* MOFunction_Private.h in Headers */,
+ EAA45E90155EEB1900F93E40 /* MOBridgeSupportObject.h in Headers */,
+ EAA45E94155EEB9500F93E40 /* MOBox.h in Headers */,
+ EAC8BFC4155F3E01003653BA /* NSArray+MochaAdditions.h in Headers */,
+ EAC8BFC9155F3ECD003653BA /* NSDictionary+MochaAdditions.h in Headers */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXNativeTarget section */
+ EAA45E02155CE44B00F93E40 /* Mocha */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = EAA45E18155CE44B00F93E40 /* Build configuration list for PBXNativeTarget "Mocha" */;
+ buildPhases = (
+ EAA45DFE155CE44B00F93E40 /* Sources */,
+ EAA45DFF155CE44B00F93E40 /* Frameworks */,
+ EAA45E00155CE44B00F93E40 /* Headers */,
+ EAA45E01155CE44B00F93E40 /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = Mocha;
+ productName = Mocha;
+ productReference = EAA45E03155CE44B00F93E40 /* Mocha.framework */;
+ productType = "com.apple.product-type.framework";
+ };
+ EAA45E70155EE5AF00F93E40 /* moc */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = EAA45E7B155EE5AF00F93E40 /* Build configuration list for PBXNativeTarget "moc" */;
+ buildPhases = (
+ EAA45E6D155EE5AF00F93E40 /* Sources */,
+ EAA45E6E155EE5AF00F93E40 /* Frameworks */,
+ EAA45E6F155EE5AF00F93E40 /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ EAA45EA9155F0B3200F93E40 /* PBXTargetDependency */,
+ );
+ name = moc;
+ productName = moc;
+ productReference = EAA45E71155EE5AF00F93E40 /* moc */;
+ productType = "com.apple.product-type.tool";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ EAA45DF9155CE44B00F93E40 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0430;
+ ORGANIZATIONNAME = "Sunflower Softworks";
+ };
+ buildConfigurationList = EAA45DFC155CE44B00F93E40 /* Build configuration list for PBXProject "Mocha" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ );
+ mainGroup = EAA45DF7155CE44B00F93E40;
+ productRefGroup = EAA45E04155CE44B00F93E40 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ EAA45E02155CE44B00F93E40 /* Mocha */,
+ EAA45E70155EE5AF00F93E40 /* moc */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ EAA45E01155CE44B00F93E40 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ EAA45E11155CE44B00F93E40 /* InfoPlist.strings in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ EAA45DFE155CE44B00F93E40 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ EAA45E15155CE44B00F93E40 /* Mocha.m in Sources */,
+ EAA45E25155CE57600F93E40 /* MochaRuntime.m in Sources */,
+ EAA45E31155CF26C00F93E40 /* MOException.m in Sources */,
+ EAA45E3B155D09A700F93E40 /* MOObject.m in Sources */,
+ 02112324155D7BD000415471 /* MOUtilities.m in Sources */,
+ 02112328155D973100415471 /* MOBridgeSupportController.m in Sources */,
+ 0211232D155D99F600415471 /* MOBridgeSupportSymbol.m in Sources */,
+ 0211233F155DB8F800415471 /* MOBridgeSupportLibrary.m in Sources */,
+ 02112343155DB9A100415471 /* MOBridgeSupportParser.m in Sources */,
+ EAA45E89155EE97200F93E40 /* MOFunction.m in Sources */,
+ EAA45E91155EEB1900F93E40 /* MOBridgeSupportObject.m in Sources */,
+ EAA45E95155EEB9500F93E40 /* MOBox.m in Sources */,
+ EAC8BFC5155F3E01003653BA /* NSArray+MochaAdditions.m in Sources */,
+ EAC8BFCA155F3ECD003653BA /* NSDictionary+MochaAdditions.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ EAA45E6D155EE5AF00F93E40 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ EAA45E76155EE5AF00F93E40 /* main.m in Sources */,
+ EAA45E81155EE68000F93E40 /* MOCInterpreter.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXTargetDependency section */
+ EAA45EA9155F0B3200F93E40 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = EAA45E02155CE44B00F93E40 /* Mocha */;
+ targetProxy = EAA45EA8155F0B3200F93E40 /* PBXContainerItemProxy */;
+ };
+/* End PBXTargetDependency section */
+
+/* Begin PBXVariantGroup section */
+ EAA45E0F155CE44B00F93E40 /* InfoPlist.strings */ = {
+ isa = PBXVariantGroup;
+ children = (
+ EAA45E10155CE44B00F93E40 /* en */,
+ );
+ name = InfoPlist.strings;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ EAA45E16155CE44B00F93E40 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ COPY_PHASE_STRIP = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ EAA45E17155CE44B00F93E40 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
+ EAA45E19155CE44B00F93E40 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1;
+ FRAMEWORK_VERSION = A;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "Mocha/Mocha-Prefix.pch";
+ INFOPLIST_FILE = "Mocha/Mocha-Info.plist";
+ INSTALL_PATH = "@rpath";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = framework;
+ };
+ name = Debug;
+ };
+ EAA45E1A155CE44B00F93E40 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1;
+ FRAMEWORK_VERSION = A;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "Mocha/Mocha-Prefix.pch";
+ INFOPLIST_FILE = "Mocha/Mocha-Info.plist";
+ INSTALL_PATH = "@rpath";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = framework;
+ };
+ name = Release;
+ };
+ EAA45E7C155EE5AF00F93E40 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "moc/moc-Prefix.pch";
+ LD_RUNPATH_SEARCH_PATHS = "@loader_path/../../../../ @loader_path/";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ EAA45E7D155EE5AF00F93E40 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "moc/moc-Prefix.pch";
+ LD_RUNPATH_SEARCH_PATHS = "@loader_path/../../../../ @loader_path/";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ EAA45DFC155CE44B00F93E40 /* Build configuration list for PBXProject "Mocha" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ EAA45E16155CE44B00F93E40 /* Debug */,
+ EAA45E17155CE44B00F93E40 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ EAA45E18155CE44B00F93E40 /* Build configuration list for PBXNativeTarget "Mocha" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ EAA45E19155CE44B00F93E40 /* Debug */,
+ EAA45E1A155CE44B00F93E40 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ EAA45E7B155EE5AF00F93E40 /* Build configuration list for PBXNativeTarget "moc" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ EAA45E7C155EE5AF00F93E40 /* Debug */,
+ EAA45E7D155EE5AF00F93E40 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = EAA45DF9155CE44B00F93E40 /* Project object */;
+}
24 Mocha/BridgeSupport/MOBridgeSupportController.h
@@ -0,0 +1,24 @@
+//
+// MOBridgeSupportController.h
+// Mocha
+//
+// Created by Logan Collins on 5/11/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@class MOBridgeSupportSymbol;
+
+
+@interface MOBridgeSupportController : NSObject
+
++ (MOBridgeSupportController *)sharedController;
+
+- (BOOL)isBridgeSupportLoadedForURL:(NSURL *)aURL;
+- (BOOL)loadBridgeSupportAtURL:(NSURL *)aURL error:(NSError **)outError;
+
+- (MOBridgeSupportSymbol *)performQueryForSymbolName:(NSString *)name;
+
+@end
94 Mocha/BridgeSupport/MOBridgeSupportController.m
@@ -0,0 +1,94 @@
+//
+// MOBridgeSupportController.m
+// Mocha
+//
+// Created by Logan Collins on 5/11/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import "MOBridgeSupportController.h"
+
+#import "MOBridgeSupportLibrary.h"
+#import "MOBridgeSupportSymbol.h"
+
+#import "MOBridgeSupportParser.h"
+
+
+@implementation MOBridgeSupportController {
+ NSMutableArray *_loadedURLs;
+ NSMutableArray *_loadedLibraries;
+ NSMutableDictionary *_symbols;
+ MOBridgeSupportParser *_parser;
+}
+
++ (MOBridgeSupportController *)sharedController {
+ static MOBridgeSupportController *sharedController = nil;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ sharedController = [[self alloc] init];
+ });
+ return sharedController;
+}
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ _loadedURLs = [[NSMutableArray alloc] init];
+ _loadedLibraries = [[NSMutableArray alloc] init];
+ _symbols = [[NSMutableDictionary alloc] init];
+ _parser = [[MOBridgeSupportParser alloc] init];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [_loadedURLs release];
+ [_loadedLibraries release];
+ [_symbols release];
+ [_parser release];
+ [super dealloc];
+}
+
+
+#pragma mark -
+#pragma mark Loading
+
+- (BOOL)isBridgeSupportLoadedForURL:(NSURL *)aURL {
+ return [_loadedURLs containsObject:aURL];
+}
+
+- (BOOL)loadBridgeSupportAtURL:(NSURL *)aURL error:(NSError **)outError {
+ if ([self isBridgeSupportLoadedForURL:aURL]) {
+ return YES;
+ }
+
+ MOBridgeSupportLibrary *library = [_parser libraryWithBridgeSupportURL:aURL error:outError];
+ if (library == nil) {
+ return NO;
+ }
+
+ [_loadedURLs addObject:aURL];
+ [_loadedLibraries addObject:library];
+
+ for (NSString *name in library.symbols) {
+ MOBridgeSupportSymbol *symbol = [library.symbols objectForKey:name];
+ if ([_symbols objectForKey:name] == nil) {
+ [_symbols setObject:symbol forKey:name];
+ }
+ else {
+ //NSLog(@"Symbol with name \"%@\" is already loaded.", name);
+ }
+ }
+
+ return YES;
+}
+
+
+#pragma mark -
+#pragma mark Queries
+
+- (MOBridgeSupportSymbol *)performQueryForSymbolName:(NSString *)name {
+ return [_symbols objectForKey:name];
+}
+
+@end
29 Mocha/BridgeSupport/MOBridgeSupportLibrary.h
@@ -0,0 +1,29 @@
+//
+// MOBridgeSupportLibrary.h
+// Mocha
+//
+// Created by Logan Collins on 5/11/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@class MOBridgeSupportSymbol;
+
+
+@interface MOBridgeSupportLibrary : NSObject
+
+@property (copy) NSString *name;
+@property (copy) NSURL *URL;
+
+@property (copy) NSArray *dependencies;
+- (void)addDependency:(NSString *)dependency;
+- (void)removeDependency:(NSString *)dependency;
+
+@property (copy) NSDictionary *symbols;
+- (MOBridgeSupportSymbol *)symbolWithName:(NSString *)name;
+- (void)setSymbol:(MOBridgeSupportSymbol *)symbol forName:(NSString *)name;
+- (void)removeSymbolForName:(NSString *)name;
+
+@end
85 Mocha/BridgeSupport/MOBridgeSupportLibrary.m
@@ -0,0 +1,85 @@
+//
+// MOBridgeSupportLibrary.m
+// Mocha
+//
+// Created by Logan Collins on 5/11/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import "MOBridgeSupportLibrary.h"
+
+
+@implementation MOBridgeSupportLibrary {
+ NSMutableArray *_dependencies;
+ NSMutableDictionary *_symbols;
+}
+
+@synthesize name=_name;
+@synthesize URL=_URL;
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ _dependencies = [[NSMutableArray alloc] init];
+ _symbols = [[NSMutableDictionary alloc] init];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [_name release];
+ [_URL release];
+ [_dependencies release];
+ [_symbols release];
+ [super dealloc];
+}
+
+
+#pragma mark -
+#pragma mark Dependencies
+
+- (NSArray *)dependencies {
+ return _dependencies;
+}
+
+- (void)setDependencies:(NSArray *)dependencies {
+ [_dependencies setArray:dependencies];
+}
+
+- (void)addDependency:(NSString *)dependency {
+ if (![_dependencies containsObject:dependency]) {
+ [_dependencies addObject:dependency];
+ }
+}
+
+- (void)removeDependency:(NSString *)dependency {
+ if ([_dependencies containsObject:dependency]) {
+ [_dependencies removeObject:dependency];
+ }
+}
+
+
+#pragma mark -
+#pragma mark Symbols
+
+- (NSDictionary *)symbols {
+ return _symbols;
+}
+
+- (void)setSymbols:(NSDictionary *)symbols {
+ [_symbols setDictionary:symbols];
+}
+
+- (MOBridgeSupportSymbol *)symbolWithName:(NSString *)name {
+ return [_symbols objectForKey:name];
+}
+
+- (void)setSymbol:(MOBridgeSupportSymbol *)symbol forName:(NSString *)name {
+ [_symbols setObject:symbol forKey:name];
+}
+
+- (void)removeSymbolForName:(NSString *)name {
+ [_symbols removeObjectForKey:name];
+}
+
+@end
19 Mocha/BridgeSupport/MOBridgeSupportParser.h
@@ -0,0 +1,19 @@
+//
+// MOBridgeSupportParser.h
+// Mocha
+//
+// Created by Logan Collins on 5/11/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@class MOBridgeSupportLibrary;
+
+
+@interface MOBridgeSupportParser : NSObject
+
+- (MOBridgeSupportLibrary *)libraryWithBridgeSupportURL:(NSURL *)aURL error:(NSError **)outError;
+
+@end
288 Mocha/BridgeSupport/MOBridgeSupportParser.m
@@ -0,0 +1,288 @@
+//
+// MOBridgeSupportParser.m
+// Mocha
+//
+// Created by Logan Collins on 5/11/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import "MOBridgeSupportParser.h"
+#import "MOBridgeSupportLibrary.h"
+#import "MOBridgeSupportSymbol.h"
+
+
+#define PARSER_DEBUG 0
+
+
+@interface MOBridgeSupportParser () <NSXMLParserDelegate>
+
+@end
+
+
+@implementation MOBridgeSupportParser {
+ NSXMLParser *_parser;
+ MOBridgeSupportLibrary *_library;
+ NSMutableArray *_symbolStack;
+}
+
+- (id)init {
+ self = [super init];
+ if (self) {
+
+ }
+ return self;
+}
+
+- (void)dealloc {
+ _parser = nil;
+ _library = nil;
+ _symbolStack = nil;
+
+ [super dealloc];
+}
+
+- (MOBridgeSupportLibrary *)libraryWithBridgeSupportURL:(NSURL *)aURL error:(NSError **)outError {
+ _parser = [[NSXMLParser alloc] initWithContentsOfURL:aURL];
+ [_parser setDelegate:self];
+
+ BOOL success = [_parser parse];
+ if (!success) {
+ [_library release];
+ _library = nil;
+ }
+
+ NSError *error = [_parser parserError];
+ if (outError != NULL) {
+ *outError = error;
+ }
+
+ [_parser release], _parser = nil;
+
+ return [_library autorelease];
+}
+
+
+#pragma mark -
+#pragma mark XML Parser delegate
+
+- (void)parserDidStartDocument:(NSXMLParser *)parser {
+#if PARSER_DEBUG
+ NSLog(@"Parser didStartDocument");
+#endif
+
+ _library = [[MOBridgeSupportLibrary alloc] init];
+ _symbolStack = [[NSMutableArray alloc] init];
+}
+
+- (void)parserDidEndDocument:(NSXMLParser *)parser {
+#if PARSER_DEBUG
+ NSLog(@"Parser didEndDocument");
+#endif
+
+ [_symbolStack release], _symbolStack = nil;
+}
+
+- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
+#if PARSER_DEBUG
+ NSLog(@"Parser didStartElement: %@, attributes=%@", elementName, attributeDict);
+#endif
+
+ if ([elementName isEqualToString:@"signatures"]) {
+ // Signatures
+
+ }
+ else if ([elementName isEqualToString:@"depends_on"]) {
+ // Dependency
+ NSString *path = [attributeDict objectForKey:@"path"];
+ [_library addDependency:path];
+ }
+ else if ([elementName isEqualToString:@"struct"]) {
+ // Struct
+ MOBridgeSupportStruct *symbol = [[[MOBridgeSupportStruct alloc] init] autorelease];
+ symbol.name = [attributeDict objectForKey:@"name"];
+ symbol.type = [attributeDict objectForKey:@"type"];
+ symbol.type64 = [attributeDict objectForKey:@"type64"];
+ symbol.opaque = [[attributeDict objectForKey:@"opaque"] isEqualToString:@"true"];
+ [_library setSymbol:symbol forName:symbol.name];
+ }
+ else if ([elementName isEqualToString:@"cftype"]) {
+ // CFType
+ MOBridgeSupportCFType *symbol = [[[MOBridgeSupportCFType alloc] init] autorelease];
+ symbol.name = [attributeDict objectForKey:@"name"];
+ symbol.type = [attributeDict objectForKey:@"type"];
+ symbol.type64 = [attributeDict objectForKey:@"type64"];
+ symbol.tollFreeBridgedClassName = [attributeDict objectForKey:@"tollfree"];
+ symbol.getTypeIDFunctionName = [attributeDict objectForKey:@"gettypeid_func"];
+ [_library setSymbol:symbol forName:symbol.name];
+ }
+ else if ([elementName isEqualToString:@"opaque"]) {
+ // Opaque
+ MOBridgeSupportOpaque *symbol = [[[MOBridgeSupportOpaque alloc] init] autorelease];
+ symbol.name = [attributeDict objectForKey:@"name"];
+ symbol.type = [attributeDict objectForKey:@"type"];
+ symbol.type64 = [attributeDict objectForKey:@"type64"];
+ [_library setSymbol:symbol forName:symbol.name];
+ }
+ else if ([elementName isEqualToString:@"constant"]) {
+ // Constant
+ MOBridgeSupportConstant *symbol = [[[MOBridgeSupportConstant alloc] init] autorelease];
+ symbol.name = [attributeDict objectForKey:@"name"];
+ symbol.type = [attributeDict objectForKey:@"type"];
+ symbol.type64 = [attributeDict objectForKey:@"type64"];
+ symbol.hasMagicCookie = [[attributeDict objectForKey:@"magic_cookie"] isEqualToString:@"true"];
+ [_library setSymbol:symbol forName:symbol.name];
+ }
+ else if ([elementName isEqualToString:@"string_constant"]) {
+ // String constant
+ MOBridgeSupportStringConstant *symbol = [[[MOBridgeSupportStringConstant alloc] init] autorelease];
+ symbol.name = [attributeDict objectForKey:@"name"];
+ symbol.value = [attributeDict objectForKey:@"value"];
+ symbol.hasNSString = [[attributeDict objectForKey:@"nsstring"] isEqualToString:@"true"];
+ [_library setSymbol:symbol forName:symbol.name];
+ }
+ else if ([elementName isEqualToString:@"enum"]) {
+ // Enum
+ MOBridgeSupportEnum *symbol = [[[MOBridgeSupportEnum alloc] init] autorelease];
+ symbol.name = [attributeDict objectForKey:@"name"];
+ if ([attributeDict objectForKey:@"value"]) {
+ symbol.value = [NSNumber numberWithInteger:[[attributeDict objectForKey:@"value"] integerValue]];
+ }
+ if ([attributeDict objectForKey:@"value64"]) {
+ symbol.value64 = [NSNumber numberWithInteger:[[attributeDict objectForKey:@"value64"] integerValue]];
+ }
+ symbol.ignored = [[attributeDict objectForKey:@"ignore"] isEqualToString:@"true"];
+ symbol.suggestion = [attributeDict objectForKey:@"suggestion"];
+ [_library setSymbol:symbol forName:symbol.name];
+ }
+ else if ([elementName isEqualToString:@"function"]) {
+ // Function
+ MOBridgeSupportFunction *symbol = [[[MOBridgeSupportFunction alloc] init] autorelease];
+ symbol.name = [attributeDict objectForKey:@"name"];
+ symbol.variadic = [[attributeDict objectForKey:@"variadic"] isEqualToString:@"true"];
+ if ([attributeDict objectForKey:@"sentinel"]) {
+ symbol.sentinel = [NSNumber numberWithInteger:[[attributeDict objectForKey:@"sentinel"] integerValue]];
+ }
+ symbol.inlineFunction = [[attributeDict objectForKey:@"inline"] isEqualToString:@"true"];
+ [_library setSymbol:symbol forName:symbol.name];
+ }
+ else if ([elementName isEqualToString:@"function_alias"]) {
+ // Function alias
+ MOBridgeSupportFunctionAlias *symbol = [[[MOBridgeSupportFunctionAlias alloc] init] autorelease];
+ symbol.name = [attributeDict objectForKey:@"name"];
+ symbol.original = [attributeDict objectForKey:@"original"];
+ [_library setSymbol:symbol forName:symbol.name];
+ }
+ else if ([elementName isEqualToString:@"class"]) {
+ // Class
+ MOBridgeSupportClass *symbol = [[[MOBridgeSupportClass alloc] init] autorelease];
+ symbol.name = [attributeDict objectForKey:@"name"];
+ [_library setSymbol:symbol forName:symbol.name];
+ [_symbolStack addObject:symbol];
+ }
+ else if ([elementName isEqualToString:@"informal_protocol"]) {
+ // Informal protocol
+ MOBridgeSupportInformalProtocol *symbol = [[[MOBridgeSupportInformalProtocol alloc] init] autorelease];
+ symbol.name = [attributeDict objectForKey:@"name"];
+ [_library setSymbol:symbol forName:symbol.name];
+ [_symbolStack addObject:symbol];
+ }
+ else if ([elementName isEqualToString:@"method"]) {
+ // Method
+ MOBridgeSupportMethod *symbol = [[[MOBridgeSupportMethod alloc] init] autorelease];
+ symbol.name = [attributeDict objectForKey:@"name"];
+ if ([attributeDict objectForKey:@"selector"]) {
+ symbol.selector = NSSelectorFromString([attributeDict objectForKey:@"selector"]);
+ }
+ symbol.type = [attributeDict objectForKey:@"type"];
+ symbol.type64 = [attributeDict objectForKey:@"type64"];
+ symbol.classMethod = [[attributeDict objectForKey:@"class_method"] isEqualToString:@"true"];
+ symbol.variadic = [[attributeDict objectForKey:@"variadic"] isEqualToString:@"true"];
+ if ([attributeDict objectForKey:@"sentinel"]) {
+ symbol.sentinel = [NSNumber numberWithInteger:[[attributeDict objectForKey:@"sentinel"] integerValue]];
+ }
+ symbol.ignored = [[attributeDict objectForKey:@"ignore"] isEqualToString:@"true"];
+ symbol.suggestion = [attributeDict objectForKey:@"suggestion"];
+
+ MOBridgeSupportSymbol *currentSymbol = [_symbolStack lastObject];
+ if ([currentSymbol isKindOfClass:[MOBridgeSupportClass class]]
+ || [currentSymbol isKindOfClass:[MOBridgeSupportInformalProtocol class]]) {
+ [(MOBridgeSupportClass *)currentSymbol addMethod:symbol];
+ }
+
+ [_symbolStack addObject:symbol];
+ }
+ else if ([elementName isEqualToString:@"arg"]) {
+ // Argument
+ MOBridgeSupportArgument *argument = [[[MOBridgeSupportArgument alloc] init] autorelease];
+ argument.cArrayLengthInArg = [attributeDict objectForKey:@"c_array_length_in_arg"];
+ argument.cArrayOfFixedLength = [[attributeDict objectForKey:@"c_array_of_fixed_length"] isEqualToString:@"true"];
+ argument.cArrayDelimitedByNull = [[attributeDict objectForKey:@"c_array_delimited_by_null"] isEqualToString:@"true"];
+ argument.cArrayOfVariableLength = [[attributeDict objectForKey:@"c_array_of_variable_length"] isEqualToString:@"true"];
+ argument.functionPointer = [[attributeDict objectForKey:@"function_pointer"] isEqualToString:@"true"];
+ argument.signature = [attributeDict objectForKey:@"sel_of_type"];
+ argument.signature64 = [attributeDict objectForKey:@"sel_of_type64"];
+ argument.cArrayLengthInReturnValue = [[attributeDict objectForKey:@"c_array_length_in_retval"] isEqualToString:@"true"];
+ argument.acceptsNull = ![[attributeDict objectForKey:@"null_accepted"] isEqualToString:@"false"];
+ argument.acceptsPrintfFormat = [[attributeDict objectForKey:@"printf_format"] isEqualToString:@"true"];
+ argument.alreadyRetained = [[attributeDict objectForKey:@"already_retained"] isEqualToString:@"true"];
+ argument.type = [attributeDict objectForKey:@"type"];
+ argument.type64 = [attributeDict objectForKey:@"type64"];
+ argument.index = [[attributeDict objectForKey:@"index"] integerValue];
+
+ MOBridgeSupportSymbol *currentSymbol = [_symbolStack lastObject];
+ if ([currentSymbol isKindOfClass:[MOBridgeSupportMethod class]]) {
+ [(MOBridgeSupportMethod *)currentSymbol addArgument:argument];
+ }
+ }
+ else if ([elementName isEqualToString:@"retval"]) {
+ // Return value
+ MOBridgeSupportArgument *argument = [[[MOBridgeSupportArgument alloc] init] autorelease];
+ argument.cArrayLengthInArg = [attributeDict objectForKey:@"c_array_length_in_arg"];
+ argument.cArrayOfFixedLength = [[attributeDict objectForKey:@"c_array_of_fixed_length"] isEqualToString:@"true"];
+ argument.cArrayDelimitedByNull = [[attributeDict objectForKey:@"c_array_delimited_by_null"] isEqualToString:@"true"];
+ argument.cArrayOfVariableLength = [[attributeDict objectForKey:@"c_array_of_variable_length"] isEqualToString:@"true"];
+ argument.functionPointer = [[attributeDict objectForKey:@"function_pointer"] isEqualToString:@"true"];
+ argument.signature = [attributeDict objectForKey:@"sel_of_type"];
+ argument.signature64 = [attributeDict objectForKey:@"sel_of_type64"];
+ argument.cArrayLengthInReturnValue = [[attributeDict objectForKey:@"c_array_length_in_retval"] isEqualToString:@"true"];
+ argument.acceptsNull = ![[attributeDict objectForKey:@"null_accepted"] isEqualToString:@"false"];
+ argument.acceptsPrintfFormat = [[attributeDict objectForKey:@"printf_format"] isEqualToString:@"true"];
+ argument.alreadyRetained = [[attributeDict objectForKey:@"already_retained"] isEqualToString:@"true"];
+ argument.type = [attributeDict objectForKey:@"type"];
+ argument.type64 = [attributeDict objectForKey:@"type64"];
+ argument.index = [[attributeDict objectForKey:@"index"] integerValue];
+
+ MOBridgeSupportSymbol *currentSymbol = [_symbolStack lastObject];
+ if ([currentSymbol isKindOfClass:[MOBridgeSupportMethod class]]) {
+ [(MOBridgeSupportMethod *)currentSymbol setReturnValue:argument];
+ }
+ }
+}
+
+- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
+#if PARSER_DEBUG
+ NSLog(@"Parser didEndElement: %@", elementName);
+#endif
+
+ MOBridgeSupportSymbol *currentSymbol = [_symbolStack lastObject];
+ if ([elementName isEqualToString:@"class"]) {
+ // Class
+ if ([currentSymbol isKindOfClass:[MOBridgeSupportClass class]]) {
+ [_symbolStack removeLastObject];
+ }
+ }
+ else if ([elementName isEqualToString:@"informal_protocol"]) {
+ // Informal protocol
+ if ([currentSymbol isKindOfClass:[MOBridgeSupportInformalProtocol class]]) {
+ [_symbolStack removeLastObject];
+ }
+ }
+ else if ([elementName isEqualToString:@"method"]) {
+ // Method
+ if ([currentSymbol isKindOfClass:[MOBridgeSupportMethod class]]) {
+ [_symbolStack removeLastObject];
+ }
+ }
+}
+
+@end
219 Mocha/BridgeSupport/MOBridgeSupportSymbol.h
@@ -0,0 +1,219 @@
+//
+// MOBridgeSupportSymbol.h
+// Mocha
+//
+// Created by Logan Collins on 5/11/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+/*!
+ * @class MOBridgeSupportSymbol
+ * @abstract Abstract superclass of all symbols
+ */
+@interface MOBridgeSupportSymbol : NSObject
+
+@property (copy) NSString *name;
+
+@end
+
+
+/*!
+ * @class MOBridgeSupportStruct
+ * @abstract Describes a C struct
+ */
+@interface MOBridgeSupportStruct : MOBridgeSupportSymbol
+
+@property (copy) NSString *type;
+@property (copy) NSString *type64;
+
+@property (getter=isOpaque) BOOL opaque;
+
+@end
+
+
+/*!
+ * @class MOBridgeSupportCFType
+ * @abstract Describes a Core Foundation-based type
+ */
+@interface MOBridgeSupportCFType : MOBridgeSupportSymbol
+
+@property (copy) NSString *type;
+@property (copy) NSString *type64;
+
+@property (copy) NSString *tollFreeBridgedClassName;
+@property (copy) NSString *getTypeIDFunctionName;
+
+@end
+
+
+/*!
+ * @class MOBridgeSupportOpaque
+ * @abstract Describes an opaque type, most generally a C pointer to a C opaque structure
+ */
+@interface MOBridgeSupportOpaque : MOBridgeSupportSymbol
+
+@property (copy) NSString *type;
+@property (copy) NSString *type64;
+
+@property BOOL hasMagicCookie;
+
+@end
+
+
+/*!
+ * @class MOBridgeSupportConstant
+ * @abstract Describes a C constant
+ */
+@interface MOBridgeSupportConstant : MOBridgeSupportSymbol
+
+@property (copy) NSString *type;
+@property (copy) NSString *type64;
+
+@property BOOL hasMagicCookie;
+
+@end
+
+
+/*!
+ * @class MOBridgeSupportStringConstant
+ * @abstract Describes a string constant
+ */
+@interface MOBridgeSupportStringConstant : MOBridgeSupportSymbol
+
+@property (copy) NSString *value;
+
+@property BOOL hasNSString;
+
+@end
+
+
+/*!
+ * @class MOBridgeSupportEnum
+ * @abstract Describes a C enumeration
+ */
+@interface MOBridgeSupportEnum : MOBridgeSupportSymbol
+
+@property (copy) NSNumber *value;
+@property (copy) NSNumber *value64;
+
+@property (getter=isIgnored) BOOL ignored;
+@property (copy) NSString *suggestion;
+
+@end
+
+
+/*!
+ * @class MOBridgeSupportFunction
+ * @abstract Describes a C function
+ */
+@interface MOBridgeSupportFunction : MOBridgeSupportSymbol
+
+@property (getter=isVariadic) BOOL variadic;
+@property (copy) NSNumber *sentinel;
+@property (getter=isInlineFunction) BOOL inlineFunction;
+
+@end
+
+
+/*!
+ * @class MOBridgeSupportFunctionAlias
+ * @abstract Describes an alias or shortcut to a C function
+ */
+@interface MOBridgeSupportFunctionAlias : MOBridgeSupportSymbol
+
+@property (copy) NSString *original;
+
+@end
+
+
+@class MOBridgeSupportMethod;
+
+/*!
+ * @class MOBridgeSupportClass
+ * @abstract Describes an Objective-C class
+ */
+@interface MOBridgeSupportClass : MOBridgeSupportSymbol
+
+@property (copy) NSArray *methods;
+- (void)addMethod:(MOBridgeSupportMethod *)method;
+- (void)removeMethod:(MOBridgeSupportMethod *)method;
+
+@end
+
+
+/*!
+ * @class MOBridgeSupportInformalProtocol
+ * @abstract Describes an Objective-C informal protocol
+ */
+@interface MOBridgeSupportInformalProtocol : MOBridgeSupportSymbol
+
+@property (copy) NSArray *methods;
+- (void)addMethod:(MOBridgeSupportMethod *)method;
+- (void)removeMethod:(MOBridgeSupportMethod *)method;
+
+@end
+
+
+@class MOBridgeSupportArgument;
+
+/*!
+ * @class MOBridgeSupportMethod
+ * @abstract Describes an Objective-C method
+ */
+@interface MOBridgeSupportMethod : MOBridgeSupportSymbol
+
+@property SEL selector;
+
+@property (copy) NSString *type;
+@property (copy) NSString *type64;
+
+@property (copy) NSArray *arguments;
+- (void)addArgument:(MOBridgeSupportArgument *)argument;
+- (void)removeArgument:(MOBridgeSupportArgument *)argument;
+
+@property (strong) MOBridgeSupportArgument *returnValue;
+
+@property (getter=isClassMethod) BOOL classMethod;
+
+@property (getter=isVariadic) BOOL variadic;
+@property (copy) NSNumber *sentinel;
+
+@property (getter=isIgnored) BOOL ignored;
+@property (copy) NSString *suggestion;
+
+@end
+
+
+/*!
+ * @class MOBridgeSupportArgument
+ * @abstract Describes an argument or return value
+ */
+@interface MOBridgeSupportArgument : NSObject
+
+@property (copy) NSString *type;
+@property (copy) NSString *type64;
+
+@property (copy) NSString *typeModifier;
+
+@property (copy) NSString *signature;
+@property (copy) NSString *signature64;
+
+@property (copy) NSString *cArrayLengthInArg;
+@property (getter=isCArrayOfFixedLength) BOOL cArrayOfFixedLength;
+@property (getter=isCArrayDelimitedByNull) BOOL cArrayDelimitedByNull;
+@property (getter=isCArrayOfVariableLength) BOOL cArrayOfVariableLength;
+@property (getter=isCArrayLengthInReturnValue) BOOL cArrayLengthInReturnValue;
+
+@property NSUInteger index;
+
+@property BOOL acceptsNull;
+@property BOOL acceptsPrintfFormat;
+
+@property (getter=isAlreadyRetained) BOOL alreadyRetained;
+@property (getter=isFunctionPointer) BOOL functionPointer;
+
+@end
+
335 Mocha/BridgeSupport/MOBridgeSupportSymbol.m
@@ -0,0 +1,335 @@
+//
+// MOBridgeSupportSymbol.m
+// Mocha
+//
+// Created by Logan Collins on 5/11/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import "MOBridgeSupportSymbol.h"
+
+
+@implementation MOBridgeSupportSymbol
+
+@synthesize name=_name;
+
+- (void)dealloc {
+ [_name release];
+ [super dealloc];
+}
+
+@end
+
+
+@implementation MOBridgeSupportStruct
+
+@synthesize type=_type;
+@synthesize type64=_type64;
+@synthesize opaque=_opaque;
+
+- (void)dealloc {
+ [_type release];
+ [_type64 release];
+ [super dealloc];
+}
+
+@end
+
+
+@implementation MOBridgeSupportCFType
+
+@synthesize type=_type;
+@synthesize type64=_type64;
+
+@synthesize tollFreeBridgedClassName=_tollFreeBridgedClassName;
+@synthesize getTypeIDFunctionName=_getTypeIDFunctionName;
+
+- (void)dealloc {
+ [_type release];
+ [_type64 release];
+ [_tollFreeBridgedClassName release];
+ [_getTypeIDFunctionName release];
+ [super dealloc];
+}
+
+@end
+
+
+@implementation MOBridgeSupportOpaque
+
+@synthesize type=_type;
+@synthesize type64=_type64;
+
+@synthesize hasMagicCookie=_hasMagicCookie;
+
+- (void)dealloc {
+ [_type release];
+ [_type64 release];
+ [super dealloc];
+}
+
+@end
+
+
+@implementation MOBridgeSupportConstant
+
+@synthesize type=_type;
+@synthesize type64=_type64;
+
+@synthesize hasMagicCookie=_hasMagicCookie;
+
+- (void)dealloc {
+ [_type release];
+ [_type64 release];
+ [super dealloc];
+}
+
+@end
+
+
+@implementation MOBridgeSupportStringConstant
+
+@synthesize value=_value;
+@synthesize hasNSString=_hasNSString;
+
+- (void)dealloc {
+ [_value release];
+ [super dealloc];
+}
+
+@end
+
+
+@implementation MOBridgeSupportEnum
+
+@synthesize value=_value;
+@synthesize value64=_value64;
+
+@synthesize ignored=_ignored;
+@synthesize suggestion=_suggestion;
+
+- (void)dealloc {
+ [_value release];
+ [_value64 release];
+ [_suggestion release];
+ [super dealloc];
+}
+
+@end
+
+
+@implementation MOBridgeSupportFunction
+
+@synthesize variadic=_variadic;
+@synthesize sentinel=_sentinel;
+@synthesize inlineFunction=_inlineFunction;
+
+- (void)dealloc {
+ [_sentinel release];
+ [super dealloc];
+}
+
+@end
+
+
+@implementation MOBridgeSupportFunctionAlias
+
+@synthesize original=_original;
+
+- (void)dealloc {
+ [_original release];
+ [super dealloc];
+}
+
+@end
+
+
+@implementation MOBridgeSupportClass {
+ NSMutableArray *_methods;
+}
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ _methods = [[NSMutableArray alloc] init];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [_methods release];
+ [super dealloc];
+}
+
+
+#pragma mark -
+#pragma mark Methods
+
+- (NSArray *)methods {
+ return _methods;
+}
+
+- (void)setMethods:(NSArray *)methods {
+ [_methods setArray:methods];
+}
+
+- (void)addMethod:(MOBridgeSupportMethod *)method {
+ if (![_methods containsObject:method]) {
+ [_methods addObject:method];
+ }
+}
+
+- (void)removeMethod:(MOBridgeSupportMethod *)method {
+ if ([_methods containsObject:method]) {
+ [_methods removeObject:method];
+ }
+}
+
+@end
+
+
+@implementation MOBridgeSupportInformalProtocol {
+ NSMutableArray *_methods;
+}
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ _methods = [[NSMutableArray alloc] init];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [_methods release];
+ [super dealloc];
+}
+
+
+#pragma mark -
+#pragma mark Methods
+
+- (NSArray *)methods {
+ return _methods;
+}
+
+- (void)setMethods:(NSArray *)methods {
+ [_methods setArray:methods];
+}
+
+- (void)addMethod:(MOBridgeSupportMethod *)method {
+ if (![_methods containsObject:method]) {
+ [_methods addObject:method];
+ }
+}
+
+- (void)removeMethod:(MOBridgeSupportMethod *)method {
+ if ([_methods containsObject:method]) {
+ [_methods removeObject:method];
+ }
+}
+
+@end
+
+
+@implementation MOBridgeSupportMethod {
+ NSMutableArray *_arguments;
+}
+
+@synthesize selector=_selector;
+
+@synthesize type=_type;
+@synthesize type64=_type64;
+
+@synthesize returnValue=_returnValue;
+
+@synthesize classMethod=_classMethod;
+
+@synthesize variadic=_variadic;
+@synthesize sentinel=_sentinel;
+
+@synthesize ignored=_ignored;
+@synthesize suggestion=_suggestion;
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ _arguments = [[NSMutableArray alloc] init];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [_type release];
+ [_type64 release];
+ [_arguments release];
+ [_returnValue release];
+ [_sentinel release];
+ [_suggestion release];
+ [super dealloc];
+}
+
+
+#pragma mark -
+#pragma mark Arguments
+
+- (NSArray *)arguments {
+ return [[_arguments copy] autorelease];
+}
+
+- (void)setArguments:(NSArray *)arguments {
+ [_arguments setArray:arguments];
+}
+
+- (void)addArgument:(MOBridgeSupportArgument *)argument {
+ if (![_arguments containsObject:argument]) {
+ [_arguments addObject:argument];
+ }
+}
+
+- (void)removeArgument:(MOBridgeSupportArgument *)argument {
+ if ([_arguments containsObject:argument]) {
+ [_arguments removeObject:argument];
+ }
+}
+
+@end
+
+
+@implementation MOBridgeSupportArgument
+
+@synthesize type=_type;
+@synthesize type64=_type64;
+
+@synthesize typeModifier=_typeModifier;
+
+@synthesize signature=_signature;
+@synthesize signature64=_signature64;
+
+@synthesize cArrayLengthInArg=_cArrayLengthInArg;
+@synthesize cArrayOfFixedLength=_cArrayOfFixedLength;
+@synthesize cArrayDelimitedByNull=_cArrayDelimitedByNull;
+@synthesize cArrayOfVariableLength=_cArrayOfVariableLength;
+@synthesize cArrayLengthInReturnValue=_cArrayLengthInReturnValue;
+
+@synthesize index=_index;
+
+@synthesize acceptsNull=_acceptsNull;
+@synthesize acceptsPrintfFormat=_acceptsPrintfFormat;
+
+@synthesize alreadyRetained=_alreadyRetained;
+@synthesize functionPointer=_functionPointer;
+
+- (void)dealloc {
+ [_type release];
+ [_type64 release];
+ [_typeModifier release];
+ [_signature release];
+ [_signature64 release];
+ [_cArrayLengthInArg release];
+ [super dealloc];
+}
+
+@end
+
+
18 Mocha/Exceptions/MOException.h
@@ -0,0 +1,18 @@
+//
+// MOException.h
+// Mocha
+//
+// Created by Logan Collins on 5/11/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface MOException : NSObject
+
+@property (copy, readonly) NSString *error;
+@property (readonly) NSUInteger lineNumber;
+@property (copy, readonly) NSURL *sourceURL;
+
+@end
37 Mocha/Exceptions/MOException.m
@@ -0,0 +1,37 @@
+//
+// MOException.m
+// Mocha
+//
+// Created by Logan Collins on 5/11/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import "MOException.h"
+#import "MOException_Private.h"
+
+
+@implementation MOException
+
+@synthesize error=_error;
+@synthesize lineNumber=_lineNumber;
+@synthesize sourceURL=_sourceURL;
+
++ (MOException *)exceptionWithError:(NSString *)error lineNumber:(NSUInteger)lineNumber sourceURL:(NSURL *)sourceURL {
+ MOException *exception = [[self alloc] init];
+ exception.error = error;
+ exception.lineNumber = lineNumber;
+ exception.sourceURL = sourceURL;
+ return exception;
+}
+
+- (void)dealloc {
+ [_error release];
+ [_sourceURL release];
+ [super dealloc];
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@: %p : error=%@, lineNumber=%lu, sourceURL=%@>", [self class], self, self.error, self.lineNumber, self.sourceURL];
+}
+
+@end
21 Mocha/Exceptions/MOException_Private.h
@@ -0,0 +1,21 @@
+//
+// MOException_Private.h
+// Mocha
+//
+// Created by Logan Collins on 5/11/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import "MOException.h"
+#import <JavaScriptCore/JavaScriptCore.h>
+
+
+@interface MOException ()
+
++ (MOException *)exceptionWithError:(NSString *)error lineNumber:(NSUInteger)lineNumber sourceURL:(NSURL *)sourceURL;
+
+@property (copy, readwrite) NSString *error;
+@property (readwrite) NSUInteger lineNumber;
+@property (copy, readwrite) NSURL *sourceURL;
+
+@end
30 Mocha/Mocha-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>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.sunflowersw.${PRODUCT_NAME:rfc1034identifier}</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>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>NSHumanReadableCopyright</key>
+ <string>Copyright © 2012 Sunflower Softworks. All rights reserved.</string>
+ <key>NSPrincipalClass</key>
+ <string></string>
+</dict>
+</plist>
7 Mocha/Mocha-Prefix.pch
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'Mocha' target in the 'Mocha' project
+//
+
+#ifdef __OBJC__
+ #import <Cocoa/Cocoa.h>
+#endif
13 Mocha/Mocha.h
@@ -0,0 +1,13 @@
+//
+// Mocha.h
+// Mocha
+//
+// Created by Logan Collins on 5/10/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import <Mocha/MochaDefines.h>
+#import <Mocha/MochaRuntime.h>
+#import <Mocha/MOException.h>
+#import <Mocha/MOFunction.h>
+#import <Mocha/MOObject.h>
10 Mocha/Mocha.m
@@ -0,0 +1,10 @@
+//
+// Mocha.m
+// Mocha
+//
+// Created by Logan Collins on 5/10/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import "Mocha.h"
+
12 Mocha/MochaDefines.h
@@ -0,0 +1,12 @@
+//
+// MochaDefines.h
+// Mocha
+//
+// Created by Logan Collins on 5/10/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+
+#define MOCHA_EXTERN extern __attribute__((visibility("default")))
+#define MOCHA_STATIC_INLINE static inline __attribute__((visibility("default")))
+
70 Mocha/MochaRuntime.h
@@ -0,0 +1,70 @@
+//
+// MochaRuntime.h
+// Mocha
+//
+// Created by Logan Collins on 5/10/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <JavaScriptCore/JavaScriptCore.h>
+
+
+@class MOException;
+@protocol MochaDelegate;
+
+
+@interface Mocha : NSObject
+
++ (Mocha *)sharedRuntime;
+
+- (id)initWithGlobalContext:(JSGlobalContextRef)ctx;
+
+@property (readonly) JSGlobalContextRef context;
+@property (assign) id <MochaDelegate> delegate;
+
+// Evaluation
+- (id)evalString:(NSString *)string;
+
+// Frameworks
+- (id)callFunctionWithName:(NSString *)functionName;
+- (id)callFunctionWithName:(NSString *)functionName withArguments:(id)firstArg, ... NS_REQUIRES_NIL_TERMINATION;
+- (id)callFunctionWithName:(NSString *)functionName withArgumentsInArray:(NSArray *)arguments;
+
+// Syntax Validation
+- (BOOL)isSyntaxValidForString:(NSString *)string;
+
+// Frameworks
+- (BOOL)loadFrameworkWithName:(NSString *)frameworkName;
+- (BOOL)loadFrameworkWithName:(NSString *)frameworkName inDirectory:(NSString *)directory;
+
+// Garbage Collector
+- (void)garbageCollect;
+
+@end
+
+
+@protocol MochaDelegate <NSObject>
+
+@optional
+
+- (void)mochaRuntime:(Mocha *)aRuntime didEncounterUncaughtException:(MOException *)exception;
+
+@end
+
+
+@interface NSObject (MochaScripting)
+
++ (BOOL)isSelectorExcludedFromMochaScript:(SEL)aSelector;
+
+- (void)finalizeForMochaScript;
+
+// Indexed subscripts
+- (id)objectForIndexedSubscript:(NSUInteger)index;
+- (void)setObject:(id)object forIndexedSubscript:(NSUInteger)index;
+
+// Keyed subscripts
+- (id)objectForKeyedSubscript:(NSString *)key;
+- (void)setObject:(id)object forKeyedSubscript:(NSString *)key;
+
+@end
1,130 Mocha/MochaRuntime.m
@@ -0,0 +1,1130 @@
+//
+// MochaRuntime.m
+// Mocha
+//
+// Created by Logan Collins on 5/10/12.
+// Copyright (c) 2012 Sunflower Softworks. All rights reserved.
+//
+
+#import "MochaRuntime.h"
+#import "MochaRuntime_Private.h"
+
+#import "MOFunction_Private.h"
+#import "MOException_Private.h"
+#import "MOBridgeSupportObject.h"
+
+#import "MOBox.h"
+#import "MOUtilities.h"
+
+#import "MOBridgeSupportController.h"
+#import "MOBridgeSupportSymbol.h"
+
+#import "NSArray+MochaAdditions.h"
+#import "NSDictionary+MochaAdditions.h"
+
+#import <objc/runtime.h>
+#import <ffi/ffi.h>
+#import <dlfcn.h>
+
+
+// Class types
+static JSClassRef MochaClass = NULL;
+static JSClassRef MOObjectClass = NULL;
+static JSClassRef MOBoxedObjectClass = NULL;
+static JSClassRef MOFunctionClass = NULL;
+
+
+// Global object
+static JSValueRef Mocha_getProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception);
+
+// Private Cocoa object callbacks
+static void MOObject_initialize(JSContextRef ctx, JSObjectRef object);
+static void MOObject_finalize(JSObjectRef object);
+
+static bool MOBoxedObject_hasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
+static JSValueRef MOBoxedObject_getProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception);
+static bool MOBoxedObject_setProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef *exception);
+static bool MOBoxedObject_deleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception);
+static void MOBoxedObject_getPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
+static JSObjectRef MOBoxedObject_callAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentsCount, const JSValueRef arguments[], JSValueRef *exception);
+static JSValueRef MOBoxedObject_convertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef *exception);
+static bool MOBoxedObject_hasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef *exception);
+
+static JSValueRef MOFunction_callAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception);
+
+
+#pragma mark -
+#pragma mark Runtime
+
+
+@implementation Mocha {
+ JSGlobalContextRef _ctx;
+ BOOL _ownsContext;
+ NSMutableDictionary *_exportedObjects;
+}
+
+@synthesize delegate=_delegate;
+
++ (void)initialize {
+ if (self == [Mocha class]) {
+ // Mocha global object
+ JSClassDefinition MochaClassDefinition = kJSClassDefinitionEmpty;
+ MochaClassDefinition.className = "Mocha";
+ MochaClassDefinition.getProperty = Mocha_getProperty;
+ MochaClass = JSClassCreate(&MochaClassDefinition);
+
+ // Mocha object
+ JSClassDefinition MOObjectDefinition = kJSClassDefinitionEmpty;
+ MOObjectDefinition.className = "MOObject";
+ MOObjectDefinition.initialize = MOObject_initialize;
+ MOObjectDefinition.finalize = MOObject_finalize;
+ MOObjectClass = JSClassCreate(&MOObjectDefinition);
+
+ // Boxed Cocoa object
+ JSClassDefinition MOBoxedObjectDefinition = kJSClassDefinitionEmpty;
+ MOBoxedObjectDefinition.className = "MOBoxedObject";
+ MOBoxedObjectDefinition.parentClass = MOObjectClass;
+ MOBoxedObjectDefinition.initialize = MOObject_initialize;
+ MOBoxedObjectDefinition.finalize = MOObject_finalize;
+ MOBoxedObjectDefinition.hasProperty = MOBoxedObject_hasProperty;
+ MOBoxedObjectDefinition.getProperty = MOBoxedObject_getProperty;
+ MOBoxedObjectDefinition.setProperty = MOBoxedObject_setProperty;
+ MOBoxedObjectDefinition.deleteProperty = MOBoxedObject_deleteProperty;
+ MOBoxedObjectDefinition.getPropertyNames = MOBoxedObject_getPropertyNames;
+ MOBoxedObjectDefinition.callAsConstructor = MOBoxedObject_callAsConstructor;
+ MOBoxedObjectDefinition.hasInstance = MOBoxedObject_hasInstance;
+ MOBoxedObjectDefinition.convertToType = MOBoxedObject_convertToType;
+ MOBoxedObjectClass = JSClassCreate(&MOBoxedObjectDefinition);
+
+ // Function object
+ JSClassDefinition MOFunctionDefinition = kJSClassDefinitionEmpty;
+ MOFunctionDefinition.className = "MOFunction";
+ MOFunctionDefinition.parentClass = MOObjectClass;
+ MOFunctionDefinition.callAsFunction = MOFunction_callAsFunction;
+ MOFunctionClass = JSClassCreate(&MOFunctionDefinition);
+
+
+ // Swizzle indexed subscripting support for NSArray
+ SEL indexedSubscriptSelector = @selector(objectForIndexedSubscript:);
+ if (![NSArray instancesRespondToSelector:indexedSubscriptSelector]) {
+ IMP imp = class_getMethodImplementation([NSArray class], @selector(mo_objectForIndexedSubscript:));
+ class_addMethod([NSArray class], @selector(objectForIndexedSubscript:), imp, "@@:l");
+
+ imp = class_getMethodImplementation([NSMutableArray class], @selector(mo_setObject:forIndexedSubscript:));
+ class_addMethod([NSMutableArray class], @selector(setObject:forIndexedSubscript:), imp, "@@:@l");
+ }
+
+ // Swizzle keyed subscripting support for NSDictionary
+ SEL keyedSubscriptSelector = @selector(objectForKeyedSubscript:);
+ if (![NSDictionary instancesRespondToSelector:keyedSubscriptSelector]) {
+ IMP imp = class_getMethodImplementation([NSDictionary class], @selector(mo_objectForKeyedSubscript:));
+ class_addMethod([NSDictionary class], @selector(objectForKeyedSubscript:), imp, "@@:@");
+
+ imp = class_getMethodImplementation([NSMutableDictionary class], @selector(mo_setObject:forKeyedSubscript:));
+ class_addMethod([NSMutableDictionary class], @selector(setObject:forKeyedSubscript:), imp, "@@:@@");
+ }
+ }
+}
+
++ (Mocha *)sharedRuntime {
+ static Mocha *sharedRuntime = nil;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ sharedRuntime = [[self alloc] init];
+ });
+ return sharedRuntime;
+}
+
++ (Mocha *)runtimeWithContext:(JSContextRef)ctx {
+ JSStringRef jsName = JSStringCreateWithUTF8CString("__mocha__");
+ JSValueRef jsValue = JSObjectGetProperty(ctx, JSContextGetGlobalObject(ctx), jsName, NULL);
+ JSStringRelease(jsName);
+ return [self objectForJSValue:jsValue inContext:ctx];
+}
+
+- (id)init {
+ return [self initWithGlobalContext:NULL];
+}
+
+- (id)initWithGlobalContext:(JSGlobalContextRef)ctx {
+ if (ctx == NULL) {
+ ctx = JSGlobalContextCreate(MochaClass);
+ _ownsContext = YES;
+ }
+ else {
+ JSGlobalContextRetain(ctx);
+ _ownsContext = NO;
+
+ // Create the global "Mocha" object
+ JSObjectRef o = JSObjectMake(ctx, MochaClass, NULL);
+ JSStringRef jsName = JSStringCreateWithUTF8CString("Mocha");
+ JSObjectSetProperty(ctx, JSContextGetGlobalObject(ctx), jsName, o, kJSPropertyAttributeDontDelete, NULL);
+ JSStringRelease(jsName);
+ }
+
+ self = [super init];
+ if (self) {
+ _ctx = ctx;
+ _exportedObjects = [[NSMutableDictionary alloc] init];
+
+ [self setObject:self withName:@"__mocha__" attributes:(kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontEnum|kJSPropertyAttributeDontDelete)];
+
+ [self installBuiltins];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [self cleanUp];
+
+ JSGlobalContextRelease(_ctx);
+
+ [_exportedObjects release];
+
+ [super dealloc];
+}
+
+- (JSGlobalContextRef)context {
+ return _ctx;
+}
+
+
+#pragma mark -
+#pragma mark Key-Value Coding
+
+- (id)valueForUndefinedKey:(NSString *)key {
+ return [_exportedObjects objectForKey:key];
+}
+
+- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
+ [_exportedObjects setObject:value forKey:key];
+}
+
+
+#pragma mark -
+#pragma mark Object Conversion
+
+static NSString * const MOMochaRuntimeObjectBoxKey = @"MOMochaRuntimeObjectBoxKey";
+
++ (JSValueRef)JSValueForObject:(id)object inContext:(JSContextRef)ctx {
+ return [[Mocha runtimeWithContext:ctx] JSValueForObject:object];
+}
+
++ (id)objectForJSValue:(JSValueRef)value inContext:(JSContextRef)ctx {
+ return [self objectForJSValue:value inContext:ctx unboxObjects:YES];
+}
+
++ (id)objectForJSValue:(JSValueRef)value inContext:(JSContextRef)ctx unboxObjects:(BOOL)unboxObjects {
+ if (value == NULL || JSValueIsUndefined(ctx, value)) {
+ return nil;
+ }
+
+ if (JSValueIsNull(ctx, value)) {
+ return [NSNull null];
+ }
+
+ if (JSValueIsString(ctx, value)) {
+ JSStringRef resultStringJS = JSValueToStringCopy(ctx, value, NULL);
+ NSString *resultString = [(NSString *)JSStringCopyCFString(kCFAllocatorDefault, resultStringJS) autorelease];
+ JSStringRelease(resultStringJS);
+ return resultString;
+ }
+
+ if (JSValueIsNumber(ctx, value)) {
+ double v = JSValueToNumber(ctx, value, NULL);
+ return [NSNumber numberWithDouble:v];
+ }
+
+ if (JSValueIsBoolean(ctx, value)) {
+ bool v = JSValueToBoolean(ctx, value);
+ return [NSNumber numberWithBool:v];
+ }
+
+ if (!JSValueIsObject(ctx, value)) {
+ return nil;
+ }
+
+ JSObjectRef jsObject = JSValueToObject(ctx, value, NULL);
+ id private = JSObjectGetPrivate(jsObject);
+
+ if (private != nil) {
+ if ([private isKindOfClass:[MOBox class]]) {
+ if (unboxObjects == YES) {
+ // Boxed ObjC object
+ id object = [private representedObject];
+ return object;
+ }
+ else {
+ return private;
+ }
+ }
+ else {
+ return private;
+ }
+ }
+ else {
+ // Normal JS object
+ JSStringRef scriptJS = JSStringCreateWithUTF8CString("return arguments[0].constructor == Array.prototype.constructor");
+ JSObjectRef fn = JSObjectMakeFunction(ctx, NULL, 0, NULL, scriptJS, NULL, 1, NULL);
+ JSValueRef result = JSObjectCallAsFunction(ctx, fn, NULL, 1, (JSValueRef *)&jsObject, NULL);
+ JSStringRelease(scriptJS);
+
+ BOOL isArray = JSValueToBoolean(ctx, result);
+ if (isArray) {
+ // Array
+ return [self arrayForJSArray:jsObject inContext:ctx];
+ }
+ else {
+ // Object
+ return [self dictionaryForJSHash:jsObject inContext:ctx];
+ }
+ }
+
+ return nil;
+}
+
++ (NSArray *)arrayForJSArray:(JSObjectRef)arrayValue inContext:(JSContextRef)ctx {
+ JSValueRef exception = NULL;
+ JSStringRef lengthJS = JSStringCreateWithUTF8CString("length");
+ NSUInteger length = JSValueToNumber(ctx, JSObjectGetProperty(ctx, arrayValue, lengthJS, NULL), &exception);
+ JSStringRelease(lengthJS);
+
+ if (exception != NULL) {
+ return nil;
+ }
+
+ NSMutableArray *array = [NSMutableArray arrayWithCapacity:length];
+
+ for (NSUInteger i=0; i<length; i++) {
+ id obj = nil;
+ JSValueRef jsValue = JSObjectGetPropertyAtIndex(ctx, arrayValue, i, &exception);
+ if (exception != NULL) {
+ return nil;
+ }
+
+ obj = [self objectForJSValue:jsValue inContext:ctx unboxObjects:YES];
+ if (obj == nil) {
+ obj = [NSNull null];
+ }
+
+ [array addObject:obj];
+ }
+
+ return [[array copy] autorelease];
+}
+
++ (NSDictionary *)dictionaryForJSHash:(JSObjectRef)hashValue inContext:(JSContextRef)ctx {
+ JSPropertyNameArrayRef names = JSObjectCopyPropertyNames(ctx, hashValue);
+ NSUInteger length = JSPropertyNameArrayGetCount(names);
+
+ NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:length];
+ JSValueRef exception = NULL;
+
+ for (NSUInteger i=0; i<length; i++) {
+ id obj = nil;
+ JSStringRef name = JSPropertyNameArrayGetNameAtIndex(names, i);
+ JSValueRef jsValue = JSObjectGetProperty(ctx, hashValue, name, &exception);
+
+ if (exception != NULL) {
+ return NO;
+ }
+
+ obj = [self objectForJSValue:jsValue inContext:ctx unboxObjects:YES];
+ if (obj == nil) {
+ obj = [NSNull null];
+ }
+
+ NSString *key = [(NSString *)JSStringCopyCFString(kCFAllocatorDefault, name) autorelease];
+ [dictionary setObject:obj forKey:key];
+ }
+
+ JSPropertyNameArrayRelease(names);
+
+ return [[dictionary copy] autorelease];
+}
+
+- (JSValueRef)JSValueForObject:(id)object {
+ JSValueRef value = NULL;
+
+ if ([object isKindOfClass:[MOBox class]]) {
+ value = [object JSObject];
+ }
+ else if ([object isKindOfClass:[NSString class]]) {
+ JSStringRef string = JSStringCreateWithCFString((CFStringRef)object);
+ value = JSValueMakeString(_ctx, string);
+ JSStringRelease(string);
+ }
+ else if ([object isKindOfClass:[NSNumber class]]) {
+ double doubleValue = [object doubleValue];
+ value = JSValueMakeNumber(_ctx, doubleValue);
+ }
+ else if ([object isKindOfClass:[NSNull class]]) {
+ value = JSValueMakeNull(_ctx);
+ }
+ else if (object == nil) {
+ value = JSValueMakeUndefined(_ctx);
+ }
+
+ if (value == NULL) {
+ value = [self boxedJSObjectForObject:object];
+ }
+
+ return value;
+}
+
+- (id)objectForJSValue:(JSValueRef)value {
+ return [self objectForJSValue:value unboxObjects:YES];
+}
+
+- (id)objectForJSValue:(JSValueRef)value unboxObjects:(BOOL)unboxObjects {
+ return [Mocha objectForJSValue:value inContext:_ctx unboxObjects:unboxObjects];
+}
+
+- (JSObjectRef)boxedJSObjectForObject:(id)object {
+ if (object == nil) {
+ return NULL;
+ }
+
+ MOBox *box = objc_getAssociatedObject(object, MOMochaRuntimeObjectBoxKey);
+ if (box != nil) {
+ return [box JSObject];
+ }
+
+ box = [[[MOBox alloc] init] autorelease];
+ box.representedObject = object;
+ JSObjectRef jsObject = NULL;
+
+ if ([object isKindOfClass:[MOFunction class]]) {
+ jsObject = JSObjectMake(_ctx, MOFunctionClass, box);
+ }
+ else {
+ jsObject = JSObjectMake(_ctx, MOBoxedObjectClass, box);;
+ }
+
+ box.JSObject = jsObject;
+
+ objc_setAssociatedObject(object, MOMochaRuntimeObjectBoxKey, box, OBJC_ASSOCIATION_RETAIN);
+
+ return jsObject;
+}
+
+- (id)unboxedObjectForJSObject:(JSObjectRef)jsObject {
+ id private = JSObjectGetPrivate(jsObject);
+ if ([private isKindOfClass:[MOBox class]]) {
+ return [private representedObject];
+ }
+ return nil;
+}
+
+
+#pragma mark -
+#pragma mark Object Storage
+
+- (id)objectWithName:(NSString *)name {
+ JSValueRef exception = NULL;
+
+ JSStringRef jsName = JSStringCreateWithUTF8CString([name UTF8String]);
+ JSValueRef jsValue = JSObjectGetProperty(_ctx, JSContextGetGlobalObject(_ctx), jsName, &exception);
+ JSStringRelease(jsName);
+
+ if (exception != NULL) {
+ MOException *mochaException = [Mocha exceptionWithJSException:exception context:_ctx];
+ if ([[self delegate] respondsToSelector:@selector(mochaRuntime:didEncounterUncaughtException:)]) {
+ [[self delegate] mochaRuntime:self didEncounterUncaughtException:mochaException];
+ }
+ return NULL;
+ }
+
+ return [self objectForJSValue:jsValue];
+}
+
+- (JSValueRef)setObject:(id)object withName:(NSString *)name {
+ return [self setObject:object withName:name attributes:(kJSPropertyAttributeNone)];
+}
+
+- (JSValueRef)setObject:(id)object withName:(NSString *)name attributes:(JSPropertyAttributes)attributes {
+ JSValueRef jsValue = [self JSValueForObject:object];
+
+ // Set
+ JSValueRef exception = NULL;
+ JSStringRef jsName = JSStringCreateWithUTF8CString([name UTF8String]);
+ JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), jsName, jsValue, attributes, &exception);
+ JSStringRelease(jsName);
+
+ if (exception != NULL) {
+ MOException *mochaException = [Mocha exceptionWithJSException:exception context:_ctx];
+ if ([[self delegate] respondsToSelector:@selector(mochaRuntime:didEncounterUncaughtException:)]) {
+ [[self delegate] mochaRuntime:self didEncounterUncaughtException:mochaException];
+ }
+ return NULL;
+ }
+
+ return jsValue;
+}
+
+- (BOOL)removeObjectWithName:(NSString *)name {
+ JSValueRef exception = NULL;
+
+ // Delete
+ JSStringRef jsName = JSStringCreateWithUTF8CString([name UTF8String]);
+ JSObjectDeleteProperty(_ctx, JSContextGetGlobalObject(_ctx), jsName, &exception);
+ JSStringRelease(jsName);
+
+ if (exception != NULL) {
+ MOException *mochaException = [Mocha exceptionWithJSException:exception context:_ctx];
+ if ([[self delegate] respondsToSelector:@selector(mochaRuntime:didEncounterUncaughtException:)]) {
+ [[self delegate] mochaRuntime:self didEncounterUncaughtException:mochaException];
+ }
+ return NO;
+ }
+
+ return YES;
+}
+
+
+#pragma mark -
+#pragma mark Evaluation
+
+- (id)evalString:(NSString *)string {
+ JSValueRef jsValue = [self evalJSString:string];
+ return [self objectForJSValue:jsValue];
+}
+
+- (JSValueRef)evalJSString:(NSString *)string {
+ return [self evalJSString:string scriptPath:nil];
+}
+
+- (JSValueRef)evalJSString:(NSString *)string scriptPath:(NSString *)scriptPath {
+ if (string == nil) {
+ return NULL;
+ }
+