about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--081run_interactive.cc63
-rw-r--r--edit.mu36
2 files changed, 23 insertions, 76 deletions
diff --git a/081run_interactive.cc b/081run_interactive.cc
index abb67b17..fd076c06 100644
--- a/081run_interactive.cc
+++ b/081run_interactive.cc
@@ -1,22 +1,6 @@
 //: Helper for various programming environments: run arbitrary mu code and
 //: return some result in string form.
 
-:(scenario run_interactive_location)
-recipe main [
-  1:number <- copy 34:literal
-  2:address:array:character <- new [1
-]
-  3:address:array:character <- run-interactive 2:address:array:character
-  4:array:character <- copy 3:address:array:character/deref
-]
-#? ?
-# size of string
-+mem: storing 2 in location 4
-# unicode '3'
-+mem: storing 51 in location 5
-# unicode '4'
-+mem: storing 52 in location 6
-
 :(scenario run_interactive_code)
 recipe main [
   2:address:array:character <- new [1:number <- copy 34:literal
@@ -25,21 +9,6 @@ recipe main [
 ]
 +mem: storing 34 in location 1
 
-:(scenario run_interactive_name)
-recipe main [
-  2:address:array:character <- new [x:number <- copy 34:literal
-]
-  run-interactive 2:address:array:character
-  3:address:array:character <- new [x
-]
-  4:address:array:character <- run-interactive 3:address:array:character
-  5:array:character <- copy 4:address:array:character/deref
-]
-# result is string "34"
-+mem: storing 2 in location 5
-+mem: storing 51 in location 6
-+mem: storing 52 in location 7
-
 :(scenario run_interactive_empty)
 recipe main [
   1:address:array:character <- run-interactive 0:literal
@@ -56,11 +25,10 @@ Recipe_ordinal["run-interactive"] = RUN_INTERACTIVE;
 case RUN_INTERACTIVE: {
   assert(scalar(ingredients.at(0)));
   products.resize(1);
-  long long int result = 0;
-  bool new_code_pushed_to_stack = run_interactive(ingredients.at(0).at(0), &result);
+  bool new_code_pushed_to_stack = run_interactive(ingredients.at(0).at(0));
   if (!new_code_pushed_to_stack) {
-    products.at(0).push_back(result);
-    break;
+    products.at(0).push_back(0);
+    break;  // done with this instruction
   }
   else {
     continue;  // not done with caller; don't increment current_step_index()
@@ -68,14 +36,11 @@ case RUN_INTERACTIVE: {
 }
 
 :(code)
-// reads a string. if it's a variable, stores its value as a string and returns false.
-// if it's lines of code, calls them and returns true (no result available yet to be stored)
-bool run_interactive(long long int address, long long int* result) {
-//?   cerr << "run interactive\n"; //? 1
+// reads a string, tries to call it as code.
+// returns true if successfully called (no errors found during load and transform)
+bool run_interactive(long long int address) {
   long long int size = Memory[address];
   if (size == 0) {
-//?     trace(1, "foo") << "AAA"; //? 2
-    *result = 0;
     return false;
   }
   ostringstream tmp;
@@ -87,32 +52,16 @@ bool run_interactive(long long int address, long long int* result) {
     Recipe_ordinal["interactive"] = Next_recipe_ordinal++;
   string command = trim(strip_comments(tmp.str()));
   if (command.empty()) return false;
-  if (is_integer(command)) {
-//?     trace(1, "foo") << "BBB"; //? 2
-    *result = stringified_value_of_location(to_integer(command));
-//?     trace(1, "foo") << *result << " " << result << " " << Memory[*result]; //? 2
-    return false;
-  }
-  if (Name[Recipe_ordinal["interactive"]].find(command) != Name[Recipe_ordinal["interactive"]].end()) {
-//?     trace(1, "foo") << "CCC"; //? 2
-    *result = stringified_value_of_location(Name[Recipe_ordinal["interactive"]][command]);
-    return false;
-  }
-//?   trace(1, "foo") << "DDD"; //? 2
   Recipe.erase(Recipe_ordinal["interactive"]);
-//?   trace("foo") << "hiding warnings\n"; //? 2
   Hide_warnings = true;
   // call run(string) but without the scheduling
   load("recipe interactive [\n"+command+"\n]\n");
   transform_all();
   if (trace_count("warn") > 0) {
     Hide_warnings = false;
-    *result = 0;
     return false;
   }
-//?   cerr << "call interactive: " << Current_routine->calls.size() << '\n'; //? 1
   Current_routine->calls.push_front(call(Recipe_ordinal["interactive"]));
-  *result = 0;
   return true;
 }
 
diff --git a/edit.mu b/edit.mu
index 2500991f..aa09fb8b 100644
--- a/edit.mu
+++ b/edit.mu
@@ -1844,43 +1844,41 @@ scenario editor-provides-edited-contents [
 
 ## running code in editors
 
-scenario run-query-for-location [
-  assume-screen 10:literal/width, 5:literal/height
+scenario run-and-show-results [
+  assume-screen 60:literal/width, 5:literal/height
   # left editor is empty
   1:address:array:character <- new []
   2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
-  # right editor contains a query for location 12
-  3:address:array:character <- new [12]
+  # right editor contains an instruction without storing outputs
+  3:address:array:character <- new [divide-with-remainder 11:literal, 3:literal]
   4:address:address:editor-data <- get-address 2:address:editor-data/deref, next-editor:offset
-  4:address:address:editor-data/deref <- new-editor 3:address:array:character, screen:address, 0:literal/top, 5:literal/left, 10:literal/right
+  4:address:address:editor-data/deref <- new-editor 3:address:array:character, screen:address, 0:literal/top, 5:literal/left, 60:literal/right
   reset-focus 2:address:editor-data
   # run the code in the editors
   assume-console [
     press 65527  # F9
   ]
   run [
-    # initialize location 12
-    12:number <- copy 34:literal
     # now run query for it
     event-loop screen:address, console:address, 2:address:editor-data
-#?     $dump-trace #? 1
-#?     $browse-trace #? 1
   ]
-  # check that screen prints the value in location 12
+  # check that screen prints the results
   screen-should-contain [
-    .     12   .
-    .     34   .
-    .          .
+    .     divide-with-remainder 11:literal, 3:literal            .
+    .     3                                                      .
+    .     2                                                      .
+    .                                                            .
   ]
+#?   $exit #? 1
   screen-should-contain-in-color 7:literal/white, [
-    .     12   .
-    .          .
-    .          .
+    .     divide-with-remainder 11:literal, 3:literal            .
+    .                                                            .
   ]
   screen-should-contain-in-color 245:literal/grey, [
-    .          .
-    .     34   .
-    .          .
+    .                                                            .
+    .     3                                                      .
+    .     2                                                      .
+    .                                                            .
   ]
 ]