Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Random functions are now working.

  • Loading branch information...
commit dcd6ba31001bb49ca2d0c2c4509b2f75f50f2083 1 parent 7e1d22a
@ccgus authored
View
21 experimental/README.md
@@ -19,4 +19,23 @@ There's a ton of unfinished code laying around, and since I tend to be scatterbr
## Random Things for Gus to Fix:
Oct 23, 2011:
-Hey, mixing TDTokens and JSTPSymbolGroup(s) together in JSTPSymbolGroup's _args array is a really bad idea. What you need to do is make a common subclass for those two, so you don't have to keep on checking if you're working with a TDToken first in description.
+Hey, mixing TDTokens and JSTPSymbolGroup(s) together in JSTPSymbolGroup's _args array is a really bad idea. What you need to do is make a common subclass for those two, so you don't have to keep on checking if you're working with a TDToken first in description.
+
+
+
+## Random Test thigns:
+
+Make sure something like this is possible:
+
+for (idx in args) {
+ print("argument " + [args objectAtIndex:idx]);
+}
+
+var d = [NSMutableDictionary dictionary];
+
+d['a'] = 'eh';
+d['b'] = 'beee';
+
+for (var key in d) {
+ print(key + ": " + [d valueForKey:key]);
+}
View
6 experimental/experimental.xcodeproj/project.pbxproj
@@ -339,6 +339,7 @@
CC5FB7C70F1FDD0B00F4ECC2 /* jstalkmain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = jstalkmain.m; path = src/jstalkmain.m; sourceTree = "<group>"; };
CC5FB7D60F1FDDE900F4ECC2 /* JSTalk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSTalk.h; path = src/JSTalk.h; sourceTree = "<group>"; };
CC5FB7D70F1FDDE900F4ECC2 /* JSTalk.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JSTalk.m; path = src/JSTalk.m; sourceTree = "<group>"; };
+ CC64173A145D117500781EA6 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
CC7528F1124FE64D005546B0 /* JSTFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSTFunction.h; path = src/JSTFunction.h; sourceTree = "<group>"; };
CC7528F2124FE64D005546B0 /* JSTFunction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JSTFunction.m; path = src/JSTFunction.m; sourceTree = "<group>"; };
CC75296C1250066F005546B0 /* JSTTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSTTests.h; path = src/JSTTests.h; sourceTree = "<group>"; };
@@ -415,6 +416,7 @@
2A37F4AAFDCFA73011CA2CEA /* JSTalk */ = {
isa = PBXGroup;
children = (
+ CC64173A145D117500781EA6 /* README.md */,
CC0EC3380F2274730094F69D /* Framework */,
2A37F4AFFDCFA73011CA2CEA /* Other Sources */,
2A37F4B8FDCFA73011CA2CEA /* Resources */,
@@ -1006,12 +1008,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = src/JSTalk_Prefix.pch;
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
INSTALL_PATH = /usr/local/bin;
OTHER_CFLAGS = "-DDEBUG";
OTHER_LDFLAGS = (
@@ -1031,10 +1033,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- COPY_PHASE_STRIP = YES;
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = src/JSTalk_Prefix.pch;
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
INSTALL_PATH = /usr/local/bin;
OTHER_LDFLAGS = (
"-lexpat",
View
24 experimental/src/JSTBridge.m
@@ -184,6 +184,7 @@ - (JSObjectRef)makeJSObjectWithNSObject:(id*)bridgedObject runtimeInfo:(JSTRunti
- (JSObjectRef)makeBridgedFunctionWithRuntimeInfo:(JSTRuntimeInfo*)info name:(NSString*)functionName {
JSTFunction *function = [[JSTFunction alloc] initWithFunctionName:functionName bridge:self runtimeInfo:info];
+ JSTAssert(function);
objc_setAssociatedObject(function, &JSTRuntimeAssociatedInfoKey, info, OBJC_ASSOCIATION_ASSIGN);
return JSObjectMake(_jsContext, _bridgedFunctionClass, function);
}
@@ -267,17 +268,9 @@ - (void)propertyNamesForObject:(JSObjectRef)jsObject propertyNameAccumulator:(JS
id object = [self NSObjectForJSObject:jsObject];
if ([object isKindOfClass:[NSArray class]]) {
-#warning add this to the tests:
- /*
- for (idx in args) {
- print("argument " + [args objectAtIndex:idx]);
- }
-
- */
+
NSArray *ar = (id)object;
for (int i = 0; i < [ar count]; i++) {
-
-
JSStringRef jsString = JSStringCreateWithUTF8CString([[NSString stringWithFormat:@"%d", i] UTF8String]);
JSPropertyNameAccumulatorAddName(propertyNames, jsString);
JSStringRelease(jsString);
@@ -285,19 +278,6 @@ - (void)propertyNamesForObject:(JSObjectRef)jsObject propertyNameAccumulator:(JS
}
if ([object isKindOfClass:[NSDictionary class]]) {
-
-#warning add a test for this:
-/*
-var d = [NSMutableDictionary dictionary];
-
-d['a'] = 'eh';
-d['b'] = 'beee';
-
-for (var key in d) {
- print(key + ": " + [d valueForKey:key]);
-}
-*/
-
NSDictionary *d = (id)object;
for (id key in [d allKeys]) {
JSStringRef jsString = JSStringCreateWithUTF8CString([[key description] UTF8String]);
View
243 experimental/src/JSTFunction.m
@@ -53,11 +53,13 @@ - (id)initForJSTMsgSendWithBridge:(JSTBridge*)bridge {
- (id)initWithFunctionName:(NSString*)name bridge:(JSTBridge*)bridge runtimeInfo:(JSTRuntimeInfo*)runtimeInfo {
if ((self = [self init])) {
+
_callAddress = dlsym(RTLD_DEFAULT, [name UTF8String]);
if (!_callAddress) {
- debug(@"Can't find the function named '%@', returning nil", name);
+ debug(@"Can't find the function named '%@', returning nil. Is 'Symbols Hidden by Default' set to YES for the compile options?", name);
[self release];
+ JSTAssert(NO);
return nil;
}
@@ -471,158 +473,109 @@ -(ffi_type*)setupReturnType {
-(ffi_type*)setValue:(void**)argVals atIndex:(int)idx {
JSValueRef argument = _jsArguments[idx];
+ ffi_type *retType = 0x00;
+ const char *argType = 0x00;
+ BOOL freeArgType = NO;
if (_msgSendMethodRuntimeInfo || (_callAddress == &objc_msgSend)) {
-
- void **foo = [self _allocate:(sizeof(void*))];
-
- ffi_type *retType = 0x00;
-
- char *argType = method_copyArgumentType(_objcMethod, idx);
-
- JSTAssert(argType);
-
- debug(@"argType: %s at index %d", argType, idx);
-
- if (strcmp(argType, @encode(id)) == 0) {
- *foo = JSTNSObjectFromValue(_bridge, argument);
- argVals[idx] = foo;
- retType = &ffi_type_pointer;
- //debug(@"object at index %d: %@", idx, *foo);
- }
- else if (strcmp(argType, @encode(SEL)) == 0) {
-
- //debug(@"sel at index %d: %@", idx, NSStringFromSelector(JSTSelectorFromValue(_bridge, argument)));
-
- *foo = JSTSelectorFromValue(_bridge, argument);
-
- argVals[idx] = foo;
- retType = &ffi_type_pointer;
-
- }
- else if (strcmp(argType, @encode(BOOL)) == 0) {
- void **storage = [self _allocate:(sizeof(void*))];
- *storage = (void*)((uint32_t)JSTLongFromValue(_bridge, argument));
- argVals[idx] = storage;
- retType = &ffi_type_sint8; // is this right?
- }
- else if (strcmp(argType, @encode(int32_t)) == 0) {
- *foo = (void*)((int32_t)JSTLongFromValue(_bridge, argument));
- argVals[idx] = foo;
- retType = &ffi_type_sint32;
- }
- else if (strcmp(argType, @encode(uint32_t)) == 0) {
- void **storage = [self _allocate:(sizeof(void*))];
- *storage = (void*)((uint32_t)JSTLongFromValue(_bridge, argument));
- argVals[idx] = storage;
- retType = &ffi_type_uint32;
- }
- else if (strcmp(argType, @encode(int64_t)) == 0) {
- void **storage = [self _allocate:(sizeof(void*))];
- *storage = (void*)((int64_t)JSTLongFromValue(_bridge, argument));
- argVals[idx] = storage;
- retType = &ffi_type_sint64;
- }
- else if (strcmp(argType, @encode(uint64_t)) == 0) {
- void **storage = [self _allocate:(sizeof(void*))];
- *storage = (void*)((uint64_t)JSTLongFromValue(_bridge, argument));
- argVals[idx] = storage;
- retType = &ffi_type_uint64;
- }
- else if (strcmp(argType, @encode(float)) == 0) {
- float **floatStorage = [self _allocate:(sizeof(float*))];
- *(float*)floatStorage = (float)JSTDoubleFromValue(_bridge, argument);
- argVals[idx] = floatStorage;
- retType = &ffi_type_float;
- }
- else if (strcmp(argType, @encode(double)) == 0) {
- double **floatStorage = [self _allocate:(sizeof(double*))];
- *(double*)floatStorage = (double)JSTDoubleFromValue(_bridge, argument);
- argVals[idx] = floatStorage;
- retType = &ffi_type_double;
- }
- else if (strcmp(argType, @encode(long double)) == 0) {
- long double **floatStorage = [self _allocate:(sizeof(long double*))];
- *(long double*)floatStorage = JSTDoubleFromValue(_bridge, argument);
- //debug(@"*(long double*)floatStorage: %Lf", *(long double*)floatStorage);
- argVals[idx] = floatStorage;
- retType = &ffi_type_longdouble;
+ argType = method_copyArgumentType(_objcMethod, idx);
+ freeArgType = YES;
+ }
+ else if (_runtimeInfo) {
+ if ([_runtimeInfo isVariadic]) {
+ // everything is pointers here...
+ argType = @encode(id);
}
else {
- NSLog(@"Unknown argument type at index %d: '%s'", (idx - 2), argType);
+ JSTRuntimeInfo *ri = [[_runtimeInfo arguments] objectAtIndex:idx];
+ NSString *encoding = [ri typeEncoding];
+ argType = [encoding UTF8String];
}
-
- free(argType);
-
- return retType;
}
- /*
else {
-
- if (_runtimeInfo) {
- if ([_runtimeInfo isVariadic]) {
- // everything is pointers here...
- void **foo = [self _allocate:(sizeof(void*))];
-
- *foo = JSTNSObjectFromValue(_bridge, argument);
- argVals[idx] = foo;
- return &ffi_type_pointer;
- }
- else {
-
- #warning refactor this with the crap above.
-
- JSTRuntimeInfo *ri = [[_runtimeInfo arguments] objectAtIndex:idx];
-
- ffi_type *retType = JSTFFITypeForTypeEncoding([ri typeEncoding]);
-
- if (retType == &ffi_type_float) {
- float **floatStorage = [self _allocate:(sizeof(float*))];
- *(float*)floatStorage = (float)JSTDoubleFromValue(_bridge, argument);
- argVals[idx] = floatStorage;
- return retType;
- }
- else if (retType == &ffi_type_double) {
- double **floatStorage = [self _allocate:(sizeof(double*))];
- *(double*)floatStorage = (double)JSTDoubleFromValue(_bridge, argument);
- argVals[idx] = floatStorage;
- return retType;
- }
- else if (retType == &ffi_type_uint64) {
-
- uint32_t **storage = [self _allocate:(sizeof(uint32_t*))];
-
- *(uint32_t*)storage = (uint32_t)JSTDoubleFromValue(_bridge, argument);
- argVals[idx] = storage;
- return retType;
- }
- if (retType == &ffi_type_pointer) {
- void **foo = [self _allocate:(sizeof(void*))];
-
- *foo = JSTNSObjectFromValue(_bridge, argument);
- argVals[idx] = foo;
- return retType;
- }
- else {
-
- assert(false);
- }
-
-
- debug(@"typeEncoding: '%@'", [ri typeEncoding]);
-
-
- //*foo = [_bridge NSObjectForJSObject:(JSObjectRef)argument];
- //return ;
- }
- }
- else {
- JSTAssert(false);
- }
- }
- */
+ // what, no type for the arg?
+ JSTAssert(NO);
+ }
+
+ JSTAssert(argType);
+
+ debug(@"argType: %s at index %d", argType, idx);
+
+ if (strcmp(argType, @encode(id)) == 0) {
+ void **storage = [self _allocate:(sizeof(void*))];
+ *storage = JSTNSObjectFromValue(_bridge, argument);
+ argVals[idx] = storage;
+ retType = &ffi_type_pointer;
+ //debug(@"object at index %d: %@", idx, *foo);
+ }
+ else if (strcmp(argType, @encode(SEL)) == 0) {
+
+ //debug(@"sel at index %d: %@", idx, NSStringFromSelector(JSTSelectorFromValue(_bridge, argument)));
+ void **storage = [self _allocate:(sizeof(void*))];
+ *storage = JSTSelectorFromValue(_bridge, argument);
+
+ argVals[idx] = storage;
+ retType = &ffi_type_pointer;
+
+ }
+ else if (strcmp(argType, @encode(BOOL)) == 0) {
+ void **storage = [self _allocate:(sizeof(void*))];
+ *storage = (void*)((uint32_t)JSTLongFromValue(_bridge, argument));
+ argVals[idx] = storage;
+ retType = &ffi_type_sint8; // is this right?
+ }
+ else if (strcmp(argType, @encode(int32_t)) == 0) {
+ void **storage = [self _allocate:(sizeof(void*))];
+ *storage = (void*)((int32_t)JSTLongFromValue(_bridge, argument));
+ argVals[idx] = storage;
+ retType = &ffi_type_sint32;
+ }
+ else if (strcmp(argType, @encode(uint32_t)) == 0) {
+ void **storage = [self _allocate:(sizeof(void*))];
+ *storage = (void*)((uint32_t)JSTLongFromValue(_bridge, argument));
+ argVals[idx] = storage;
+ retType = &ffi_type_uint32;
+ }
+ else if (strcmp(argType, @encode(int64_t)) == 0) {
+ void **storage = [self _allocate:(sizeof(void*))];
+ *storage = (void*)((int64_t)JSTLongFromValue(_bridge, argument));
+ argVals[idx] = storage;
+ retType = &ffi_type_sint64;
+ }
+ else if (strcmp(argType, @encode(uint64_t)) == 0) {
+ void **storage = [self _allocate:(sizeof(void*))];
+ *storage = (void*)((uint64_t)JSTLongFromValue(_bridge, argument));
+ argVals[idx] = storage;
+ retType = &ffi_type_uint64;
+ }
+ else if (strcmp(argType, @encode(float)) == 0) {
+ float **floatStorage = [self _allocate:(sizeof(float*))];
+ *(float*)floatStorage = (float)JSTDoubleFromValue(_bridge, argument);
+ argVals[idx] = floatStorage;
+ retType = &ffi_type_float;
+ }
+ else if (strcmp(argType, @encode(double)) == 0) {
+ double **floatStorage = [self _allocate:(sizeof(double*))];
+ *(double*)floatStorage = (double)JSTDoubleFromValue(_bridge, argument);
+ argVals[idx] = floatStorage;
+ retType = &ffi_type_double;
+ }
+ else if (strcmp(argType, @encode(long double)) == 0) {
+ long double **floatStorage = [self _allocate:(sizeof(long double*))];
+ *(long double*)floatStorage = JSTDoubleFromValue(_bridge, argument);
+ //debug(@"*(long double*)floatStorage: %Lf", *(long double*)floatStorage);
+ argVals[idx] = floatStorage;
+ retType = &ffi_type_longdouble;
+ }
+ else {
+ NSLog(@"Unknown argument type at index %d: '%s'", (idx - 2), argType);
+ }
+
+ if (freeArgType) {
+ free((void*)argType);
+ }
- return 0x00;
+ return retType;
}
Please sign in to comment.
Something went wrong with that request. Please try again.