about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--020run.cc19
-rw-r--r--038scheduler.cc26
2 files changed, 39 insertions, 6 deletions
diff --git a/020run.cc b/020run.cc
index b280901e..78b51c44 100644
--- a/020run.cc
+++ b/020run.cc
@@ -154,10 +154,16 @@ transform_all();
 
 //: Step 2: load any .mu files provided at the commandline
 :(before "End Commandline Parsing")
-// Loading Commandline Files
 if (argc > 1) {
-  for (int i = 1; i < argc; ++i) {
-    load_permanently(argv[i]);
+  // skip argv[0]
+  argv++;
+  argc--;
+  // ignore argv past '--'; that's commandline args for 'main'
+  while (argc > 0) {
+    if (string(*argv) == "--") break;
+    load_permanently(*argv);
+    argv++;
+    argc--;
   }
   transform_all();
   if (Run_tests) Recipe.erase(Recipe_ordinal[string("main")]);
@@ -171,9 +177,14 @@ if (!Run_tests) {
 //?   Trace_file = "interactive";
 //?   START_TRACING_UNTIL_END_OF_SCOPE;
 //?   Trace_stream->collect_layers.insert("app");
+  run_main(argc, argv);
+  teardown();
+}
+
+:(code)
+void run_main(int argc, char* argv[]) {
   recipe_ordinal r = Recipe_ordinal[string("main")];
   if (r) run(r);
-  teardown();
 }
 
 :(code)
diff --git a/038scheduler.cc b/038scheduler.cc
index 5f329bc2..f6fc3a3c 100644
--- a/038scheduler.cc
+++ b/038scheduler.cc
@@ -47,7 +47,12 @@ Scheduling_interval = 500;
 Routines.clear();
 :(replace{} "void run(recipe_ordinal r)")
 void run(recipe_ordinal r) {
-  Routines.push_back(new routine(r));
+  run(new routine(r));
+}
+
+:(code)
+void run(routine* rr) {
+  Routines.push_back(rr);
   Current_routine_index = 0, Current_routine = Routines.at(0);
   while (!all_routines_done()) {
     skip_to_next_routine();
@@ -65,7 +70,6 @@ void run(recipe_ordinal r) {
   }
 }
 
-:(code)
 bool all_routines_done() {
   for (long long int i = 0; i < SIZE(Routines); ++i) {
     if (Routines.at(i)->state == RUNNING) {
@@ -103,6 +107,24 @@ for (long long int i = 0; i < SIZE(Routines); ++i)
   delete Routines.at(i);
 Routines.clear();
 
+//: special case for the very first routine
+:(replace{} "void run_main(int argc, char* argv[])")
+void run_main(int argc, char* argv[]) {
+  recipe_ordinal r = Recipe_ordinal[string("main")];
+  if (r) {
+    // pass in commandline args as ingredients to main
+    // todo: test this
+    routine* rr = new routine(r);
+    Current_routine = rr;
+    for (long long int i = 1; i < argc; ++i) {
+      vector<double> arg;
+      arg.push_back(new_mu_string(argv[i]));
+      Current_routine->calls.front().ingredient_atoms.push_back(arg);
+    }
+    run(rr);
+  }
+}
+
 //:: To schedule new routines to run, call 'start-running'.
 
 //: 'start-running' will return a unique id for the routine that was created.