about summary refs log tree commit diff stats
path: root/091run_interactive.cc
diff options
context:
space:
mode:
Diffstat (limited to '091run_interactive.cc')
-rw-r--r--091run_interactive.cc123
1 files changed, 35 insertions, 88 deletions
diff --git a/091run_interactive.cc b/091run_interactive.cc
index 1e6bf9c2..b84d8ca9 100644
--- a/091run_interactive.cc
+++ b/091run_interactive.cc
@@ -62,8 +62,6 @@ bool Track_most_recent_products = false;
 :(before "End Tracing")
 trace_stream* Save_trace_stream = NULL;
 string Save_trace_file;
-vector<recipe_ordinal> Save_recently_added_recipes;
-vector<recipe_ordinal> Save_recently_added_shape_shifting_recipes;
 :(before "End Setup")
 Track_most_recent_products = false;
 :(code)
@@ -79,9 +77,9 @@ bool run_interactive(int address) {
       Memory.erase(i);
   }
   string command = trim(strip_comments(read_mu_string(address)));
-  if (command.empty()) return false;
   Name[get(Recipe_ordinal, "interactive")].clear();
   run_code_begin(/*snapshot_recently_added_recipes*/true);
+  if (command.empty()) return false;
   // don't kill the current routine on parse errors
   routine* save_current_routine = Current_routine;
   Current_routine = NULL;
@@ -108,16 +106,22 @@ bool run_interactive(int address) {
   return true;
 }
 
+//: Carefully update all state to exactly how it was -- including snapshots.
+
+:(before "End Globals")
+map<string, recipe_ordinal> Recipe_ordinal_snapshot_stash;
+map<recipe_ordinal, recipe> Recipe_snapshot_stash;
+map<string, type_ordinal> Type_ordinal_snapshot_stash;
+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) {
   // stuff to undo later, in run_code_end()
   Hide_errors = true;
   Disable_redefine_checks = true;
-  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;
-    Recently_added_shape_shifting_recipes.clear();
-  }
+  if (snapshot_recently_added_recipes)
+    stash_snapshots();
   Save_trace_stream = Trace_stream;
   Save_trace_file = Trace_file;
   Trace_file = "";
@@ -134,13 +138,28 @@ void run_code_end() {
   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()) {
-    clear_recently_added_recipes();
-    Recently_added_recipes = Save_recently_added_recipes;
-    Save_recently_added_recipes.clear();
-    Recently_added_shape_shifting_recipes = Save_recently_added_shape_shifting_recipes;
-    Save_recently_added_shape_shifting_recipes.clear();
-  }
+  if (!Recipe_snapshot_stash.empty())
+    unstash_snapshots();
+}
+
+// keep sync'd with save_snapshots and restore_snapshots
+void stash_snapshots() {
+  Recipe_ordinal_snapshot_stash = Recipe_ordinal_snapshot;
+  Recipe_snapshot_stash = Recipe_snapshot;
+  Type_ordinal_snapshot_stash = Type_ordinal_snapshot;
+  Type_snapshot_stash = Type_snapshot;
+  Name_snapshot_stash = Name_snapshot;
+  Recipe_variants_snapshot_stash = Recipe_variants_snapshot;
+  save_snapshots();
+}
+void unstash_snapshots() {
+  restore_snapshots();
+  Recipe_ordinal_snapshot = Recipe_ordinal_snapshot_stash;  Recipe_ordinal_snapshot_stash.clear();
+  Recipe_snapshot = Recipe_snapshot_stash;  Recipe_snapshot_stash.clear();
+  Type_ordinal_snapshot = Type_ordinal_snapshot_stash;  Type_ordinal_snapshot_stash.clear();
+  Type_snapshot = Type_snapshot_stash;  Type_snapshot_stash.clear();
+  Name_snapshot = Name_snapshot_stash;  Name_snapshot_stash.clear();
+  Recipe_variants_snapshot = Recipe_variants_snapshot_stash;  Recipe_variants_snapshot_stash.clear();
 }
 
 :(before "End Load Recipes")
@@ -161,8 +180,6 @@ load(string(
   "$cleanup-run-interactive\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)")
@@ -315,31 +332,6 @@ b:number <- copy 0
 # no errors
 +mem: storing 0 in location 3
 
-:(code)
-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"
-       "  return 34\n"
-       "]\n");
-  assert(SIZE(Recently_added_recipes) == 1);  // foo
-  assert(variant_count("foo") == 1);
-  // run-interactive a call that specializes this recipe
-  run("recipe main [\n"
-       "  1:number/raw <- copy 0\n"
-       "  2:address:shared:array:character <- new [foo 1:number/raw]\n"
-       "  run-interactive 2:address:shared:array:character\n"
-       "]\n");
-  assert(SIZE(Recently_added_recipes) == 2);  // foo, main
-  // check that number of variants doesn't change
-  CHECK_EQ(variant_count("foo"), 1);
-}
-
-int variant_count(string recipe_name) {
-  if (!contains_key(Recipe_variants, recipe_name)) return 0;
-  return non_ghost_size(get(Recipe_variants, recipe_name));
-}
-
 :(before "End Globals")
 string Most_recent_products;
 :(before "End Setup")
@@ -456,25 +448,6 @@ case RELOAD: {
 }
 :(before "End Primitive Recipe Implementations")
 case RELOAD: {
-  // clear any containers in advance
-  for (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) {
-    vector<recipe_ordinal>& variants = p->second;
-    for (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 (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));
-  }
-  Recently_added_shape_shifting_recipes.clear();
   string code = read_mu_string(ingredients.at(0).at(0));
   run_code_begin(/*snapshot_recently_added_recipes*/false);
   routine* save_current_routine = Current_routine;
@@ -503,29 +476,3 @@ def main [
   1:number/raw <- copy 34
 ]
 +mem: storing 34 in location 1
-
-:(code)
-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);
-  // a call that specializes this recipe
-  run("recipe main [\n"
-      "  local-scope\n"
-      "  x:address:shared:array:character <- new [recipe foo x:_elem -> n:number [\n"
-      "local-scope\n"
-      "load-ingredients\n"
-      "return 34\n"
-      "]\n"
-      "recipe main2 [\n"
-      "local-scope\n"
-      "load-ingredients\n"
-      "x:number <- copy 34\n"
-      "foo x:number\n"
-      "]]\n"
-      "  reload x\n"
-      "]\n");
-  // check that number of variants includes specialization
-  assert(SIZE(Recently_added_recipes) == 4);  // foo, main, main2, foo specialization
-  CHECK_EQ(variant_count("foo"), 2);
-}
href='/akkartik/mu/blame/linux/126write-int-decimal.subx?h=main&id=1a1a1671edd8d27cdd6229c08e6b40a202d85740'>^
117a710a ^


de7713d9 ^
117a710a ^



de7713d9 ^
117a710a ^







de7713d9 ^

117a710a ^


de7713d9 ^
117a710a ^



de7713d9 ^
117a710a ^































71e4f381 ^


































117a710a ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466