Permalink
Browse files

Support :static-fns

Fixes #155
  • Loading branch information...
mfikes committed Nov 3, 2015
1 parent 46cab3a commit 16627fdb468e8c2ad91f2b938227fcdca3bcc653
@@ -37,6 +37,7 @@ Usage: planck [init-opt*] [main-opt] [args]
-k, --cache path Cache analysis/compilation artifacts in specified path
-v, --verbose Emit verbose diagnostic output
-d, --dumb-terminal Disables line editing / VT100 terminal control
-s, --static-fns Generate static dispatch function calls
main options:
-m, --main ns-name Call the -main function from a namespace with args
@@ -60,8 +60,10 @@
(defonce app-env (atom nil))
(defn ^:export init-app-env
[verbose cache-path]
(reset! planck.repl/app-env {:verbose verbose :cache-path cache-path}))
[verbose cache-path static-fns]
(reset! planck.repl/app-env {:verbose verbose
:cache-path cache-path
:static-fns static-fns}))
(defn repl-read-string
[line]
@@ -117,9 +119,10 @@
(defn- make-base-eval-opts
[]
{:ns @current-ns
:context :expr
:verbose (:verbose @app-env)})
{:ns @current-ns
:context :expr
:verbose (:verbose @app-env)
:static-fns (:static-fns @app-env)})
(defn- process-in-ns
[argument]
@@ -699,7 +702,8 @@
(merge
{:ns @current-ns
:source-map false
:verbose (:verbose @app-env)}
:verbose (:verbose @app-env)
:static-fns (:static-fns @app-env)}
(if expression?
{:context :expr
:def-emits-var true}
@@ -7,7 +7,7 @@
@interface PLKClojureScriptEngine : NSObject
-(void)startInitializationWithSrcPaths:(NSArray*)srcPaths outPath:(NSString*)outPath cachePath:(NSString*)cachePath verbose:(BOOL)verbose boundArgs:(NSArray*)boundArgs planckVersion:(NSString*)planckVersion;
-(void)startInitializationWithSrcPaths:(NSArray*)srcPaths outPath:(NSString*)outPath cachePath:(NSString*)cachePath verbose:(BOOL)verbose staticFns:(BOOL)staticFns boundArgs:(NSArray*)boundArgs planckVersion:(NSString*)planckVersion;
-(int)executeSourceType:(NSString*)sourceType value:(NSString*)sourceValue expression:(BOOL)expression printNilExpression:(BOOL)printNilExpression inExitContext:(BOOL)inExitContext;
-(int)runMainInNs:(NSString*)mainNsName args:(NSArray*)args;
-(BOOL)isReadable:(NSString*)expression;
@@ -174,7 +174,7 @@ -(NSDate*)getModificationDateForFile:(NSString*)path
return fileModificationDate;
}
-(void)startInitializationWithSrcPaths:(NSArray*)srcPaths outPath:(NSString*)outPath cachePath:(NSString*)cachePath verbose:(BOOL)verbose boundArgs:(NSArray*)boundArgs planckVersion:(NSString*)planckVersion
-(void)startInitializationWithSrcPaths:(NSArray*)srcPaths outPath:(NSString*)outPath cachePath:(NSString*)cachePath verbose:(BOOL)verbose staticFns:(BOOL)staticFns boundArgs:(NSArray*)boundArgs planckVersion:(NSString*)planckVersion
{
// By default we expect :none, but this can be set if :simple
@@ -397,11 +397,12 @@ -(void)startInitializationWithSrcPaths:(NSArray*)srcPaths outPath:(NSString*)out
}
{
JSValueRef arguments[2];
JSValueRef arguments[3];
JSValueRef result;
int num_arguments = 2;
int num_arguments = 3;
arguments[0] = JSValueMakeBoolean(self.context, verbose);
arguments[1] = JSValueMakeStringFromNSString(self.context, cachePath);
arguments[2] = JSValueMakeBoolean(self.context, staticFns);
result = JSObjectCallAsFunction(self.context, [self getFunction:@"init-app-env"], JSContextGetGlobalObject(self.context), num_arguments, arguments, NULL);
}
View
@@ -25,7 +25,7 @@ +(int)processArgsCount:(int)argc vector:(char * const *)argv
return YES;
}
// opt is a short opt or clump of short opts. If the clump ends with i, e, m, s, c, or k then this opt
// opt is a short opt or clump of short opts. If the clump ends with i, e, m, c, or k then this opt
// takes an argument.
int idx = 0;
char c = 0;
@@ -35,7 +35,7 @@ +(int)processArgsCount:(int)argc vector:(char * const *)argv
idx++;
}
return (BOOL)(last_c == 'i' || last_c =='e' || last_c == 'm' || last_c =='s' || last_c =='c' || last_c =='k');
return (BOOL)(last_c == 'i' || last_c =='e' || last_c == 'm' || last_c =='c' || last_c =='k');
};
// A bare hyphen or a script path not preceded by -[iems] are the two types of mainopt not detected
@@ -68,6 +68,7 @@ +(int)processArgsCount:(int)argc vector:(char * const *)argv
BOOL repl = NO;
BOOL verbose = NO;
BOOL dumbTerminal = NO;
BOOL staticFns = NO;
// Undocumented options, used for development.
// The defaults set here are for release use.
@@ -82,21 +83,21 @@ +(int)processArgsCount:(int)argc vector:(char * const *)argv
{"legal", no_argument, NULL, 'l'},
{"init", optional_argument, NULL, 'i'},
{"eval", optional_argument, NULL, 'e'},
{"src", optional_argument, NULL, 's'},
{"classpath", optional_argument, NULL, 'c'},
{"cache", optional_argument, NULL, 'k'},
{"verbose", optional_argument, NULL, 'v'},
{"dumb-terminal", optional_argument, NULL, 'd'},
{"main", optional_argument, NULL, 'm'},
{"repl", optional_argument, NULL, 'r'},
{"static-fns", optional_argument, NULL, 's'},
// Undocumented options used for development
{"out", optional_argument, NULL, 'o'},
{0, 0, 0, 0}
};
const char *shortopts = "h?li:e:s:c:vdm:ro:k:";
const char *shortopts = "h?li:e:c:vdsm:ro:k:";
BOOL didEncounterMainOpt = NO;
// pass indexOfScriptPathOrHyphen instead of argc to guarantee that everything after a bare dash "-" or a script path gets earmuffed
while (!didEncounterMainOpt && ((option = getopt_long(indexOfScriptPathOrHyphen, argv, shortopts, longopts, NULL)) != -1)) {
@@ -128,12 +129,6 @@ +(int)processArgsCount:(int)argc vector:(char * const *)argv
[scripts addObject:[[PLKScript alloc] initWithExpression:[NSString stringWithCString:optarg encoding:NSMacOSRomanStringEncoding]]];
break;
}
case 's':
{
fprintf(stderr, "The -s / --src option is deprecated. Use -c / --classpath instead.\n" );
[srcPaths addObject:@[@"src", [NSString stringWithCString:optarg encoding:NSMacOSRomanStringEncoding]]];
break;
}
case 'c':
{
NSString* classpath = [NSString stringWithCString:optarg encoding:NSMacOSRomanStringEncoding];
@@ -180,6 +175,11 @@ +(int)processArgsCount:(int)argc vector:(char * const *)argv
cachePath = [NSString stringWithCString:optarg encoding:NSMacOSRomanStringEncoding];
break;
}
case 's':
{
staticFns = YES;
break;
}
}
}
@@ -223,6 +223,7 @@ +(int)processArgsCount:(int)argc vector:(char * const *)argv
printf(" -k, --cache path Cache analysis/compilation artifacts in specified path\n");
printf(" -v, --verbose Emit verbose diagnostic output\n");
printf(" -d, --dumb-terminal Disables line editing / VT100 terminal control\n");
printf(" -s, --static-fns Generate static dispatch function calls\n");
printf("\n");
printf(" main options:\n");
printf(" -m, --main ns-name Call the -main function from a namespace with args\n");
@@ -256,6 +257,7 @@ +(int)processArgsCount:(int)argc vector:(char * const *)argv
outPath:outPath
cachePath:cachePath
dumbTerminal:dumbTerminal
staticFns:staticFns
args:args
planckVersion:[NSString stringWithCString:PLANCK_VERSION
encoding:NSUTF8StringEncoding]];
View
@@ -10,6 +10,7 @@
outPath:(NSString*)outPath
cachePath:(NSString*)cachePath
dumbTerminal:(BOOL)dumbTerminal
staticFns:(BOOL)staticFns
args:(NSArray*)args
planckVersion:(NSString*)planckVersion;
View
@@ -20,6 +20,7 @@ -(int)runScripts:(NSArray*)scripts
outPath:(NSString*)outPath
cachePath:(NSString*)cachePath
dumbTerminal:(BOOL)dumbTerminal
staticFns:(BOOL)staticFns
args:(NSArray*)args
planckVersion:(NSString*)planckVersion {
@@ -30,7 +31,7 @@ -(int)runScripts:(NSArray*)scripts
// the first arg will be treated as a path to a file to be executed and should not be bound
boundArgs = [args subarrayWithRange:NSMakeRange(1, args.count - 1)];
}
[self setupClojureScriptEngineWithSrcPaths:srcPaths outPath:outPath cachePath:cachePath verbose:verbose boundArgs:boundArgs planckVersion:planckVersion];
[self setupClojureScriptEngineWithSrcPaths:srcPaths outPath:outPath cachePath:cachePath verbose:verbose staticFns:staticFns boundArgs:boundArgs planckVersion:planckVersion];
// Process init arguments
@@ -64,7 +65,7 @@ -(int)runScripts:(NSArray*)scripts
return exitValue;
}
-(void)setupClojureScriptEngineWithSrcPaths:(NSArray*)srcPaths outPath:(NSString*)outPath cachePath:(NSString*)cachePath verbose:(BOOL)verbose boundArgs:(NSArray*)boundArgs planckVersion:(NSString*)planckVersion
-(void)setupClojureScriptEngineWithSrcPaths:(NSArray*)srcPaths outPath:(NSString*)outPath cachePath:(NSString*)cachePath verbose:(BOOL)verbose staticFns:(BOOL)staticFns boundArgs:(NSArray*)boundArgs planckVersion:(NSString*)planckVersion
{
NSMutableArray* adjustedSrcPaths = [[NSMutableArray alloc] init];
for (NSArray* srcPath in srcPaths) {
@@ -99,7 +100,7 @@ -(void)setupClojureScriptEngineWithSrcPaths:(NSArray*)srcPaths outPath:(NSString
outPath = [self ensureTrailingSlash:[self fullyQualify:outPath]];
self.clojureScriptEngine = [[PLKClojureScriptEngine alloc] init];
[self.clojureScriptEngine startInitializationWithSrcPaths:adjustedSrcPaths outPath:outPath cachePath:cachePath verbose:verbose boundArgs:boundArgs planckVersion:planckVersion];
[self.clojureScriptEngine startInitializationWithSrcPaths:adjustedSrcPaths outPath:outPath cachePath:cachePath verbose:verbose staticFns:staticFns boundArgs:boundArgs planckVersion:planckVersion];
}
-(NSString*)ensureTrailingSlash:(NSString*)s

0 comments on commit 16627fd

Please sign in to comment.