Skip to content

Commit

Permalink
some additions for importing code
Browse files Browse the repository at this point in the history
  • Loading branch information
stevedekorte committed Aug 26, 2011
1 parent 11e1e74 commit 7f4b7a8
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 34 deletions.
8 changes: 5 additions & 3 deletions addons/Blowfish/source/IoBlowfish.c
Expand Up @@ -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");
Expand All @@ -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[] = {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions addons/Blowfish/tests/correctness/BlowfishTest.io
Expand Up @@ -8,8 +8,6 @@ Sequence asChars := method(
*/

BlowfishTest := UnitTest clone do(
type := "BlowfishTest"

testBasic := method(
s := "This is a test."

Expand Down
5 changes: 3 additions & 2 deletions addons/ObjcBridge/CMakeLists.txt
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
40 changes: 18 additions & 22 deletions 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 -----------------------------------

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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]"
Expand All @@ -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)
)

Expand Down
3 changes: 3 additions & 0 deletions addons/ObjcBridge/source/IoLanguage.m
Expand Up @@ -51,6 +51,7 @@ + (id)shared
return shared;
}

void IoBlowfishInit(IoObject *context);
void IoSocketInit(IoObject *context);
void IoSystemCallInit(IoObject *context);
void IoBoxInit(IoObject *context);
Expand All @@ -59,6 +60,7 @@ + (id)shared

void IoLanguageStateBindingsInitCallback(void *context, void *state)
{
IoBlowfishInit(state);
IoSocketInit(state);
IoSystemCallInit(state);
IoBoxInit(state);
Expand Down Expand Up @@ -171,6 +173,7 @@ void ILanguageoStateActiveCoroCallback(void *context, int r)
[self runIoResource:@"Vector"];
[self runIoResource:@"ObjcBridge"];
[self runIoResource:@"SystemCall"];
[self runIoResource:@"Blowfish"];
return self;
}

Expand Down
53 changes: 53 additions & 0 deletions extras/IoLanguageKit/IoLanguageKit.xcodeproj/project.pbxproj
Expand Up @@ -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 */
Expand Down Expand Up @@ -556,6 +562,12 @@
AABB98B113DD7A3B00B6A0CB /* IoBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IoBox.h; sourceTree = "<group>"; };
AABB98B213DD7A3B00B6A0CB /* IoBoxApi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IoBoxApi.h; sourceTree = "<group>"; };
AABB98B313DD7A3B00B6A0CB /* IoBoxInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = IoBoxInit.c; sourceTree = "<group>"; };
AAC988891401CF510028A0A9 /* Blowfish.io */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Blowfish.io; sourceTree = "<group>"; };
AAC9888C1401CF510028A0A9 /* blowfish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = blowfish.c; sourceTree = "<group>"; };
AAC9888D1401CF510028A0A9 /* blowfish.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = blowfish.h; sourceTree = "<group>"; };
AAC9888E1401CF510028A0A9 /* IoBlowfish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = IoBlowfish.c; sourceTree = "<group>"; };
AAC9888F1401CF510028A0A9 /* IoBlowfish.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IoBlowfish.h; sourceTree = "<group>"; };
AAC988901401CF510028A0A9 /* IoBlowfishInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = IoBlowfishInit.c; sourceTree = "<group>"; };
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; };
Expand Down Expand Up @@ -681,6 +693,7 @@
AABB93B313DD09B800B6A0CB /* libs */ = {
isa = PBXGroup;
children = (
AAC988781401CF510028A0A9 /* Blowfish */,
AA3A0B4C13F9D1B400FB76A0 /* Socket */,
AA3A0B1B13F9C8DA00FB76A0 /* SystemCall */,
AABB989C13DD7A3B00B6A0CB /* Box */,
Expand Down Expand Up @@ -1031,6 +1044,36 @@
path = source;
sourceTree = "<group>";
};
AAC988781401CF510028A0A9 /* Blowfish */ = {
isa = PBXGroup;
children = (
AAC988881401CF510028A0A9 /* io */,
AAC9888B1401CF510028A0A9 /* source */,
);
name = Blowfish;
path = ../addons/Blowfish;
sourceTree = "<group>";
};
AAC988881401CF510028A0A9 /* io */ = {
isa = PBXGroup;
children = (
AAC988891401CF510028A0A9 /* Blowfish.io */,
);
path = io;
sourceTree = "<group>";
};
AAC9888B1401CF510028A0A9 /* source */ = {
isa = PBXGroup;
children = (
AAC9888C1401CF510028A0A9 /* blowfish.c */,
AAC9888D1401CF510028A0A9 /* blowfish.h */,
AAC9888E1401CF510028A0A9 /* IoBlowfish.c */,
AAC9888F1401CF510028A0A9 /* IoBlowfish.h */,
AAC988901401CF510028A0A9 /* IoBlowfishInit.c */,
);
path = source;
sourceTree = "<group>";
};
AAFE00E013D6526E00649838 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
55 changes: 50 additions & 5 deletions libs/iovm/io/Z_Importer.io
Expand Up @@ -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"
Expand Down

0 comments on commit 7f4b7a8

Please sign in to comment.