From 7f4b7a8e455a42940aa21d6ce4ba1bcb1b504869 Mon Sep 17 00:00:00 2001 From: Steve Dekorte Date: Thu, 25 Aug 2011 19:58:58 -0700 Subject: [PATCH] some additions for importing code --- addons/Blowfish/source/IoBlowfish.c | 8 ++- .../tests/correctness/BlowfishTest.io | 2 - addons/ObjcBridge/CMakeLists.txt | 5 +- addons/ObjcBridge/io/ObjcBridge.io | 40 ++++++-------- addons/ObjcBridge/source/IoLanguage.m | 3 + .../IoLanguageKit.xcodeproj/project.pbxproj | 53 ++++++++++++++++++ libs/iovm/io/Z_Importer.io | 55 +++++++++++++++++-- 7 files changed, 132 insertions(+), 34 deletions(-) diff --git a/addons/Blowfish/source/IoBlowfish.c b/addons/Blowfish/source/IoBlowfish.c index f8d7c2c51..b6d8e299c 100644 --- a/addons/Blowfish/source/IoBlowfish.c +++ b/addons/Blowfish/source/IoBlowfish.c @@ -52,6 +52,8 @@ decryptedData := cipher outputBuffer #define DATA(self) ((IoBlowfishData *)(IoObject_dataPointer(self))) +static const char *protoId = "Blowfish"; + IoTag *IoBlowfish_newTag(void *state) { IoTag *tag = IoTag_newWithName_("Blowfish"); @@ -68,7 +70,7 @@ IoBlowfish *IoBlowfish_proto(void *state) IoObject_setDataPointer_(self, calloc(1, sizeof(IoBlowfishData))); - IoState_registerProtoWithFunc_(state, self, IoBlowfish_proto); + IoState_registerProtoWithFunc_(state, self, protoId); { IoMethodTable methodTable[] = { @@ -93,7 +95,7 @@ IoBlowfish *IoBlowfish_rawClone(IoBlowfish *proto) IoBlowfish *IoBlowfish_new(void *state) { - IoObject *proto = IoState_protoWithInitFunction_(state, IoBlowfish_proto); + IoObject *proto = IoState_protoWithInitFunction_(state, protoId); return IOCLONE(proto); } @@ -125,7 +127,7 @@ IoObject *IoBlowfish_beginProcessing(IoObject *self, IoObject *locals, IoMessage UArray *key = IoObject_rawGetUArraySlot(self, locals, m, IOSYMBOL("key")); blowfish_ctx *context = &(DATA(self)->context); - blowfish_init(context, (uint8_t *)UArray_bytes(key), UArray_sizeInBytes(key)); + blowfish_init(context, (uint8_t *)UArray_bytes(key), (int)UArray_sizeInBytes(key)); return self; } diff --git a/addons/Blowfish/tests/correctness/BlowfishTest.io b/addons/Blowfish/tests/correctness/BlowfishTest.io index a99ac7f74..e0d54db10 100644 --- a/addons/Blowfish/tests/correctness/BlowfishTest.io +++ b/addons/Blowfish/tests/correctness/BlowfishTest.io @@ -8,8 +8,6 @@ Sequence asChars := method( */ BlowfishTest := UnitTest clone do( - type := "BlowfishTest" - testBasic := method( s := "This is a test." diff --git a/addons/ObjcBridge/CMakeLists.txt b/addons/ObjcBridge/CMakeLists.txt index 135e04661..99deebcea 100644 --- a/addons/ObjcBridge/CMakeLists.txt +++ b/addons/ObjcBridge/CMakeLists.txt @@ -20,6 +20,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../Box/source ${CMAKE_CURRENT_SOURCE_DIR}/../Socket/source ${CMAKE_CURRENT_SOURCE_DIR}/../SystemCall/source + ${CMAKE_CURRENT_SOURCE_DIR}/../Blowfish/source ) # Our library sources. @@ -37,8 +38,8 @@ set(CMAKE_EXE_LINKER_FLAGS "-framework AppKit") # Now build the shared library add_library(IoObjcBridge SHARED ${SRCS}) -add_dependencies(IoObjcBridge iovmall Foundation IoBox IoSocket IoSystemCall) -target_link_libraries(IoObjcBridge iovmall ${ObjcBridge_LIBRARY} IoBox IoSocket IoSystemCall /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit) +add_dependencies(IoObjcBridge iovmall Foundation IoBox IoSocket IoBlowfish IoSystemCall) +target_link_libraries(IoObjcBridge iovmall ${ObjcBridge_LIBRARY} IoBox IoSocket IoBlowfish IoSystemCall /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit) # Install the addon to our global addons hierarchy. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION lib/io/addons) diff --git a/addons/ObjcBridge/io/ObjcBridge.io b/addons/ObjcBridge/io/ObjcBridge.io index 8edd7d277..511aae7f2 100644 --- a/addons/ObjcBridge/io/ObjcBridge.io +++ b/addons/ObjcBridge/io/ObjcBridge.io @@ -1,7 +1,7 @@ NSMakePoint := method(x, y, Point clone set(x, y)) -NSMakeSize := method(w, h, Point clone set(w, h)) -NSMakeRect := method(x, y, w, h, Box clone set(NSMakePoint(x, y), NSMakeSize(w, h))) +NSMakeSize := method(w, h, Point clone set(w, h)) +NSMakeRect := method(x, y, w, h, Box clone set(NSMakePoint(x, y), NSMakeSize(w, h))) // AddressBook ----------------------------------- @@ -15,11 +15,11 @@ if(Addon platform != "darwin", ABSearchElement := method(ObjcBridge classNamed("ADSearchElement")) ) -NSImageFrameNone := 0 -NSImageFramePhoto := 1 +NSImageFrameNone := 0 +NSImageFramePhoto := 1 NSImageFrameGrayBezel := 2 -NSImageFrameGroove := 3 -NSImageFrameButton := 4 +NSImageFrameGroove := 3 +NSImageFrameButton := 4 NSNoBorder := 0 NSLineBorder := 1 @@ -42,13 +42,13 @@ NSBoxSeparator := 2 NSBoxOldStyle := 3 NSBoxCustom := 4 -NSNoTitle := 0 -NSAboveTop := 1 -NSAtTop := 2 -NSBelowTop := 3 -NSAboveBottom := 4 -NSAtBottom := 5 -NSBelowBottom := 6 +NSNoTitle := 0 +NSAboveTop := 1 +NSAtTop := 2 +NSBelowTop := 3 +NSAboveBottom := 4 +NSAtBottom := 5 +NSBelowBottom := 6 //NSToolbarDisplayMode NSToolbarDisplayModeDefault := 0 @@ -70,20 +70,15 @@ NSNaturalTextAlignment := 4 YES := 1 NO := 0 -NSTaskTerminationReasonExit := 1 +NSTaskTerminationReasonExit := 1 NSTaskTerminationReasonUncaughtSignal := 2 +NSTaskDidTerminateNotification := "NSTaskDidTerminateNotification" NSFileHandleNotificationFileHandleItem := "NSFileHandleNotificationFileHandleItem" -NSFileHandleNotificationDataItem := "NSFileHandleNotificationDataItem" -NSFileHandleOperationException := "NSFileHandleOperationException" +NSFileHandleNotificationDataItem := "NSFileHandleNotificationDataItem" +NSFileHandleOperationException := "NSFileHandleOperationException" NSFileHandleReadCompletionNotification := "NSFileHandleReadCompletionNotification" -NSTaskDidTerminateNotification := "NSTaskDidTerminateNotification" -NSTaskTerminationReasonExit := 1 -NSTaskTerminationReasonUncaughtSignal := 2 - - - // --------------------------------- Object io2ObjcType := "[NOT an Io2Objc object]" @@ -94,6 +89,7 @@ Lobby forward := method( m := call message name v := ObjcBridge classNamed(m) if(v, return v) + //writeln("bridge importing ", m) Importer import(call) ) diff --git a/addons/ObjcBridge/source/IoLanguage.m b/addons/ObjcBridge/source/IoLanguage.m index 8f89506f1..74c47e196 100644 --- a/addons/ObjcBridge/source/IoLanguage.m +++ b/addons/ObjcBridge/source/IoLanguage.m @@ -51,6 +51,7 @@ + (id)shared return shared; } +void IoBlowfishInit(IoObject *context); void IoSocketInit(IoObject *context); void IoSystemCallInit(IoObject *context); void IoBoxInit(IoObject *context); @@ -59,6 +60,7 @@ + (id)shared void IoLanguageStateBindingsInitCallback(void *context, void *state) { + IoBlowfishInit(state); IoSocketInit(state); IoSystemCallInit(state); IoBoxInit(state); @@ -171,6 +173,7 @@ void ILanguageoStateActiveCoroCallback(void *context, int r) [self runIoResource:@"Vector"]; [self runIoResource:@"ObjcBridge"]; [self runIoResource:@"SystemCall"]; + [self runIoResource:@"Blowfish"]; return self; } diff --git a/extras/IoLanguageKit/IoLanguageKit.xcodeproj/project.pbxproj b/extras/IoLanguageKit/IoLanguageKit.xcodeproj/project.pbxproj index 0a87289c1..98b13fdf2 100644 --- a/extras/IoLanguageKit/IoLanguageKit.xcodeproj/project.pbxproj +++ b/extras/IoLanguageKit/IoLanguageKit.xcodeproj/project.pbxproj @@ -273,6 +273,12 @@ AABB98CC13DD7A3C00B6A0CB /* IoBox.h in Headers */ = {isa = PBXBuildFile; fileRef = AABB98B113DD7A3B00B6A0CB /* IoBox.h */; settings = {ATTRIBUTES = (Public, ); }; }; AABB98CD13DD7A3C00B6A0CB /* IoBoxApi.h in Headers */ = {isa = PBXBuildFile; fileRef = AABB98B213DD7A3B00B6A0CB /* IoBoxApi.h */; settings = {ATTRIBUTES = (Public, ); }; }; AABB98CE13DD7A3C00B6A0CB /* IoBoxInit.c in Sources */ = {isa = PBXBuildFile; fileRef = AABB98B313DD7A3B00B6A0CB /* IoBoxInit.c */; }; + AAC9889E1401CF520028A0A9 /* Blowfish.io in Resources */ = {isa = PBXBuildFile; fileRef = AAC988891401CF510028A0A9 /* Blowfish.io */; }; + AAC988A01401CF520028A0A9 /* blowfish.c in Sources */ = {isa = PBXBuildFile; fileRef = AAC9888C1401CF510028A0A9 /* blowfish.c */; }; + AAC988A11401CF520028A0A9 /* blowfish.h in Headers */ = {isa = PBXBuildFile; fileRef = AAC9888D1401CF510028A0A9 /* blowfish.h */; }; + AAC988A21401CF520028A0A9 /* IoBlowfish.c in Sources */ = {isa = PBXBuildFile; fileRef = AAC9888E1401CF510028A0A9 /* IoBlowfish.c */; }; + AAC988A31401CF520028A0A9 /* IoBlowfish.h in Headers */ = {isa = PBXBuildFile; fileRef = AAC9888F1401CF510028A0A9 /* IoBlowfish.h */; }; + AAC988A41401CF520028A0A9 /* IoBlowfishInit.c in Sources */ = {isa = PBXBuildFile; fileRef = AAC988901401CF510028A0A9 /* IoBlowfishInit.c */; }; AAFE00F013D6526E00649838 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AAFE00EF13D6526E00649838 /* Cocoa.framework */; }; AAFE00FA13D6526E00649838 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = AAFE00F813D6526E00649838 /* InfoPlist.strings */; }; /* End PBXBuildFile section */ @@ -556,6 +562,12 @@ AABB98B113DD7A3B00B6A0CB /* IoBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IoBox.h; sourceTree = ""; }; AABB98B213DD7A3B00B6A0CB /* IoBoxApi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IoBoxApi.h; sourceTree = ""; }; AABB98B313DD7A3B00B6A0CB /* IoBoxInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = IoBoxInit.c; sourceTree = ""; }; + AAC988891401CF510028A0A9 /* Blowfish.io */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Blowfish.io; sourceTree = ""; }; + AAC9888C1401CF510028A0A9 /* blowfish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = blowfish.c; sourceTree = ""; }; + AAC9888D1401CF510028A0A9 /* blowfish.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = blowfish.h; sourceTree = ""; }; + AAC9888E1401CF510028A0A9 /* IoBlowfish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = IoBlowfish.c; sourceTree = ""; }; + AAC9888F1401CF510028A0A9 /* IoBlowfish.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IoBlowfish.h; sourceTree = ""; }; + AAC988901401CF510028A0A9 /* IoBlowfishInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = IoBlowfishInit.c; sourceTree = ""; }; AAFE00EC13D6526E00649838 /* IoLanguageKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = IoLanguageKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; AAFE00EF13D6526E00649838 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; AAFE00F213D6526E00649838 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; @@ -681,6 +693,7 @@ AABB93B313DD09B800B6A0CB /* libs */ = { isa = PBXGroup; children = ( + AAC988781401CF510028A0A9 /* Blowfish */, AA3A0B4C13F9D1B400FB76A0 /* Socket */, AA3A0B1B13F9C8DA00FB76A0 /* SystemCall */, AABB989C13DD7A3B00B6A0CB /* Box */, @@ -1031,6 +1044,36 @@ path = source; sourceTree = ""; }; + AAC988781401CF510028A0A9 /* Blowfish */ = { + isa = PBXGroup; + children = ( + AAC988881401CF510028A0A9 /* io */, + AAC9888B1401CF510028A0A9 /* source */, + ); + name = Blowfish; + path = ../addons/Blowfish; + sourceTree = ""; + }; + AAC988881401CF510028A0A9 /* io */ = { + isa = PBXGroup; + children = ( + AAC988891401CF510028A0A9 /* Blowfish.io */, + ); + path = io; + sourceTree = ""; + }; + AAC9888B1401CF510028A0A9 /* source */ = { + isa = PBXGroup; + children = ( + AAC9888C1401CF510028A0A9 /* blowfish.c */, + AAC9888D1401CF510028A0A9 /* blowfish.h */, + AAC9888E1401CF510028A0A9 /* IoBlowfish.c */, + AAC9888F1401CF510028A0A9 /* IoBlowfish.h */, + AAC988901401CF510028A0A9 /* IoBlowfishInit.c */, + ); + path = source; + sourceTree = ""; + }; AAFE00E013D6526E00649838 = { isa = PBXGroup; children = ( @@ -1232,6 +1275,8 @@ AA3A0C2013F9D1B400FB76A0 /* LocalNameServers.h in Headers */, AA3A0C2613F9D1B400FB76A0 /* Socket.h in Headers */, AA3A0C2813F9D1B400FB76A0 /* UnixPath.h in Headers */, + AAC988A11401CF520028A0A9 /* blowfish.h in Headers */, + AAC988A31401CF520028A0A9 /* IoBlowfish.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1306,6 +1351,7 @@ AA3A0BEB13F9D1B400FB76A0 /* IPAddress.io in Resources */, AA3A0BEC13F9D1B400FB76A0 /* UnixPath.io in Resources */, AA3A0BED13F9D1B400FB76A0 /* URL.io in Resources */, + AAC9889E1401CF520028A0A9 /* Blowfish.io in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1427,6 +1473,9 @@ AA3A0C1F13F9D1B400FB76A0 /* LocalNameServers.c in Sources */, AA3A0C2513F9D1B400FB76A0 /* Socket.c in Sources */, AA3A0C2713F9D1B400FB76A0 /* UnixPath.c in Sources */, + AAC988A01401CF520028A0A9 /* blowfish.c in Sources */, + AAC988A21401CF520028A0A9 /* IoBlowfish.c in Sources */, + AAC988A41401CF520028A0A9 /* IoBlowfishInit.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1502,6 +1551,8 @@ "\"$(SRCROOT)/../../addons/SystemCall/_build/lib\"", "\"$(SRCROOT)/../../addons/Socket/_build/dll\"", "\"$(SRCROOT)/../../addons/Socket/_build/lib\"", + "\"$(SRCROOT)/../../addons/Blowfish/_build/dll\"", + "\"$(SRCROOT)/../../addons/Blowfish/_build/lib\"", ); PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = framework; @@ -1532,6 +1583,8 @@ "\"$(SRCROOT)/../../addons/SystemCall/_build/lib\"", "\"$(SRCROOT)/../../addons/Socket/_build/dll\"", "\"$(SRCROOT)/../../addons/Socket/_build/lib\"", + "\"$(SRCROOT)/../../addons/Blowfish/_build/dll\"", + "\"$(SRCROOT)/../../addons/Blowfish/_build/lib\"", ); PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = framework; diff --git a/libs/iovm/io/Z_Importer.io b/libs/iovm/io/Z_Importer.io index f3f9c3bbd..3326d1e06 100644 --- a/libs/iovm/io/Z_Importer.io +++ b/libs/iovm/io/Z_Importer.io @@ -31,17 +31,62 @@ Importer := Object clone do( ) ) directories foreach(folder, - path := Path with(folder, protoName .. ".io") asSymbol + if(tryToImportProtoFromFolder(protoName, folder), return true) + ) + false + ) + + + //doc FileImporter ioFileSuffixes A list of valid io source file suffixes. + ioFileSuffixes ::= list("io", "ioe") + + //doc FileImporter tryToImportProtoFromFolder(protoName, path) Looks for the protoName with the valid ioFileSuffixes and calls importPath if found. + tryToImportProtoFromFolder := method(protoName, folder, + ioFileSuffixes foreach(suffix, + path := Path with(folder, protoName .. "." .. suffix) asSymbol + //writeln("looking for ", path) if(File with(path) exists, - //writeln("importing: ", path) - Lobby doFile(path) - return true + return importPath(path) ) ) false ) + + key := "deafultKey" + + //doc FileImporter importPath(path) Performs Lobby doFile(path). Can override to deal with other formats. + importPath := method(path, + //writeln("importing: ", path) + if(path endsWithSeq("ioe"), + Lobby doString(decryptSourceFile(path), path) + didLoadPath(path) + return true + ) + Lobby doFile(path) + didLoadPath(path) + return true + ) + + decryptSourceFile := method(path, + //writeln("decrypting " .. path) + return Blowfish clone setKey(key) decrypt(File with(path) contents) + ) + + encryptSourceFile := method(path, + //writeln("encrypting " .. path) + es := Blowfish clone setKey(key) encrypt(File with(path) contents) + File with(path beforeSeq(".io") .. ".ioe") setContents(es) + ) + + didLoadPath := method(path, + //writeln("FileImporter didLoadPath ", path) + //encryptSourceFile(path) + //File with(path) remove + nil + ) ) - + + //doc Importer FolderImporter An Importer for objects laid out as folders with files as methods. FolderImporter := Object clone do( importsFrom := "folder"