about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-23 13:04:46 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-23 13:04:46 -0700
commitfedebaf5dbc1b39347ad3e3a1580fa0190c320b6 (patch)
treec7951656c6495acb5f69db45953ce8cec60587f5
parent02a55f7183f1497284accb3b89abab4a103d6e68 (diff)
downloadmu-fedebaf5dbc1b39347ad3e3a1580fa0190c320b6.tar.gz
1630 - bring back replace-in-console
This takes away the need for multi-level escaping in scenario setup.
Post-conditions like screen-should-contain are still an issue, though.

Maybe each string literal should be able to specify escapes inside its
syntax? Or at a per-instruction granularity?
-rw-r--r--075scenario_console.cc26
-rw-r--r--repl.mu68
2 files changed, 60 insertions, 34 deletions
diff --git a/075scenario_console.cc b/075scenario_console.cc
index f776f6b2..017eebcd 100644
--- a/075scenario_console.cc
+++ b/075scenario_console.cc
@@ -157,6 +157,32 @@ scenario events-in-scenario [
   ]
 ]
 
+//: Deal with special keys and unmatched brackets by allowing each test to
+//: independently choose the unicode symbol to denote them.
+:(before "End Primitive Recipe Declarations")
+REPLACE_IN_CONSOLE,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["replace-in-console"] = REPLACE_IN_CONSOLE;
+:(before "End Primitive Recipe Implementations")
+case REPLACE_IN_CONSOLE: {
+  assert(scalar(ingredients.at(0)));
+//?   cerr << "console: " << Memory[CONSOLE] << '\n'; //? 1
+  if (!Memory[CONSOLE])
+    raise << "console not initialized\n" << die();
+  long long int console_data = Memory[Memory[CONSOLE]+1];
+//?   cerr << "console data starts at " << console_data << '\n'; //? 1
+  long long int size = Memory[console_data];  // array size
+//?   cerr << "size of console data is " << size << '\n'; //? 1
+  for (long long int i = 0, curr = console_data+1; i < size; ++i, curr+=size_of_event()) {
+//?     cerr << curr << '\n'; //? 1
+    if (Memory[curr] != /*text*/0) continue;
+    if (Memory[curr+1] != ingredients.at(0).at(0)) continue;
+    for (long long int n = 0; n < size_of_event(); ++n)
+      Memory[curr+n] = ingredients.at(1).at(n);
+  }
+  break;
+}
+
 :(code)
 long long int count_events(const recipe& r) {
   long long int result = 0;
diff --git a/repl.mu b/repl.mu
index e8c62e5e..59aa6850 100644
--- a/repl.mu
+++ b/repl.mu
@@ -412,11 +412,10 @@ scenario read-instruction-color-comment [
 scenario read-instruction-cancel-comment-on-backspace [
   assume-screen 30:literal/width, 5:literal/height
   assume-console [
-    type [#a]
-    press 8  # backspace
-    press 8  # backspace
-    type [z]
+    type [#a««z]
   ]
+  backspace:event <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 171:literal/«, backspace:event
   run [
     read-instruction console:address, screen:address
   ]
@@ -433,12 +432,10 @@ scenario read-instruction-cancel-comment-on-backspace [
 scenario read-instruction-cancel-comment-on-backspace2 [
   assume-screen 30:literal/width, 5:literal/height
   assume-console [
-    type [#ab]
-    press 8  # backspace
-    press 8  # backspace
-    press 8  # backspace
-    type [z]
+    type [#ab«««z]
   ]
+  backspace:event <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 171:literal/«, backspace:event
   run [
     read-instruction console:address, screen:address
   ]
@@ -455,10 +452,10 @@ scenario read-instruction-cancel-comment-on-backspace2 [
 scenario read-instruction-cancel-comment-on-backspace3 [
   assume-screen 30:literal/width, 5:literal/height
   assume-console [
-    type [#a]
-    press 8  # backspace
-    type [z]
+    type [#a«z]
   ]
+  backspace:event <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 171:literal/«, backspace:event
   run [
     read-instruction console:address, screen:address
   ]
@@ -643,12 +640,13 @@ scenario read-instruction-color-string-inside-string [
 
 scenario read-instruction-cancel-string-on-backspace [
   assume-screen 30:literal/width, 5:literal/height
-  # need to escape the '[' once for 'scenario' and once for 'assume-console'
   assume-console [
-    type [\\\\\[a]
-    press 8  # backspace
-    type [z]
+    type [(a««z]  # '(' is '[' and '«' is backspace
   ]
+  open-bracket:event <- merge 0:literal/text, 91:literal/open-bracket, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 40:literal/open-paren, open-bracket:event
+  backspace:event <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 171:literal/«, backspace:event
   run [
 #?     d:address:array:event <- get console:address/deref, data:offset #? 1
 #?     $print [a: ], d:address:array:event #? 1
@@ -669,12 +667,14 @@ scenario read-instruction-cancel-string-on-backspace [
 scenario read-instruction-cancel-string-inside-string-on-backspace [
   assume-screen 30:literal/width, 5:literal/height
   assume-console [
-    type [\\\\\[a[b]]
-    press 8  # backspace
-    press 8  # backspace
-    press 8  # backspace
-    type [b\\\\\]]
-  ]
+    type [(a[b]«««b)]  # '(' is '[' and '«' is backspace
+  ]
+  open-bracket:event <- merge 0:literal/text, 91:literal/open-bracket, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 40:literal/open-paren, open-bracket:event
+  close-bracket:event <- merge 0:literal/text, 93:literal/close-bracket, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 41:literal/close-paren, close-bracket:event
+  backspace:event <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 171:literal/«, backspace:event
   run [
     read-instruction console:address, screen:address
   ]
@@ -691,10 +691,10 @@ scenario read-instruction-cancel-string-inside-string-on-backspace [
 scenario read-instruction-backspace-back-into-string [
   assume-screen 30:literal/width, 5:literal/height
   assume-console [
-    type [[a]]
-    press 8  # backspace
-    type [b]
+    type [[a]«b]  # '«' is backspace
   ]
+  backspace:event <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 171:literal/«, backspace:event
   run [
     read-instruction console:address, screen:address
   ]
@@ -766,9 +766,10 @@ scenario read-instruction-highlight-assignment [
 scenario read-instruction-backspace-over-assignment [
   assume-screen 30:literal/width, 5:literal/height
   assume-console [
-    type [a <-]
-    press 8  # backspace
+    type [a <-«]  # '«' is backspace
   ]
+  backspace:event <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 171:literal/«, backspace:event
   run [
     read-instruction console:address, screen:address
   ]
@@ -789,10 +790,10 @@ scenario read-instruction-backspace-over-assignment [
 scenario read-instruction-assignment-continues-after-backspace [
   assume-screen 30:literal/width, 5:literal/height
   assume-console [
-    type [a <-]
-    press 8  # backspace
-    type [-]
+    type [a <-«-]  # '«' is backspace
   ]
+  backspace:event <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 171:literal/«, backspace:event
 #?   $print [aaa] #? 1
   run [
     read-instruction console:address, screen:address
@@ -814,11 +815,10 @@ scenario read-instruction-assignment-continues-after-backspace [
 scenario read-instruction-assignment-continues-after-backspace2 [
   assume-screen 30:literal/width, 5:literal/height
   assume-console [
-    type [a <- ]
-    press 8  # backspace
-    press 8  # backspace
-    type [-]
+    type [a <- ««-]  # '«' is backspace
   ]
+  backspace:event <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
+  replace-in-console 171:literal/«, backspace:event
   run [
     read-instruction console:address, screen:address
 #?     $browse-trace #? 1