about summary refs log tree commit diff stats
path: root/apps/tile
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-10-24 16:52:33 -0700
committerKartik Agaram <vc@akkartik.com>2020-10-24 16:52:33 -0700
commit1137dd2a997a271761c8da0b7e2be05d977909e1 (patch)
tree7b8cfab28466aad00d62d70221a945e12a86c6f0 /apps/tile
parent07a1a2991275f2c98d20750c68dc87fb9d99895c (diff)
downloadmu-1137dd2a997a271761c8da0b7e2be05d977909e1.tar.gz
tile: process space at start of word
This was very difficult to debug.

We still need to process space in the middle of a word.
Diffstat (limited to 'apps/tile')
-rw-r--r--apps/tile/data.mu12
-rw-r--r--apps/tile/environment.mu53
-rw-r--r--apps/tile/main.mu15
-rw-r--r--apps/tile/word.mu77
4 files changed, 148 insertions, 9 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu
index 6310c8e8..03f66bd2 100644
--- a/apps/tile/data.mu
+++ b/apps/tile/data.mu
@@ -594,10 +594,22 @@ fn decrement-final-element list: (addr handle call-path-element) {
   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
+#?   print-string 0, "replacing "
+#?   {
+#?     var foo/eax: int <- copy val
+#?     print-int32-hex 0, foo
+#?   }
   var new-ah/edx: (addr handle word) <- get val, prev
   var target/eax: (addr word) <- lookup *new-ah
   compare target, 0
   break-if-=
+  # val = val->prev
+#?   print-string 0, " with "
+#?   {
+#?     var foo/eax: int <- copy target
+#?     print-int32-hex 0, foo
+#?   }
+#?   print-string 0, "\n"
   copy-object new-ah, val-ah
 }
 
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index 0190cc24..1fc811aa 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -169,10 +169,30 @@ $process-sandbox:body: {
     {
       compare prev-word, 0
       break-if-=
-#?       print-string 0, "previous word\n"
+#?       print-string 0, "move to previous word\n"
       cursor-to-end prev-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
+#?         var cursor-word/ebx: (addr word) <- copy _cursor-word
+#?         print-string 0, "word at cursor before: "
+#?         print-word 0, cursor-word
+#?         print-string 0, "\n"
+#?       }
       var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
       decrement-final-element cursor-call-path
+#?       {
+#?         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
+#?         var cursor-word/ebx: (addr word) <- copy _cursor-word
+#?         print-string 0, "word at cursor after: "
+#?         print-word 0, cursor-word
+#?         print-string 0, "\n"
+#?       }
     }
     break $process-sandbox:body
   }
