about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-01 01:26:08 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-01 01:26:08 -0800
commit339dfd55df8a85f65a95d2a88b9b177a4112b069 (patch)
tree8ddb1cd3b6077415e9add71a9af81e964a4d9048
parentff72d104b036360b4615aaa8b0b32fc4aff4bddb (diff)
downloadmu-339dfd55df8a85f65a95d2a88b9b177a4112b069.tar.gz
695 - another attempt to handle strings in history
But now that we've added the keyboard parameter to process-keys,
modifying it in a recursive call also clobbers it in the caller. All
because of my weird, non-standard use of shared scope.
-rw-r--r--color-repl.mu28
-rw-r--r--mu.arc3
2 files changed, 16 insertions, 15 deletions
diff --git a/color-repl.mu b/color-repl.mu
index 8931a1fa..efbe0035 100644
--- a/color-repl.mu
+++ b/color-repl.mu
@@ -24,11 +24,8 @@
   { begin
     ; repeatedly read keys from the keyboard
     ;   test: 34<enter>
-    (c:character <- wait-for-key k:keyboard-address silent:literal/terminal)
-    (loop-unless c:character)
-    (done?:boolean <- process-key default-space:space-address c:character k:keyboard-address screen:terminal-address)
-    (break-if done?:boolean)
-    (loop)
+    (done?:boolean <- process-key default-space:space-address k:keyboard-address screen:terminal-address)
+    (loop-unless done?:boolean)
   }
   ; trim trailing newline in result (easier history management below)
   { begin
@@ -46,9 +43,9 @@
 (function process-key [  ; return t to signal end of expression
   ; must always be called from within 'read-expression'
   (default-space:space-address/names:read-expression <- next-input)
-  (c:character <- next-input)
   (k:keyboard-address <- next-input)
   (screen:terminal-address <- next-input)
+  (c:character <- wait-for-key k:keyboard-address silent:literal/terminal)
   (len:integer-address <- get-address result:buffer-address/deref length:offset)
   (maybe-cancel-this-expression c:character abort:continuation)
   ; check for ctrl-d and exit
@@ -141,17 +138,18 @@
     (curr-history:string-address <- buffer-index history:buffer-address current-history-index:integer)
     (curr-history-len:integer <- length curr-history:string-address/deref)
     ; and retype it into the current expression
-    (i:integer <- copy 0:literal)
+    (hist:keyboard-address <- init-keyboard curr-history:string-address)
+    (hist-index:integer-address <- get-address hist:keyboard-address/deref index:offset)
     { begin
-      (done?:boolean <- greater-or-equal i:integer curr-history-len:integer)
+      ($print hist-index:integer-address/deref)
+      ($print curr-history-len:integer)
+      ($print (("\n" literal)))
+      (done?:boolean <- greater-or-equal hist-index:integer-address/deref curr-history-len:integer)
       (break-if done?:boolean)
-      ; no more access to current character
-      (c:character <- index curr-history:string-address/deref i:integer)
-      ; recursive calls to process-key can clobber any local state except i,
-      ; which we won't touch because history strings are guaranteed to only
-      ; have printable characters, never <up> or <down>
-      (process-key default-space:space-address c:character)
-      (i:integer <- add i:integer 1:literal)
+      ; beware: recursive calls to process-key can clobber locals used outside
+      ; the up/down cases
+      (sub-return:boolean <- process-key default-space:space-address hist:keyboard-address screen:terminal-address)
+      (assert-false sub-return:boolean (("recursive call to process keys thought it was done" literal)))
       (loop)
     }
     ; <enter> is trimmed in the history expression, so wait for the human to
diff --git a/mu.arc b/mu.arc
index fd1f0cdf..2b2971cc 100644
--- a/mu.arc
+++ b/mu.arc
@@ -667,6 +667,9 @@
                 assert
                   (unless (m arg.0)
                     (die (v arg.1)))  ; other routines will be able to look at the error status
+                assert-false
+                  (when (m arg.0)
+                    (die (v arg.1)))
 
                 ; cursor-based (text mode) interaction
                 cursor-mode