about summary refs log tree commit diff stats
path: root/apps/tile
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-19 23:41:35 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-19 23:41:35 -0700
commit0e86b32a5e7cc5408e640d9369c0dde057dff411 (patch)
tree8f7b18472f30934d435c72497283a578da12d7ff /apps/tile
parent6413032997ed0b33ee87fca915dbfd3110aeb2f9 (diff)
downloadmu-0e86b32a5e7cc5408e640d9369c0dde057dff411.tar.gz
6816 - tile: inserting new words
Diffstat (limited to 'apps/tile')
-rw-r--r--apps/tile/word.mu34
1 files changed, 26 insertions, 8 deletions
diff --git a/apps/tile/word.mu b/apps/tile/word.mu
index 9145f1d5..07e5280f 100644
--- a/apps/tile/word.mu
+++ b/apps/tile/word.mu
@@ -170,17 +170,35 @@ fn print-word screen: (addr screen), _self: (addr word) {
   render-gap-buffer screen, data
 }
 
-# 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
+  var _self/eax: (addr word) <- lookup *self-ah
+  var self/ebx: (addr word) <- copy _self
+  # 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
+  # new->next = self->next
+  var src/esi: (addr handle word) <- get self, next
+  var dest/edi: (addr handle word) <- get new-addr, next
+  copy-object src, dest
+  # new->next->prev = new
+  {
+    var next-addr/eax: (addr word) <- lookup *src
+    compare next-addr, 0
+    break-if-=
+    dest <- get next-addr, prev
+    copy-object new-ah, dest
+  }
+  # new->prev = self
+  dest <- get new-addr, prev
+  copy-object _self-ah, dest
+  # self->next = new
+  dest <- get self, next
+  copy-object new-ah, dest
 }
 
 fn emit-word _self: (addr word), out: (addr stream byte) {