@@ -391,10 +411,30 @@ $process-sandbox:body: {
   compare key, 0x20  # space
   $process-sandbox:space: {
     break-if-!=
-    # insert new word
-    append-word cursor-word-ah
-    var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
-    increment-final-element cursor-call-path
+#?     print-string 0, "space\n"
+    # if cursor is at start of word, insert word before
+    {
+      var at-start?/eax: boolean <- cursor-at-start? cursor-word
+      compare at-start?, 0  # false
+      break-if-=
+      var prev-word-ah/eax: (addr handle word) <- get cursor-word, prev
+      append-word prev-word-ah
+      var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+      decrement-final-element cursor-call-path
+      break $process-sandbox:body
+    }
+    # if cursor is at end of word, insert word after
+    {
+      var at-end?/eax: boolean <- cursor-at-end? cursor-word
+      compare at-end?, 0  # false
+      break-if-=
+      append-word cursor-word-ah
+      var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+      increment-final-element cursor-call-path
+      break $process-sandbox:body
+    }
+    # otherwise split word into two
+    # TODO
     break $process-sandbox:body
   }
   compare key, 0xe  # ctrl-n
@@ -888,6 +928,9 @@ fn render-final-line-with-stack screen: (addr screen), functions: (addr handle f
   var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
   var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah
   var cursor-word/ebx: (addr word) <- copy _cursor-word
+#?   print-string 0, "word at cursor: "
+#?   print-word 0, cursor-word
+#?   print-string 0, "\n"
   # cursor-call-path
   var cursor-call-path: (addr handle call-path-element)
   {
diff --git a/apps/tile/main.mu b/apps/tile/main.mu
index 3e79bcbd..4cf325a1 100644
--- a/apps/tile/main.mu
+++ b/apps/tile/main.mu
@@ -77,9 +77,20 @@ fn test {
   initialize-environment-with-fake-screen env, 5, 0xa
   var g/eax: grapheme <- copy 0x31  # '1'
   process env, g
-  g <- copy 1  # 'ctrl-a'
+  g <- copy 0x20  # space
+  process env, g
+  g <- copy 0x32  # '2'
+  process env, g
+  g <- copy 0x33  # '3'
+  process env, g
+  g <- copy 0x445b1b  # left-arrow
+  process env, g
+  g <- copy 0x445b1b  # left-arrow
+  process env, g
+  g <- copy 0x20  # space
+  process env, g
+  g <- copy 0x445b1b  # left-arrow
   process env, g
-#?   render env
 }
 
 fn repl {
diff --git a/apps/tile/word.mu b/apps/tile/word.mu
index 9bd1d44c..63695ae0 100644
--- a/apps/tile/word.mu
+++ b/apps/tile/word.mu
@@ -367,17 +367,46 @@ fn copy-word _src-a: (addr word), _dest-ah: (addr handle word) {
 
 # one implication of handles: append must take a handle
 fn append-word _self-ah: (addr handle word) {
+  var saved-self-storage: (handle word)
+  var saved-self/eax: (addr handle word) <- address saved-self-storage
+  copy-object _self-ah, saved-self
+#?   {
+#?     print-string 0, "self-ah is "
+#?     var foo/eax: int <- copy _self-ah
+#?     print-int32-hex 0, foo
+#?     print-string 0, "\n"
+#?   }
   var self-ah/esi: (addr handle word) <- copy _self-ah
   var _self/eax: (addr word) <- lookup *self-ah
   var self/ebx: (addr word) <- copy _self
+#?   {
+#?     print-string 0, "0: self is "
+#?     var self-ah/eax: (addr handle word) <- copy _self-ah
+#?     var self/eax: (addr word) <- lookup *self-ah
+#?     var foo/eax: int <- copy self
+#?     print-int32-hex 0, foo
+#?     print-string 0, "\n"
+#?   }
   # allocate new handle
   var new: (handle word)
   var new-ah/ecx: (addr handle word) <- address new
   allocate new-ah
   var new-addr/eax: (addr word) <- lookup new
   initialize-word new-addr
+#?   {
+#?     print-string 0, "new is "
+#?     var foo/eax: int <- copy new-addr
+#?     print-int32-hex 0, foo
+#?     print-string 0, "\n"
+#?   }
   # new->next = self->next
   var src/esi: (addr handle word) <- get self, next
+#?   {
+#?     print-string 0, "src is "
+#?     var foo/eax: int <- copy src
+#?     print-int32-hex 0, foo
+#?     print-string 0, "\n"
+#?   }
   var dest/edi: (addr handle word) <- get new-addr, next
   copy-object src, dest
   # new->next->prev = new
@@ -385,12 +414,56 @@ fn append-word _self-ah: (addr handle word) {
     var next-addr/eax: (addr word) <- lookup *src
     compare next-addr, 0
     break-if-=
+#?     {
+#?       print-string 0, "next-addr is "
+#?       var foo/eax: int <- copy next-addr
+#?       print-int32-hex 0, foo
+#?       print-string 0, "\n"
+#?     }
     dest <- get next-addr, prev
+#? #?     {
+#? #?       print-string 0, "self-ah is "
+#? #?       var foo/eax: int <- copy _self-ah
+#? #?       print-int32-hex 0, foo
+#? #?       print-string 0, "\n"
+#? #?       print-string 0, "2: self is "
+#? #?       var self-ah/eax: (addr handle word) <- copy _self-ah
+#? #?       var self/eax: (addr word) <- lookup *self-ah
+#? #?       var foo/eax: int <- copy self
+#? #?       print-int32-hex 0, foo
+#? #?       print-string 0, "\n"
+#? #?     }
+#?     {
+#?       print-string 0, "copying new to "
+#?       var foo/eax: int <- copy dest
+#?       print-int32-hex 0, foo
+#?       print-string 0, "\n"
+#?     }
     copy-object new-ah, dest
+#?     {
+#?       print-string 0, "4: self is "
+#?       var self-ah/eax: (addr handle word) <- copy _self-ah
+#?       var self/eax: (addr word) <- lookup *self-ah
+#?       var foo/eax: int <- copy self
+#?       print-int32-hex 0, foo
+#?       print-string 0, "\n"
+#?     }
   }
-  # new->prev = self
+  # new->prev = saved-self
   dest <- get new-addr, prev
-  copy-object _self-ah, dest
+#?   {
+#?     print-string 0, "copying "
+#?     var self-ah/esi: (addr handle word) <- copy _self-ah
+#?     var self/eax: (addr word) <- lookup *self-ah
+#?     var foo/eax: int <- copy self
+#?     print-int32-hex 0, foo
+#?     print-string 0, " to "
+#?     foo <- copy dest
+#?     print-int32-hex 0, foo
+#?     print-string 0, "\n"
+#?   }
+  var saved-self-ah/eax: (addr handle word) <- address saved-self-storage
+  copy-object saved-self-ah, dest
   # self->next = new
   dest <- get self, next
   copy-object new-ah, dest