about summary refs log tree commit diff stats
path: root/apps/tile/environment.mu
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-10-09 23:43:24 -0700
committerKartik Agaram <vc@akkartik.com>2020-10-09 23:43:24 -0700
commitf864cf0874147a1613960d6f799ec2c764faa482 (patch)
treeded0e6e6a17159591a6e4a61c05ecd3591d671f1 /apps/tile/environment.mu
parent5b7ccbc8f4f16a1c104f3415cccbdf5cce55727f (diff)
downloadmu-f864cf0874147a1613960d6f799ec2c764faa482.tar.gz
6986
Cursor now stays on the right row as we bounce in and out of function calls.
Diffstat (limited to 'apps/tile/environment.mu')
-rw-r--r--apps/tile/environment.mu24
1 files changed, 23 insertions, 1 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index cbbae239..71da0ddc 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -413,7 +413,29 @@ fn render-sandbox screen: (addr screen), functions: (addr handle function), bind
   allocate curr-path  # leak
 #?   print-string 0, "==\n"
   var dummy/ecx: int <- render-line screen, functions, 0, line, expanded-words, 3, left-col, curr-path, cursor-word, cursor-col-a  # input-row=3
-  move-cursor screen, 3, cursor-col  # input-row
+  var cursor-row/eax: int <- call-depth-at-cursor _sandbox
+  move-cursor screen, cursor-row, cursor-col
+}
+
+fn call-depth-at-cursor _sandbox: (addr sandbox) -> result/eax: int {
+  var sandbox/esi: (addr sandbox) <- copy _sandbox
+  var cursor-call-path/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path
+  result <- call-path-element-length cursor-call-path
+  result <- add 2  # input-row-1
+}
+
+fn call-path-element-length _x: (addr handle call-path-element) -> result/eax: int {
+  var curr-ah/ecx: (addr handle call-path-element) <- copy _x
+  var out/edi: int <- copy 0
+  {
+    var curr/eax: (addr call-path-element) <- lookup *curr-ah
+    compare curr, 0
+    break-if-=
+    curr-ah <- get curr, next
+    out <- increment
+    loop
+  }
+  result <- copy out
 }
 
 # Render the line of words in line, along with the state of the stack under each word.