about summary refs log tree commit diff stats
path: root/078run_interactive.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-31 23:44:52 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-01 00:11:31 -0700
commit87fbfc2d4607ff31d5b0b023f41d8ba439dd5958 (patch)
treec511ff6d2ea35991dca67f905559d81d6004b5a3 /078run_interactive.cc
parent4bbd3ded0b767ae0919551776e4c17189140e735 (diff)
downloadmu-87fbfc2d4607ff31d5b0b023f41d8ba439dd5958.tar.gz
1518 - still horribly broken
Just figured out why a first keystroke of backspace was sending me out
for a spin: run_interactive needs all early exits that don't actually
run anything to increment the current_step_index(). FML, this is lousy..
Diffstat (limited to '078run_interactive.cc')
-rw-r--r--078run_interactive.cc58
1 files changed, 58 insertions, 0 deletions
diff --git a/078run_interactive.cc b/078run_interactive.cc
new file mode 100644
index 00000000..25ca4dd9
--- /dev/null
+++ b/078run_interactive.cc
@@ -0,0 +1,58 @@
+//: Helper for the repl.
+
+:(before "End Primitive Recipe Declarations")
+RUN_INTERACTIVE,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["run-interactive"] = RUN_INTERACTIVE;
+//? cerr << "run-interactive: " << RUN_INTERACTIVE << '\n'; //? 1
+:(before "End Primitive Recipe Implementations")
+case RUN_INTERACTIVE: {
+  assert(scalar(ingredients.at(0)));
+//?   cerr << "AAA 0\n"; //? 1
+  run_interactive(ingredients.at(0).at(0));
+//?   cerr << "ZZZ\n"; //? 1
+  continue;  // not done with caller; don't increment current_step_index()
+}
+
+:(code)
+// manual tests:
+//  just an integer prints value of that location in memory
+//  instruction executes [not yet working]
+//  backspace at start begins new attempt
+void run_interactive(long long int address) {
+//?   tb_shutdown(); //? 1
+  long long int size = Memory[address];
+  if (size == 0) {
+    ++current_step_index();
+    return;
+  }
+  ostringstream tmp;
+  for (long long int curr = address+1; curr < address+size; ++curr) {
+    // todo: unicode
+    tmp << (char)(int)Memory[curr];
+  }
+//?   cerr << size << ' ' << Memory[address+size] << '\n'; //? 1
+  assert(Memory[address+size] == 10);  // skip the newline
+  if (Recipe_number.find("interactive") == Recipe_number.end())
+    Recipe_number["interactive"] = Next_recipe_number++;
+  if (is_integer(tmp.str())) {
+    cerr << "=> " << Memory[to_integer(tmp.str())] << '\n';
+    ++current_step_index();
+    return;
+  }
+//?   exit(0); //? 1
+  if (Name[Recipe_number["interactive"]].find(tmp.str()) != Name[Recipe_number["interactive"]].end()) {
+    cerr << "=> " << Memory[Name[Recipe_number["interactive"]][tmp.str()]] << '\n';
+    ++current_step_index();
+    return;
+  }
+//?   tb_shutdown(); //? 1
+//?   cerr << tmp.str(); //? 1
+//?   exit(0); //? 1
+//?   cerr << "AAA 1\n"; //? 1
+  Recipe.erase(Recipe_number["interactive"]);
+  // call run(string) but without the scheduling
+  load("recipe interactive [\n"+tmp.str()+"]\n");
+  transform_all();
+  Current_routine->calls.push_front(call(Recipe_number["interactive"]));
+}