about summary refs log tree commit diff stats
path: root/apps/tile
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-20 13:42:13 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-20 13:42:13 -0700
commit022595a20a66d09a1e1a9e0c0a7d9eb07b4e863f (patch)
treee537c1abc68b75add44a68a3afcb5a1ebcf74ba0 /apps/tile
parenta1ae40403df306a6bfd026493303ff2aac84d48b (diff)
downloadmu-022595a20a66d09a1e1a9e0c0a7d9eb07b4e863f.tar.gz
6821 - highlight words clobbered by the next word
Another suggestion from the Future of Software forum.
Diffstat (limited to 'apps/tile')
-rw-r--r--apps/tile/environment.mu35
-rw-r--r--apps/tile/gap-buffer.mu34
-rw-r--r--apps/tile/word.mu6
3 files changed, 75 insertions, 0 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index 98a18653..355572b6 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -201,15 +201,26 @@ fn render-column screen: (addr screen), first-word: (addr word), final-word: (ad
   initialize-int-stack stack-addr, 0x10  # max-words
   evaluate first-word, final-word, stack-addr
   # render stack
+  var stack-index/ebx: int <- copy 0
   var stack-remaining/eax: int <- int-stack-length stack-addr
   var curr-row/edx: int <- copy botleft-depth
   curr-row <- add 6  # input-row 3 + stack-margin-top 3
   curr-row <- subtract stack-remaining
+  # highlight item just added
   start-color screen, 0, 2
   {
     compare stack-remaining, 0
     break-if-<=
     move-cursor screen, curr-row, botleft-col
+    # highlight items about to be removed
+    {
+      compare stack-index, 1  # second from top
+      break-if-!=
+      var safe-next-word?/eax: boolean <- next-word-is-number? final-word
+      compare safe-next-word?, 0  # false
+      break-if-!=
+      start-color screen, 0, 1
+    }
     {
       var val/eax: int <- pop-int-stack stack-addr
       print-int32-decimal screen, val
@@ -220,6 +231,7 @@ fn render-column screen: (addr screen), first-word: (addr word), final-word: (ad
     }
     reset-formatting screen
     curr-row <- increment
+    stack-index <- increment
     stack-remaining <- decrement
     loop
   }
@@ -246,6 +258,29 @@ fn render-column screen: (addr screen), first-word: (addr word), final-word: (ad
   right-col <- add 3  # margin-right
 }
 
+# gotcha: returns true by default
+fn next-word-is-number? _w: (addr word) -> result/eax: boolean {
+$next-word-is-operator?:body: {
+  var w/esi: (addr word) <- copy _w
+  var next-ah/eax: (addr handle word) <- get w, next
+  var next/eax: (addr word) <- lookup *next-ah
+  compare next, 0
+  {
+    break-if-!=
+    result <- copy 1  # true
+    break $next-word-is-operator?:body
+  }
+  var first-grapheme/eax: grapheme <- first-grapheme next
+  compare first-grapheme, -1
+  {
+    break-if-!=
+    result <- copy 1  # true
+    break $next-word-is-operator?:body
+  }
+  result <- is-decimal-digit? first-grapheme
+}
+}
+
 # We could be a little faster by not using 'first-word' (since max is commutative),
 # but this way the code follows the pattern of 'render'. Let's see if that's a net win.
 fn compute-max-depth _env: (addr environment) -> result/eax: int {
diff --git a/apps/tile/gap-buffer.mu b/apps/tile/gap-buffer.mu
index 3d001cf6..9527fac3 100644
--- a/apps/tile/gap-buffer.mu
+++ b/apps/tile/gap-buffer.mu
@@ -169,6 +169,40 @@ fn gap-index _self: (addr gap-buffer) -> result/eax: int {
   result <- copy *top-addr
 }
 
+fn first-grapheme-in-gap-buffer _self: (addr gap-buffer) -> result/eax: grapheme {
+$first-grapheme-in-gap-buffer:body: {
+  var self/esi: (addr gap-buffer) <- copy _self
+  # try to read from left
+  var left/eax: (addr grapheme-stack) <- get self, left
+  var top-addr/ecx: (addr int) <- get left, top
+  compare *top-addr, 0
+  {
+    break-if-<=
+    var data-ah/eax: (addr handle array grapheme) <- get left, data
+    var data/eax: (addr array grapheme) <- lookup *data-ah
+    var result-addr/eax: (addr grapheme) <- index data, 0
+    result <- copy *result-addr
+    break $first-grapheme-in-gap-buffer:body
+  }
+  # try to read from right
+  var right/eax: (addr grapheme-stack) <- get self, right
+  top-addr <- get right, top
+  compare *top-addr, 0
+  {
+    break-if-<=
+    var data-ah/eax: (addr handle array grapheme) <- get right, data
+    var data/eax: (addr array grapheme) <- lookup *data-ah
+    var top/ecx: int <- copy *top-addr
+    top <- decrement
+    var result-addr/eax: (addr grapheme) <- index data, top
+    result <- copy *result-addr
+    break $first-grapheme-in-gap-buffer:body
+  }
+  # give up
+  result <- copy -1
+}
+}
+
 fn delete-before-gap _self: (addr gap-buffer) {
   var self/eax: (addr gap-buffer) <- copy _self
   var left/eax: (addr grapheme-stack) <- get self, left
diff --git a/apps/tile/word.mu b/apps/tile/word.mu
index 07e5280f..70c2eafb 100644
--- a/apps/tile/word.mu
+++ b/apps/tile/word.mu
@@ -92,6 +92,12 @@ fn final-word _self: (addr word) -> result/eax: (addr word) {
   result <- copy out
 }
 
+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
+  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