From 4690ce81e079fc58cae8d6d583e5e3eb3ed81a83 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 9 Mar 2016 02:56:27 -0800 Subject: 2743 Looks like "TOhtml | " doesn't work on Mac OS X for some reason.. --- html/091run_interactive.cc.html | 230 +++++++++++++++++++--------------------- 1 file changed, 111 insertions(+), 119 deletions(-) (limited to 'html/091run_interactive.cc.html') diff --git a/html/091run_interactive.cc.html b/html/091run_interactive.cc.html index 444f50af..915cb510 100644 --- a/html/091run_interactive.cc.html +++ b/html/091run_interactive.cc.html @@ -3,48 +3,41 @@ Mu - 091run_interactive.cc - - + + - - + - - -
+
 //: Helper for various programming environments: run arbitrary mu code and
 //: return some result in string form.
 
 :(scenario run_interactive_code)
-recipe main [
+def main [
   1:number/raw <- copy 0
-  2:address:shared:array:character <- new [1:number/raw <- copy 34]
+  2:address:shared:array:character <- new [1:number/raw <- copy 34]
   run-interactive 2:address:shared:array:character
   3:number/raw <- copy 1:number/raw
 ]
 +mem: storing 34 in location 3
 
 :(scenario run_interactive_empty)
-recipe main [
+def main [
   1:address:shared:array:character <- copy 0/unsafe
   2:address:shared:array:character <- run-interactive 1:address:shared:array:character
 ]
@@ -61,21 +54,21 @@ RUN_INTERACTIVE,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "run-interactive", RUN_INTERACTIVE);
 :(before "End Primitive Recipe Checks")
-case RUN_INTERACTIVE: {
-  if (SIZE(inst.ingredients) != 1) {
-    raise_error << maybe(get(Recipe, r).name) << "'run-interactive' requires exactly one ingredient, but got " << to_string(inst) << '\n' << end();
+case RUN_INTERACTIVE: {
+  if (SIZE(inst.ingredients) != 1) {
+    raise << maybe(get(Recipe, r).name) << "'run-interactive' requires exactly one ingredient, but got " << to_string(inst) << '\n' << end();
     break;
   }
-  if (!is_mu_string(inst.ingredients.at(0))) {
-    raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'run-interactive' should be a string, but got " << to_string(inst.ingredients.at(0)) << '\n' << end();
+  if (!is_mu_string(inst.ingredients.at(0))) {
+    raise << maybe(get(Recipe, r).name) << "first ingredient of 'run-interactive' should be a string, but got " << to_string(inst.ingredients.at(0)) << '\n' << end();
     break;
   }
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case RUN_INTERACTIVE: {
-  bool new_code_pushed_to_stack = run_interactive(ingredients.at(0).at(0));
-  if (!new_code_pushed_to_stack) {
+case RUN_INTERACTIVE: {
+  bool new_code_pushed_to_stack = run_interactive(ingredients.at(0).at(0));
+  if (!new_code_pushed_to_stack) {
     products.resize(5);
     products.at(0).push_back(0);
     products.at(1).push_back(trace_error_contents());
@@ -85,13 +78,13 @@ case RUN_INTERACTIVE: {
     run_code_end();
     break;  // done with this instruction
   }
-  else {
+  else {
     continue;  // not done with caller; don't increment current_step_index()
   }
 }
 
 :(before "End Globals")
-bool Track_most_recent_products = false;
+bool Track_most_recent_products = false;
 :(before "End Tracing")
 trace_stream* Save_trace_stream = NULL;
 string Save_trace_file;
@@ -103,16 +96,16 @@ Track_most_recent_products = false// reads a string, tries to call it as code (treating it as a test), saving
 // all errors.
 // returns true if successfully called (no errors found during load and transform)
-bool run_interactive(long long int address) {
+bool run_interactive(long long int address) {
   assert(contains_key(Recipe_ordinal, "interactive") && get(Recipe_ordinal, "interactive") != 0);
   // try to sandbox the run as best you can
   // todo: test this
-  if (!Current_scenario) {
-    for (long long int i = 1; i < Reserved_for_tests; ++i)
+  if (!Current_scenario) {
+    for (long long int i = 1; i < Reserved_for_tests; ++i)
       Memory.erase(i);
   }
   string command = trim(strip_comments(read_mu_string(address)));
-  if (command.empty()) return false;
+  if (command.empty()) return false;
   Name[get(Recipe_ordinal, "interactive")].clear();
   run_code_begin(/*snapshot_recently_added_recipes*/true);
   // don't kill the current routine on parse errors
@@ -125,14 +118,14 @@ bool run_interactive(long long int address"$start-tracking-products\n" +
           command + "\n" +
           "$stop-tracking-products\n" +
-          "reply screen\n" +
+          "return screen\n" +
        "]\n");
   transform_all();
   Current_routine = save_current_routine;
-  if (trace_count("error") > 0) return false;
+  if (trace_count("error") > 0) return false;
   // now call 'sandbox' which will run 'interactive' in a separate routine,
   // and wait for it
-  if (Save_trace_stream) {
+  if (Save_trace_stream) {
     ++Save_trace_stream->callstack_depth;
     trace(9999, "trace") << "run-interactive: incrementing callstack depth to " << Save_trace_stream->callstack_depth << end();
     assert(Save_trace_stream->callstack_depth < 9000);  // 9998-101 plus cushion
@@ -141,11 +134,11 @@ bool run_interactive(long long int addressreturn true;
 }
 
-void run_code_begin(bool snapshot_recently_added_recipes) {
+void run_code_begin(bool snapshot_recently_added_recipes) {
   // stuff to undo later, in run_code_end()
   Hide_errors = true;
   Disable_redefine_checks = true;
-  if (snapshot_recently_added_recipes) {
+  if (snapshot_recently_added_recipes) {
     Save_recently_added_recipes = Recently_added_recipes;
     Recently_added_recipes.clear();
     Save_recently_added_shape_shifting_recipes = Recently_added_shape_shifting_recipes;
@@ -154,20 +147,20 @@ void run_code_begin(bool snapshot_recently_added_
   Save_trace_stream = Trace_stream;
   Save_trace_file = Trace_file;
   Trace_file = "";
-  Trace_stream = new trace_stream;
+  Trace_stream = new trace_stream;
   Trace_stream->collect_depth = App_depth;
 }
 
-void run_code_end() {
+void run_code_end() {
   Hide_errors = false;
   Disable_redefine_checks = false;
-  delete Trace_stream;
+  delete Trace_stream;
   Trace_stream = Save_trace_stream;
   Save_trace_stream = NULL;
   Trace_file = Save_trace_file;
   Save_trace_file.clear();
   Recipe.erase(get(Recipe_ordinal, "interactive"));  // keep past sandboxes from inserting errors
-  if (!Save_recently_added_recipes.empty()) {
+  if (!Save_recently_added_recipes.empty()) {
     clear_recently_added_recipes();
     Recently_added_recipes = Save_recently_added_recipes;
     Save_recently_added_recipes.clear();
@@ -192,18 +185,18 @@ load(string(
   "errors:address:shared:array:character <- save-errors\n" +
   "stashes:address:shared:array:character <- save-app-trace\n" +
   "$cleanup-run-interactive\n" +
-  "reply output, errors, screen, stashes, completed?\n" +
+  "return output, errors, screen, stashes, completed?\n" +
 "]\n");
 transform_all();
 Recently_added_recipes.clear();
 
 //: adjust errors in the sandbox
 :(after "string maybe(string s)")
-  if (s == "interactive") return "";
+  if (s == "interactive") return "";
 
 :(scenario run_interactive_comments)
-recipe main [
-  1:address:shared:array:character <- new [# ab
+def main [
+  1:address:shared:array:character <- new [# ab
 add 2, 2]
   2:address:shared:array:character <- run-interactive 1:address:shared:array:character
   3:array:character <- copy *2:address:shared:array:character
@@ -215,11 +208,11 @@ _START_TRACKING_PRODUCTS,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "$start-tracking-products", _START_TRACKING_PRODUCTS);
 :(before "End Primitive Recipe Checks")
-case _START_TRACKING_PRODUCTS: {
+case _START_TRACKING_PRODUCTS: {
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case _START_TRACKING_PRODUCTS: {
+case _START_TRACKING_PRODUCTS: {
   Track_most_recent_products = true;
   break;
 }
@@ -229,11 +222,11 @@ _STOP_TRACKING_PRODUCTS,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "$stop-tracking-products", _STOP_TRACKING_PRODUCTS);
 :(before "End Primitive Recipe Checks")
-case _STOP_TRACKING_PRODUCTS: {
+case _STOP_TRACKING_PRODUCTS: {
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case _STOP_TRACKING_PRODUCTS: {
+case _STOP_TRACKING_PRODUCTS: {
   Track_most_recent_products = false;
   break;
 }
@@ -243,11 +236,11 @@ _MOST_RECENT_PRODUCTS,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "$most-recent-products", _MOST_RECENT_PRODUCTS);
 :(before "End Primitive Recipe Checks")
-case _MOST_RECENT_PRODUCTS: {
+case _MOST_RECENT_PRODUCTS: {
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case _MOST_RECENT_PRODUCTS: {
+case _MOST_RECENT_PRODUCTS: {
   products.resize(1);
   products.at(0).push_back(new_mu_string(Most_recent_products));
   break;
@@ -258,11 +251,11 @@ SAVE_ERRORS,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "save-errors", SAVE_ERRORS);
 :(before "End Primitive Recipe Checks")
-case SAVE_ERRORS: {
+case SAVE_ERRORS: {
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case SAVE_ERRORS: {
+case SAVE_ERRORS: {
   products.resize(1);
   products.at(0).push_back(trace_error_contents());
   break;
@@ -273,11 +266,11 @@ SAVE_APP_TRACE,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "save-app-trace", SAVE_APP_TRACE);
 :(before "End Primitive Recipe Checks")
-case SAVE_APP_TRACE: {
+case SAVE_APP_TRACE: {
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case SAVE_APP_TRACE: {
+case SAVE_APP_TRACE: {
   products.resize(1);
   products.at(0).push_back(trace_app_contents());
   break;
@@ -288,19 +281,19 @@ _CLEANUP_RUN_INTERACTIVE,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "$cleanup-run-interactive", _CLEANUP_RUN_INTERACTIVE);
 :(before "End Primitive Recipe Checks")
-case _CLEANUP_RUN_INTERACTIVE: {
+case _CLEANUP_RUN_INTERACTIVE: {
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case _CLEANUP_RUN_INTERACTIVE: {
+case _CLEANUP_RUN_INTERACTIVE: {
   run_code_end();
   break;
 }
 
 :(scenario "run_interactive_converts_result_to_text")
-recipe main [
+def main [
   # try to interactively add 2 and 2
-  1:address:shared:array:character <- new [add 2, 2]
+  1:address:shared:array:character <- new [add 2, 2]
   2:address:shared:array:character <- run-interactive 1:address:shared:array:character
   10:array:character <- copy 2:address:shared:array:character/lookup
 ]
@@ -308,11 +301,11 @@ recipe main [
 +mem: storing 52 in location 11
 
 :(scenario "run_interactive_returns_text")
-recipe main [
+def main [
   # try to interactively add 2 and 2
-  1:address:shared:array:character <- new [
-    x:address:shared:array:character <- new [a]
-    y:address:shared:array:character <- new [b]
+  1:address:shared:array:character <- new [
+    x:address:shared:array:character <- new [a]
+    y:address:shared:array:character <- new [b]
     z:address:shared:array:character <- append x:address:shared:array:character, y:address:shared:array:character
   ]
   2:address:shared:array:character <- run-interactive 1:address:shared:array:character
@@ -323,9 +316,9 @@ recipe main [
 +mem: storing 98 in location 12
 
 :(scenario "run_interactive_returns_errors")
-recipe main [
+def main [
   # run a command that generates an error
-  1:address:shared:array:character <- new [x:number <- copy 34
+  1:address:shared:array:character <- new [x:number <- copy 34
 get x:number, foo:offset]
   2:address:shared:array:character, 3:address:shared:array:character <- run-interactive 1:address:shared:array:character
   10:array:character <- copy 3:address:shared:array:character/lookup
@@ -338,9 +331,9 @@ get x:number, foo:offset]
 # ...
 
 :(scenario run_interactive_with_comment)
-recipe main [
+def main [
   # 2 instructions, with a comment after the first
-  1:address:shared:array:number <- new [a:number <- copy 0  # abc
+  1:address:shared:array:number <- new [a:number <- copy 0  # abc
 b:number <- copy 0
 ]
   2:address:shared:array:character, 3:address:shared:array:character <- run-interactive 1:address:shared:array:character
@@ -349,11 +342,11 @@ b:number <- copy 0
 +mem: storing 0 in location 3
 
 :(code)
-void test_run_interactive_cleans_up_any_created_specializations() {
+void test_run_interactive_cleans_up_any_created_specializations() {
   // define a generic recipe
   assert(!contains_key(Recipe_ordinal, "foo"));
   load("recipe foo x:_elem -> n:number [\n"
-       "  reply 34\n"
+       "  return 34\n"
        "]\n");
   assert(SIZE(Recently_added_recipes) == 1);  // foo
   assert(variant_count("foo") == 1);
@@ -368,8 +361,8 @@ void test_run_interactive_cleans_up_any_created_specializations(variant_count("foo"), 1);
 }
 
-long long int variant_count(string recipe_name) {
-  if (!contains_key(Recipe_variants, recipe_name)) return 0;
+long long int variant_count(string recipe_name) {
+  if (!contains_key(Recipe_variants, recipe_name)) return 0;
   return non_ghost_size(get(Recipe_variants, recipe_name));
 }
 
@@ -378,21 +371,21 @@ string Most_recent_products;
 :(before "End Setup")
 Most_recent_products = "";
 :(before "End of Instruction")
-if (Track_most_recent_products) {
+if (Track_most_recent_products) {
   track_most_recent_products(current_instruction(), products);
 }
 :(code)
-void track_most_recent_products(const instruction& instruction, const vector<vector<double> >& products) {
+void track_most_recent_products(const instruction& instruction, const vector<vector<double> >& products) {
   ostringstream out;
-  for (long long int i = 0; i < SIZE(products); ++i) {
+  for (long long int i = 0; i < SIZE(products); ++i) {
     // string
-    if (i < SIZE(instruction.products)) {
-      if (is_mu_string(instruction.products.at(i))) {
-        if (!scalar(products.at(i))) {
+    if (i < SIZE(instruction.products)) {
+      if (is_mu_string(instruction.products.at(i))) {
+        if (!scalar(products.at(i))) {
           tb_shutdown();
           cerr << read_mu_string(trace_error_contents()) << '\n';
           cerr << SIZE(products.at(i)) << ": ";
-          for (long long int j = 0; j < SIZE(products.at(i)); ++j)
+          for (long long int j = 0; j < SIZE(products.at(i)); ++j)
             cerr << no_scientific(products.at(i).at(j)) << ' ';
           cerr << '\n';
         }
@@ -402,7 +395,7 @@ void track_most_recent_products(const instruction
       }
       // End Record Product Special-cases
     }
-    for (long long int j = 0; j < SIZE(products.at(i)); ++j)
+    for (long long int j = 0; j < SIZE(products.at(i)); ++j)
       out << no_scientific(products.at(i).at(j)) << ' ';
     out << '\n';
   }
@@ -412,55 +405,55 @@ void track_most_recent_products(const instruction
 :(code)
 string strip_comments(string in) {
   ostringstream result;
-  for (long long int i = 0; i < SIZE(in); ++i) {
-    if (in.at(i) != '#') {
+  for (long long int i = 0; i < SIZE(in); ++i) {
+    if (in.at(i) != '#') {
       result << in.at(i);
     }
-    else {
-      while (i+1 < SIZE(in) && in.at(i+1) != '\n')
+    else {
+      while (i+1 < SIZE(in) && in.at(i+1) != '\n')
         ++i;
     }
   }
   return result.str();
 }
 
-long long int stringified_value_of_location(long long int address) {
+long long int stringified_value_of_location(long long int address) {
   // convert to string
   ostringstream out;
   out << no_scientific(get_or_insert(Memory, address));
   return new_mu_string(out.str());
 }
 
-long long int trace_error_contents() {
-  if (!Trace_stream) return 0;
+long long int trace_error_contents() {
+  if (!Trace_stream) return 0;
   ostringstream out;
-  for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
-    if (p->label != "error") continue;
+  for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
+    if (p->label != "error") continue;
     out << p->contents;
-    if (*--p->contents.end() != '\n') out << '\n';
+    if (*--p->contents.end() != '\n') out << '\n';
   }
   string result = out.str();
-  if (result.empty()) return 0;
+  if (result.empty()) return 0;
   truncate(result);
   return new_mu_string(result);
 }
 
-long long int trace_app_contents() {
-  if (!Trace_stream) return 0;
+long long int trace_app_contents() {
+  if (!Trace_stream) return 0;
   ostringstream out;
-  for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
-    if (p->depth != App_depth) continue;
+  for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
+    if (p->depth != App_depth) continue;
     out << p->contents;
-    if (*--p->contents.end() != '\n') out << '\n';
+    if (*--p->contents.end() != '\n') out << '\n';
   }
   string result = out.str();
-  if (result.empty()) return 0;
+  if (result.empty()) return 0;
   truncate(result);
   return new_mu_string(result);
 }
 
-void truncate(string& x) {
-  if (SIZE(x) > 512) {
+void truncate(string& x) {
+  if (SIZE(x) > 512) {
     x.erase(512);
     *x.rbegin() = '\n';
     *++x.rbegin() = '.';
@@ -476,34 +469,34 @@ RELOAD,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "reload", RELOAD);
 :(before "End Primitive Recipe Checks")
-case RELOAD: {
-  if (SIZE(inst.ingredients) != 1) {
-    raise_error << maybe(get(Recipe, r).name) << "'reload' requires exactly one ingredient, but got " << to_string(inst) << '\n' << end();
+case RELOAD: {
+  if (SIZE(inst.ingredients) != 1) {
+    raise << maybe(get(Recipe, r).name) << "'reload' requires exactly one ingredient, but got " << to_string(inst) << '\n' << end();
     break;
   }
-  if (!is_mu_string(inst.ingredients.at(0))) {
-    raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'reload' should be a string, but got " << inst.ingredients.at(0).original_string << '\n' << end();
+  if (!is_mu_string(inst.ingredients.at(0))) {
+    raise << maybe(get(Recipe, r).name) << "first ingredient of 'reload' should be a string, but got " << inst.ingredients.at(0).original_string << '\n' << end();
     break;
   }
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case RELOAD: {
+case RELOAD: {
   // clear any containers in advance
-  for (long long int i = 0; i < SIZE(Recently_added_types); ++i) {
-    if (!contains_key(Type, Recently_added_types.at(i))) continue;
+  for (long long int i = 0; i < SIZE(Recently_added_types); ++i) {
+    if (!contains_key(Type, Recently_added_types.at(i))) continue;
     Type_ordinal.erase(get(Type, Recently_added_types.at(i)).name);
     Type.erase(Recently_added_types.at(i));
   }
-  for (map<string, vector<recipe_ordinal> >::iterator p = Recipe_variants.begin(); p != Recipe_variants.end(); ++p) {
+  for (map<string, vector<recipe_ordinal> >::iterator p = Recipe_variants.begin(); p != Recipe_variants.end(); ++p) {
     vector<recipe_ordinal>& variants = p->second;
-    for (long long int i = 0; i < SIZE(p->second); ++i) {
-      if (variants.at(i) == -1) continue;
-      if (find(Recently_added_shape_shifting_recipes.begin(), Recently_added_shape_shifting_recipes.end(), variants.at(i)) != Recently_added_shape_shifting_recipes.end())
+    for (long long int i = 0; i < SIZE(p->second); ++i) {
+      if (variants.at(i) == -1) continue;
+      if (find(Recently_added_shape_shifting_recipes.begin(), Recently_added_shape_shifting_recipes.end(), variants.at(i)) != Recently_added_shape_shifting_recipes.end())
         variants.at(i) = -1;  // ghost
     }
   }
-  for (long long int i = 0; i < SIZE(Recently_added_shape_shifting_recipes); ++i) {
+  for (long long int i = 0; i < SIZE(Recently_added_shape_shifting_recipes); ++i) {
     Recipe_ordinal.erase(get(Recipe, Recently_added_shape_shifting_recipes.at(i)).name);
     Recipe.erase(Recently_added_shape_shifting_recipes.at(i));
   }
@@ -515,7 +508,7 @@ case RELOAD: {
   vector<recipe_ordinal> recipes_reloaded = load(code);
   // clear a few things from previous runs
   // ad hoc list; we've probably missed a few
-  for (long long int i = 0; i < SIZE(recipes_reloaded); ++i)
+  for (long long int i = 0; i < SIZE(recipes_reloaded); ++i)
     Name.erase(recipes_reloaded.at(i));
   transform_all();
   Trace_stream->newline();  // flush trace
@@ -527,9 +520,9 @@ case RELOAD: {
 }
 
 :(scenario reload_continues_past_error)
-recipe main [
+def main [
   local-scope
-  x:address:shared:array:character <- new [recipe foo [
+  x:address:shared:array:character <- new [recipe foo [
   get 1234:number, foo:offset
 ]]
   reload x
@@ -538,7 +531,7 @@ recipe main [
 +mem: storing 34 in location 1
 
 :(code)
-void test_reload_cleans_up_any_created_specializations() {
+void test_reload_cleans_up_any_created_specializations() {
   // define a generic recipe and a call to it
   assert(!contains_key(Recipe_ordinal, "foo"));
   assert(variant_count("foo") == 0);
@@ -548,7 +541,7 @@ void test_reload_cleans_up_any_created_specializations()
       "  x:address:shared:array:character <- new [recipe foo x:_elem -> n:number [\n"
       "local-scope\n"
       "load-ingredients\n"
-      "reply 34\n"
+      "return 34\n"
       "]\n"
       "recipe main2 [\n"
       "local-scope\n"
@@ -565,4 +558,3 @@ void test_reload_cleans_up_any_created_specializations()
 
- -- cgit 1.4.1-2-gfad0