about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-23 22:32:32 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-23 22:35:00 -0700
commit3daf4cb3e30fb1372d65a21021168b9fa15ecfe1 (patch)
tree25f1ecc5ee260edf674c2ec116155dc18a9220c2
parent22a7849a5efb5d5fa76a6f5633f802b8be9b21c3 (diff)
downloadmu-3daf4cb3e30fb1372d65a21021168b9fa15ecfe1.tar.gz
6845
-rw-r--r--apps/tile/data.mu23
-rw-r--r--apps/tile/word.mu57
2 files changed, 46 insertions, 34 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu
index c9988ed3..1cdbbc5c 100644
--- a/apps/tile/data.mu
+++ b/apps/tile/data.mu
@@ -25,13 +25,13 @@ type line {
   prev: (handle line)
 }
 
-#? type word {
-#?   # at most one of these will be non-null
-#?   scalar-data: (handle gap-buffer)
-#?   box-data: (handle line)  # recurse
-#?   left: (handle word)
-#?   right: (handle word)
-#? }
+type word {
+  # at most one of these will be non-null
+  scalar-data: (handle gap-buffer)
+  box-data: (handle line)  # recurse
+  next: (handle word)
+  prev: (handle word)
+}
 
 type result {
   data: (handle word-stack)
@@ -71,3 +71,12 @@ fn initialize-line _line: (addr line), out: (addr handle word) {
   var word/eax: (addr word) <- lookup *word-ah
   initialize-word word
 }
+
+fn initialize-word _self: (addr word) {
+  var self/esi: (addr word) <- copy _self
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  allocate data-ah
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
+  initialize-gap-buffer data
+  # TODO: sometimes initialize box-data rather than scalar-data
+}
diff --git a/apps/tile/word.mu b/apps/tile/word.mu
index 70c2eafb..e0d20f56 100644
--- a/apps/tile/word.mu
+++ b/apps/tile/word.mu
@@ -1,20 +1,9 @@
-type word {
-  data: gap-buffer
-  next: (handle word)
-  prev: (handle word)
-}
-
-fn initialize-word _self: (addr word) {
-  var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
-  initialize-gap-buffer data
-}
-
 ## some helpers for creating words. mostly for tests
 
 fn initialize-word-with _self: (addr word), s: (addr array byte) {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   initialize-gap-buffer-with data, s
 }
 
@@ -52,13 +41,15 @@ fn prepend-word-with self-h: (handle word), s: (addr array byte) {
 
 fn word-equal? _self: (addr word), s: (addr array byte) -> result/eax: boolean {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   result <- gap-buffer-equal? data, s
 }
 
 fn word-length _self: (addr word) -> result/eax: int {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   result <- gap-buffer-length data
 }
 
@@ -94,61 +85,71 @@ fn final-word _self: (addr word) -> result/eax: (addr word) {
 
 fn first-grapheme _self: (addr word) -> result/eax: grapheme {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   result <- first-grapheme-in-gap-buffer data
 }
 
 fn add-grapheme-to-word _self: (addr word), c: grapheme {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   add-grapheme-at-gap data, c
 }
 
 fn cursor-at-start? _self: (addr word) -> result/eax: boolean {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   result <- gap-at-start? data
 }
 
 fn cursor-at-end? _self: (addr word) -> result/eax: boolean {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   result <- gap-at-end? data
 }
 
 fn cursor-left _self: (addr word) {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   var dummy/eax: grapheme <- gap-left data
 }
 
 fn cursor-right _self: (addr word) {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   var dummy/eax: grapheme <- gap-right data
 }
 
 fn cursor-to-start _self: (addr word) {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   gap-to-start data
 }
 
 fn cursor-to-end _self: (addr word) {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   gap-to-end data
 }
 
 fn cursor-index _self: (addr word) -> result/eax: int {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   result <- gap-index data
 }
 
 fn delete-before-cursor _self: (addr word) {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   delete-before-gap data
 }
 
@@ -172,7 +173,8 @@ $delete-next:body: {
 
 fn print-word screen: (addr screen), _self: (addr word) {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   render-gap-buffer screen, data
 }
 
@@ -209,6 +211,7 @@ fn append-word _self-ah: (addr handle word) {
 
 fn emit-word _self: (addr word), out: (addr stream byte) {
   var self/esi: (addr word) <- copy _self
-  var data/eax: (addr gap-buffer) <- get self, data
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
   emit-gap-buffer data, out
 }