Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

vacation time, so I work on JSTalk a tiny bit of course

  • Loading branch information...
commit e93e4062e6c504041d4494dfa6d16ea4bb39f353 1 parent 9b53f39
@ccgus authored
View
12 experimental/README.txt
@@ -1,3 +1,13 @@
This is Gus's rewrite of the js bridge. It's probably a bad idea, and very broken.
-This is not being done on a branch because Gus started doing that and kept on screwing things up oh lordy do I hate git.
+This is not being done on a branch because Gus started doing that and kept on screwing things up oh lordy do I hate git.
+
+
+Notes from Gus, for Gus:
+
+Oct 2, 2011:
+The current plan for the new parser is to preprocess jstalk/objc messages into jstobjc_msgSend, since that's reasonably unique and we can special case things in there for calls that return floats or structs or whatever. So '[NSString string]' would become 'jstobjc_msgSend(NSString, "string")', '[Foo isEqualTo:"foo"]' objc_msgSend(Foo, "isEqualToString:", "foo")
+
+What's the best way to setup tests for this though? I want them written in JSTalk itself, but that gets a bit tricky. So currently that's what I'm working on exploring.
+
+There's a ton of unfinished code laying around, and since I tend to be scatterbrained it should probably be ignored. It'll be rewritten, as this is currently a playground for my ideas.
View
2  experimental/src/JSTBridgeSupportLoader.m
@@ -212,8 +212,6 @@ - (BOOL)loadFrameworkAtPath:(NSString*)frameworkPath {
- (BOOL)loadBridgeSupportAtPath:(NSString*)path {
- debug(@"path: '%@'", path);
-
NSXMLParser *parser = [[[NSXMLParser alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path]] autorelease];
if (!parser) {
View
2  experimental/src/JSTPreprocessor.m
@@ -337,7 +337,7 @@ - (NSString*)description {
[msgSendArgs removeAllObjects];
}
- NSMutableString *buf = [NSMutableString stringWithString:@"objc_msgSend("];
+ NSMutableString *buf = [NSMutableString stringWithString:@"jst_msgSend("];
[buf appendFormat:@"%@, \"%@\"", target, selector];
View
98 experimental/src/jstalkmain.m
@@ -1,7 +1,7 @@
#import <Cocoa/Cocoa.h>
#import "JSTListener.h"
#import "JSTalk.h"
-
+#import "JSTPreprocessor.h"
@interface JSCErrorHandler : NSObject {
@@ -86,6 +86,84 @@ void runREPL(void) {
}
+void testPreprocess(NSString *shouldLookLike, NSString *processMe) {
+
+}
+
+void testScriptAtPath(NSString *pathToScript) {
+
+
+ NSString *s = [NSString stringWithContentsOfFile:pathToScript encoding:NSUTF8StringEncoding error:nil];
+
+ JSTalk *t = [[[JSTalk alloc] init] autorelease];
+
+ [[t env] setObject:[NSURL fileURLWithPath:pathToScript] forKey:@"scriptURL"];
+ [[t env] setObject:[[NSURL fileURLWithPath:pathToScript] URLByDeletingLastPathComponent] forKey:@"scriptDirectoryURL"];
+
+ [t executeString:s];
+
+ exit(0);
+}
+
+void testPreprocessAtPath(NSString *pathToScript) {
+ NSLog(@"Testing %@", pathToScript);
+
+ NSString *bp = [[pathToScript stringByDeletingPathExtension] stringByAppendingPathExtension:@"jstpc"];
+ NSString *a = [NSString stringWithContentsOfFile:pathToScript encoding:NSUTF8StringEncoding error:nil];
+ NSString *b = [NSString stringWithContentsOfFile:bp encoding:NSUTF8StringEncoding error:nil];
+
+ NSString *r = [JSTPreprocessor preprocessCode:a];
+
+ b = [b stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ r = [r stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+
+ if (![b isEqualToString:r]) {
+ NSLog(@"Bad preprocess for %@", pathToScript);
+ [[r dataUsingEncoding:NSUTF8StringEncoding] writeToFile:@"/private/tmp/jstb.jstalk" atomically:YES];
+ NSString *cmd = [NSString stringWithFormat:@"/usr/bin/diff %@ /private/tmp/jstb.jstalk", bp];
+ NSLog(@"%@", cmd);
+ system([cmd UTF8String]);
+ }
+}
+
+int testFolder(NSString *folder) {
+
+ NSFileManager *fm = [NSFileManager defaultManager];
+
+ BOOL isDir;
+ if (!([fm fileExistsAtPath:folder isDirectory:&isDir] && isDir)) {
+ printf("The test path given does not exist or is not a folder\n");
+ return 1;
+ }
+
+ NSError *err = 0x00;
+ NSArray *ar = [fm subpathsOfDirectoryAtPath:folder error:&err];
+ if (!ar) {
+ NSLog(@"Error loading %@: %@", folder, err);
+ return 1;
+ }
+
+
+ for (NSString *sd in ar) {
+
+ if (![[sd pathExtension] isEqualToString:@"jstalk"]) {
+ continue;
+ }
+
+ else if ([sd hasPrefix:@"testPreprocess"]) {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ testPreprocessAtPath([folder stringByAppendingPathComponent:sd]);
+ [pool release];
+ }
+ else if ([sd hasPrefix:@"test"]) {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ testScriptAtPath([folder stringByAppendingPathComponent:sd]);
+ [pool release];
+ }
+ }
+
+ return 0;
+}
int main(int argc, char *argv[]) {
@@ -94,17 +172,25 @@ int main(int argc, char *argv[]) {
return 1;
}
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *arg = [NSString stringWithUTF8String:argv[1]];
if ([arg isEqualToString:@"-e"]) {
-
runREPL();
-
exit(0);
}
+ if ([arg isEqualToString:@"-t"]) {
+ if (argc < 3) {
+ printf("-t requires a path to a test folder\n");
+ return 1;
+ }
+
+ NSString *arg2 = [NSString stringWithUTF8String:argv[2]];
+
+ exit(testFolder(arg2));
+ }
NSString *s = [NSString stringWithContentsOfFile:arg encoding:NSUTF8StringEncoding error:nil];
@@ -117,8 +203,8 @@ int main(int argc, char *argv[]) {
//JSCocoaController *jsController = [t jsController];
//jsController.delegate = eh;
- [t.env setObject:[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]] forKey:@"scriptURL"];
- [t.env setObject:[[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]] URLByDeletingLastPathComponent] forKey:@"scriptDirectoryURL"];
+ [[t env] setObject:[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]] forKey:@"scriptURL"];
+ [[t env] setObject:[[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]] URLByDeletingLastPathComponent] forKey:@"scriptDirectoryURL"];
if ([s hasPrefix:@"#!"]) {
View
9 experimental/tests/preprocess/testPreprocess01.jstalk
@@ -0,0 +1,9 @@
+print([4 - 5, b]);
+print([a, b]);
+[NSString string];
+
+[NSFullUserName() lowercaseString];
+
+print([NSString stringWithString:@"a"+"b"])
+
+[fo doSomething:" a " + [b fun] + " c " in:nil];
View
9 experimental/tests/preprocess/testPreprocess01.jstpc
@@ -0,0 +1,9 @@
+print([4 - 5, b]);
+print([a, b]);
+jst_msgSend(NSString, "string");
+
+jst_msgSend(NSFullUserName(), "lowercaseString");
+
+print(jst_msgSend(NSString, "stringWithString:", JSTNSString("a")+"b"))
+
+jst_msgSend(fo, "doSomething:in:", " a "+jst_msgSend(b, "fun")+" c ", null);
View
3  experimental/tests/preprocess/testPreprocess02.jstalk
@@ -0,0 +1,3 @@
+print([4 - 5, b]);
+print([a, b]);
+[NSString string];
View
3  experimental/tests/preprocess/testPreprocess02.jstpc
@@ -0,0 +1,3 @@
+print([4 - 5, b]);
+print([a, b]);
+jst_msgSend(NSString, "string");
Please sign in to comment.
Something went wrong with that request. Please try again.