about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-19 18:27:29 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-19 18:27:29 -0700
commita553a5e201b347f4ecc5f0fd9956fb083f941c86 (patch)
treeba6167b3fca05eecb68931d95a54b0cb6704c9af /apps
parentabfd0bad29b2a481583207d17f7bd1ebe2ffc2f5 (diff)
downloadmu-a553a5e201b347f4ecc5f0fd9956fb083f941c86.tar.gz
6804 - tile: render all words
Diffstat (limited to 'apps')
-rw-r--r--apps/tile/environment.mu22
-rw-r--r--apps/tile/word.mu23
2 files changed, 37 insertions, 8 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index 6b31c22a..09898c26 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -43,9 +43,6 @@ fn render-loop _self: (addr environment) {
 fn process _self: (addr environment), key: grapheme {
 $process:body: {
     var self/esi: (addr environment) <- copy _self
-    var cursor-word-ah/eax: (addr handle word) <- get self, cursor-word
-    var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah
-    var cursor-word/ecx: (addr word) <- copy _cursor-word
     compare key, 0x445b1b  # left-arrow
     {
       break-if-!=
@@ -69,7 +66,11 @@ $process:body: {
     compare key, 0x20  # space
     {
       break-if-!=
-      # TODO: new word
+      var cursor-word-ah/edx: (addr handle word) <- get self, cursor-word
+      append-word cursor-word-ah
+      var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
+      var next-word-ah/ecx: (addr handle word) <- get cursor-word, next
+      copy-object next-word-ah, cursor-word-ah
       break $process:body
     }
     var g/edx: grapheme <- copy key
@@ -77,6 +78,8 @@ $process:body: {
     {
       compare print?, 0  # false
       break-if-=
+      var cursor-word-ah/eax: (addr handle word) <- get self, cursor-word
+      var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
       add-grapheme-to-word cursor-word, g
       break $process:body
     }
@@ -128,7 +131,16 @@ fn render _env: (addr environment), max-depth: int {
 # - If final-word is same as cursor-word, do some additional computation to set
 #   cursor-col-a.
 fn render-stack screen: (addr screen), first-word: (addr word), final-word: (addr word), botleft-row: int, botleft-col: int, cursor-word: (addr word), cursor-col-a: (addr int) -> right-col/ecx: int {
-  print-word screen, first-word
+  var curr/eax: (addr word) <- copy first-word
+  {
+    print-word screen, curr
+    compare curr, final-word
+    break-if-=
+    print-string screen " "
+    var next/ecx: (addr handle word) <- get curr, next
+    curr <- lookup *next
+    loop
+  }
 }
 
 # We could be a little faster by not using 'first-word' (since max is commutative),
diff --git a/apps/tile/word.mu b/apps/tile/word.mu
index c87a2242..1fb214a6 100644
--- a/apps/tile/word.mu
+++ b/apps/tile/word.mu
@@ -25,6 +25,19 @@ fn allocate-word-with _out: (addr handle word), s: (addr array byte) {
   initialize-word-with out-addr, s
 }
 
+# TODO: handle existing next
+# one implication of handles: append must take a handle
+fn append-word _self-ah: (addr handle word) {
+  var self-ah/esi: (addr handle word) <- copy _self-ah
+  var self/eax: (addr word) <- lookup *self-ah
+  var next-ah/eax: (addr handle word) <- get self, next
+  allocate next-ah
+  var next/eax: (addr word) <- lookup *next-ah
+  initialize-word next
+  var prev-ah/eax: (addr handle word) <- get next, prev
+  copy-handle *self-ah, prev-ah
+}
+
 # just for tests for now
 # TODO: handle existing next
 # one implication of handles: append must take a handle
@@ -71,15 +84,19 @@ fn first-word _self: (addr word) -> result/eax: (addr word) {
   result <- copy out
 }
 
-fn final-word _self: (addr word), out: (addr handle word) {
+fn final-word _self: (addr word) -> result/eax: (addr word) {
   var self/esi: (addr word) <- copy _self
+  var out/edi: (addr word) <- copy self
   var next/esi: (addr handle word) <- get self, next
   {
-    copy-object next, out
     var curr/eax: (addr word) <- lookup *next
     compare curr, 0
-    loop-if-!=
+    break-if-=
+    out <- copy curr
+    next <- get curr, next
+    loop
   }
+  result <- copy out
 }
 
 fn add-grapheme-to-word _self: (addr word), c: grapheme {