about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--apps/tile/data.mu32
-rw-r--r--apps/tile/environment.mu14
-rw-r--r--apps/tile/main.mu13
3 files changed, 36 insertions, 23 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu
index 44f2149b..6310c8e8 100644
--- a/apps/tile/data.mu
+++ b/apps/tile/data.mu
@@ -60,9 +60,7 @@ type call-path {
   next: (handle call-path)
 }
 
-# A call-path is a list of elements, each of which corresponds to some call.
-# Calls are denoted by their position in the caller's body. They also include
-# the function being called.
+# A call-path element is a list of elements, each of which corresponds to some call.
 type call-path-element {
   word: (handle word)
   next: (handle call-path-element)
@@ -444,8 +442,8 @@ fn initialize-path-from-line _line: (addr line), _out: (addr handle call-path-el
   copy-object src, dest
 }
 
-fn find-in-call-path in: (addr handle call-path), needle: (addr handle call-path-element) -> result/eax: boolean {
-  var curr-ah/esi: (addr handle call-path) <- copy in
+fn find-in-call-paths call-paths: (addr handle call-path), needle: (addr handle call-path-element) -> result/eax: boolean {
+  var curr-ah/esi: (addr handle call-path) <- copy call-paths
   var out/edi: boolean <- copy 0  # false
   $find-in-call-path:loop: {
     var curr/eax: (addr call-path) <- lookup *curr-ah
@@ -603,6 +601,19 @@ fn decrement-final-element list: (addr handle call-path-element) {
   copy-object new-ah, val-ah
 }
 
+fn move-final-element-to-start-of-line list: (addr handle call-path-element) {
+  var final-ah/eax: (addr handle call-path-element) <- copy list
+  var final/eax: (addr call-path-element) <- lookup *final-ah
+  var val-ah/ecx: (addr handle word) <- get final, word
+  var val/eax: (addr word) <- lookup *val-ah
+  var new-ah/edx: (addr handle word) <- get val, prev
+  var target/eax: (addr word) <- lookup *new-ah
+  compare target, 0
+  break-if-=
+  copy-object new-ah, val-ah
+  move-final-element-to-start-of-line list
+}
+
 fn push-to-call-path-element list: (addr handle call-path-element), new: (addr handle word) {
   var new-element-storage: (handle call-path-element)
   var new-element-ah/edi: (addr handle call-path-element) <- address new-element-storage
@@ -625,6 +636,17 @@ fn drop-from-call-path-element _list: (addr handle call-path-element) {
   copy-object next, _list
 }
 
+fn drop-nested-calls _list: (addr handle call-path-element) {
+  var list-ah/esi: (addr handle call-path-element) <- copy _list
+  var list/eax: (addr call-path-element) <- lookup *list-ah
+  var next-ah/edi: (addr handle call-path-element) <- get list, next
+  var next/eax: (addr call-path-element) <- lookup *next-ah
+  compare next, 0
+  break-if-=
+  copy-object next-ah, _list
+  drop-nested-calls _list
+}
+
 fn dump-call-path-element screen: (addr screen), _x-ah: (addr handle call-path-element) {
 $dump-call-path-element:body: {
   var x-ah/ecx: (addr handle call-path-element) <- copy _x-ah
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index 22bd94aa..9e1c8bf1 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -115,7 +115,7 @@ $process-sandbox:body: {
     {
       var cursor-call-path/esi: (addr handle call-path-element) <- get sandbox, cursor-call-path
       var expanded-words/edx: (addr handle call-path) <- get sandbox, expanded-words
-      var curr-word-is-expanded?/eax: boolean <- find-in-call-path expanded-words, cursor-call-path
+      var curr-word-is-expanded?/eax: boolean <- find-in-call-paths expanded-words, cursor-call-path
       compare curr-word-is-expanded?, 0  # false
       break-if-=
       # update cursor-call-path
@@ -220,7 +220,7 @@ $process-sandbox:body: {
 #?         print-string 0, "c\n"
         {
           var expanded-words/eax: (addr handle call-path) <- get sandbox, expanded-words
-          var curr-word-is-expanded?/eax: boolean <- find-in-call-path expanded-words, cursor-call-path
+          var curr-word-is-expanded?/eax: boolean <- find-in-call-paths expanded-words, cursor-call-path
           compare curr-word-is-expanded?, 0  # false
           break-if-= $process-sandbox:key-right-arrow-next-word-is-call-expanded
         }
@@ -320,11 +320,11 @@ $process-sandbox:body: {
   compare key, 1  # ctrl-a
   $process-sandbox:start-of-line: {
     break-if-!=
-    # move cursor to initial word of sandbox
+    # move cursor up past all calls and to start of line
     var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
-    initialize-path-from-sandbox sandbox, cursor-call-path-ah
+    drop-nested-calls cursor-call-path-ah
+    move-final-element-to-start-of-line cursor-call-path-ah
     # move cursor to start of initial word
-    var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
     var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
     var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
     var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
@@ -757,7 +757,7 @@ $toggle-cursor-word:body: {
 #?   dump-call-path-element 0, cursor-call-path
 #?   print-string 0, "expanded words:\n"
 #?   dump-call-paths 0, expanded-words
-  var already-expanded?/eax: boolean <- find-in-call-path expanded-words, cursor-call-path
+  var already-expanded?/eax: boolean <- find-in-call-paths expanded-words, cursor-call-path
   compare already-expanded?, 0  # false
   {
     break-if-!=
@@ -1123,7 +1123,7 @@ fn render-line screen: (addr screen), functions: (addr handle function), binding
     $render-line:subsidiary: {
       {
 #?         print-string 0, "check sub\n"
-        var display-subsidiary-stack?/eax: boolean <- find-in-call-path expanded-words, curr-path
+        var display-subsidiary-stack?/eax: boolean <- find-in-call-paths expanded-words, curr-path
         compare display-subsidiary-stack?, 0  # false
         break-if-= $render-line:subsidiary
       }
diff --git a/apps/tile/main.mu b/apps/tile/main.mu
index 2defb364..3e79bcbd 100644
--- a/apps/tile/main.mu
+++ b/apps/tile/main.mu
@@ -77,18 +77,9 @@ fn test {
   initialize-environment-with-fake-screen env, 5, 0xa
   var g/eax: grapheme <- copy 0x31  # '1'
   process env, g
-  g <- copy 0x20  # space
+  g <- copy 1  # 'ctrl-a'
   process env, g
-  g <- copy 0x32  # '2'
-  process env, g
-  render env
-  g <- copy 4  # 'ctrl-d'
-  process env, g
-  g <- copy 0x61  # 'a'
-  process env, g
-  g <- copy 0xa  # newline
-  process env, g
-  render env
+#?   render env
 }
 
 fn repl {