about summary refs log tree commit diff stats
path: root/101run_sandboxed.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-03-20 18:03:21 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-03-20 18:03:21 -0700
commitd35595fd7d8244c51cfbaf357f1d4214ca7bfeda (patch)
tree94626e8fb2797032ea4287c81f1219a598fb9eb0 /101run_sandboxed.cc
parent60f2ec5148ef494beee5d0cfd6d41f3967e7f66b (diff)
downloadmu-d35595fd7d8244c51cfbaf357f1d4214ca7bfeda.tar.gz
3805
Diffstat (limited to '101run_sandboxed.cc')
-rw-r--r--101run_sandboxed.cc48
1 files changed, 45 insertions, 3 deletions
diff --git a/101run_sandboxed.cc b/101run_sandboxed.cc
index b048b321..1904942f 100644
--- a/101run_sandboxed.cc
+++ b/101run_sandboxed.cc
@@ -350,6 +350,42 @@ def foo [
 # no product should have been tracked
 +mem: storing 0 in location 10
 
+:(scenario "run_interactive_ignores_products_in_previous_instructions")
+def main [
+  1:text <- new [
+    add 1, 1  # generates a product
+    foo]  # no products
+  2:text <- run-sandboxed 1:text
+  10:@:char <- copy *2:text
+]
+def foo [
+  20:num <- copy 1234
+  {
+    break
+    reply 5678
+  }
+]
+# no product should have been tracked
++mem: storing 0 in location 10
+
+:(scenario "run_interactive_remembers_products_before_final_label")
+def main [
+  1:text <- new [
+    add 1, 1  # generates a product
+    +foo]  # no products
+  2:text <- run-sandboxed 1:text
+  10:@:char <- copy *2:text
+]
+def foo [
+  20:num <- copy 1234
+  {
+    break
+    reply 5678
+  }
+]
+# product tracked
++mem: storing 50 in location 11
+
 :(scenario "run_interactive_returns_text")
 def main [
   # try to interactively add 2 and 2
@@ -391,12 +427,18 @@ b:num <- copy 0
 # no errors
 +mem: storing 0 in location 3
 
+:(after "Running One Instruction")
+if (Track_most_recent_products && SIZE(Current_routine->calls) == Call_depth_to_track_most_recent_products_at
+    && !current_instruction().is_label
+    && current_instruction().name != "$stop-tracking-products") {
+  Most_recent_products = "";
+}
 :(before "End Running One Instruction")
 if (Track_most_recent_products && SIZE(Current_routine->calls) == Call_depth_to_track_most_recent_products_at) {
-  track_most_recent_products(current_instruction(), products);
+  Most_recent_products = track_most_recent_products(current_instruction(), products);
 }
 :(code)
-void track_most_recent_products(const instruction& instruction, const vector<vector<double> >& products) {
+string track_most_recent_products(const instruction& instruction, const vector<vector<double> >& products) {
   ostringstream out;
   for (int i = 0; i < SIZE(products); ++i) {
     // A sandbox can print a string result, but only if it is actually saved
@@ -420,7 +462,7 @@ void track_most_recent_products(const instruction& instruction, const vector<vec
       out << no_scientific(products.at(i).at(j)) << ' ';
     out << '\n';
   }
-  Most_recent_products = out.str();
+  return out.str();
 }
 
 :(code)