Permalink
Browse files

Allow main function to be specified

  • Loading branch information...
mwilliamson committed Aug 11, 2012
1 parent 0e03a34 commit 68eea5367a4cf453e87191e614c60a02f2967937
Showing with 16 additions and 2 deletions.
  1. +16 −2 lib/compilation.shed
View
@@ -9,23 +9,37 @@ import files;
import promises;
import strings;
import lists;
+import sequenceables;
import lop.strings.createStringSource;
import shed.compiler.moduleCompilation;
def main fun(argv: List[String]) => do {
+ val pathRoots = argv.filter(fun(arg: String) => not(arg.substring(0, 2).equals("--")));
+
val shedFilePaths = files.finder()
.filesOnly()
- .roots(argv)
+ .roots(pathRoots)
.filterFiles().hasExtension("shed")
.find();
val shedParts = shedFilePaths.bind(compileShedFiles).map(joinJavaScriptUnits);
val runtime = compileRuntime();
val programParts = promises.combineList(listOf(runtime, shedParts));
- programParts.map(joinJavaScriptUnits).map(print);
+ val mainFunction = sequenceables.head(
+ argv.filter(fun(arg: String) => arg.substring(0, 7).equals("--main="))
+ .map(fun(arg: String) => arg.sliceFrom(7))
+ );
+
+ programParts.map(joinJavaScriptUnits).map(fun(program: String) => do {
+ print(program);
+ mainFunction.map(fun(mainFunction: String) => do {
+ print("\n\n$shed.js.import(\"".concat(mainFunction).concat("\")"));
+ print("($shed.lists.createFromArray(process.argv.slice(2).map($shed.string)));");
+ });
+ });
}
def compileString fun(input: String) => do {

0 comments on commit 68eea53

Please sign in to comment.