about summary refs log tree commit diff stats
path: root/091run_interactive.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-03-21 23:45:42 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-03-21 23:45:42 -0700
commit0f0d3e7ae6412c281f67ee48f71b48f23d13e3bb (patch)
tree5c60e6d614c6a7f42cdefe955f2d9092fa562cb5 /091run_interactive.cc
parent2103abd30e9dd2956f84304ef77c4d8916cd3557 (diff)
downloadmu-0f0d3e7ae6412c281f67ee48f71b48f23d13e3bb.tar.gz
2806 - bugfix: cleaning up in 'reload'
This brings back some of the complexity I thought I'd gotten rid of in
2799.

The regression brought home the point that I'd forgotten to write tests
for those bits. Written now.

It also brought home the point that our cleanup in 'reload' has always
been hacky and incomplete.

It's also ugly that those tests in the sandbox/ and edit/ apps need
changing (particularly when the test is about how the output doesn't
change).
Diffstat (limited to '091run_interactive.cc')
-rw-r--r--091run_interactive.cc45
1 files changed, 37 insertions, 8 deletions
diff --git a/091run_interactive.cc b/091run_interactive.cc
index a4e0d21b..7f00acba 100644
--- a/091run_interactive.cc
+++ b/091run_interactive.cc
@@ -78,7 +78,7 @@ bool run_interactive(int address) {
   }
   string command = trim(strip_comments(read_mu_string(address)));
   Name[get(Recipe_ordinal, "interactive")].clear();
-  run_code_begin(/*snapshot_recently_added_recipes*/true);
+  run_code_begin(/*should_stash_snapshots*/true);
   if (command.empty()) return false;
   // don't kill the current routine on parse errors
   routine* save_current_routine = Current_routine;
@@ -116,11 +116,11 @@ map<type_ordinal, type_info> Type_snapshot_stash;
 map<recipe_ordinal, map<string, int> > Name_snapshot_stash;
 map<string, vector<recipe_ordinal> > Recipe_variants_snapshot_stash;
 :(code)
-void run_code_begin(bool snapshot_recently_added_recipes) {
+void run_code_begin(bool should_stash_snapshots) {
   // stuff to undo later, in run_code_end()
   Hide_errors = true;
   Disable_redefine_checks = true;
-  if (snapshot_recently_added_recipes)
+  if (should_stash_snapshots)
     stash_snapshots();
   Save_trace_stream = Trace_stream;
   Save_trace_file = Trace_file;
@@ -448,15 +448,22 @@ case RELOAD: {
 }
 :(before "End Primitive Recipe Implementations")
 case RELOAD: {
+  // conundrum: need to support repeated reloads of the same code, but not
+  // wipe out state for the current test
+  // hacky solution: subset of restore_snapshots() without restoring recipes {
+  // can't yet define containers in a test that runs 'reload'
+  Type_ordinal = Type_ordinal_snapshot;
+  Type = Type_snapshot;
+  // can't yet create new specializations of shape-shifting recipes in a test
+  // that runs 'reload'
+  Recipe_variants = Recipe_variants_snapshot;
+  Name = Name_snapshot;
+  // }
   string code = read_mu_string(ingredients.at(0).at(0));
-  run_code_begin(/*snapshot_recently_added_recipes*/false);
+  run_code_begin(/*should_stash_snapshots*/false);
   routine* save_current_routine = Current_routine;
   Current_routine = NULL;
   vector<recipe_ordinal> recipes_reloaded = load(code);
-  // clear a few things from previous runs
-  // ad hoc list; we've probably missed a few
-  for (int i = 0; i < SIZE(recipes_reloaded); ++i)
-    Name.erase(recipes_reloaded.at(i));
   transform_all();
   Trace_stream->newline();  // flush trace
   Current_routine = save_current_routine;
@@ -476,3 +483,25 @@ def main [
   1:number/raw <- copy 34
 ]
 +mem: storing 34 in location 1
+
+:(scenario reload_can_repeatedly_load_container_definitions)
+# define a container and try to create it (merge requires knowing container size)
+def main [
+  local-scope
+  x:address:shared:array:character <- new [
+    container foo [
+      x:number
+      y:number
+    ]
+    recipe bar [
+      local-scope
+      x:foo <- merge 34, 35
+    ]
+  ]
+  # save warning addresses in locations of type 'number' to avoid spurious changes to them due to 'abandon'
+  1:number/raw <- reload x
+  2:number/raw <- reload x
+]
+# no errors on either load
++mem: storing 0 in location 1
++mem: storing 0 in location 2