about summary refs log tree commit diff stats
path: root/apps/tile
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-10-19 23:13:28 -0700
committerKartik Agaram <vc@akkartik.com>2020-10-19 23:13:28 -0700
commit5e9a4821933db50a1de7950bc64f4a84c5176938 (patch)
tree3dbc091d11426e4bceeb7708ff1453d6d3547092 /apps/tile
parent5532ea013b6ee7f7aeda72d2ed592b7aa246a5f2 (diff)
downloadmu-5e9a4821933db50a1de7950bc64f4a84c5176938.tar.gz
7077 - tile: render function list
Diffstat (limited to 'apps/tile')
-rw-r--r--apps/tile/environment.mu39
-rw-r--r--apps/tile/word.mu26
2 files changed, 53 insertions, 12 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index 1017edd5..d1d231dd 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -1250,18 +1250,33 @@ fn clear-canvas _env: (addr environment) {
   reset-formatting screen
   print-string screen, " define function  "
   # currently defined functions
-  move-cursor screen, 3, 2
-  print-string screen, "x 2* = x 2 *"
-  move-cursor screen, 4, 2
-  print-string screen, "x 1+ = x 1 +"
-  move-cursor screen, 5, 2
-  print-string screen, "x 2+ = x 1+ 1+"
-  move-cursor screen, 6, 2
-  print-string screen, "x square = x x *"
-  move-cursor screen, 7, 2
-  print-string screen, "x 1- = x 1 -"
-  move-cursor screen, 8, 2
-  print-string screen, "x y sub = x y -"
+  var row/ecx: int <- copy 3
+  var functions/esi: (addr handle function) <- get env, functions
+  {
+    var curr/eax: (addr function) <- lookup *functions
+    compare curr, 0
+    break-if-=
+    move-cursor screen, row, 2
+    render-function screen, curr
+    functions <- get curr, next
+    row <- increment
+    loop
+  }
+}
+
+# only single-line functions supported for now
+fn render-function screen: (addr screen), _f: (addr function) {
+  var f/esi: (addr function) <- copy _f
+  var args/ecx: (addr handle word) <- get f, args
+  print-words-in-reverse screen, args
+  var name-ah/eax: (addr handle array byte) <- get f, name
+  var name/eax: (addr array byte) <- lookup *name-ah
+  print-string screen, name
+  print-string screen, " = "
+  var body-ah/eax: (addr handle line) <- get f, body
+  var body/eax: (addr line) <- lookup *body-ah
+  var body-words-ah/eax: (addr handle word) <- get body, data
+  print-words screen, body-words-ah
 }
 
 fn real-grapheme? g: grapheme -> result/eax: boolean {
diff --git a/apps/tile/word.mu b/apps/tile/word.mu
index b8b9f7c0..d630b176 100644
--- a/apps/tile/word.mu
+++ b/apps/tile/word.mu
@@ -238,6 +238,32 @@ fn print-word screen: (addr screen), _self: (addr word) {
   render-gap-buffer screen, data
 }
 
+fn print-words screen: (addr screen), _words-ah: (addr handle word) {
+  var words-ah/eax: (addr handle word) <- copy _words-ah
+  var words-a/eax: (addr word) <- lookup *words-ah
+  compare words-a, 0
+  break-if-=
+  # print
+  print-word screen, words-a
+  print-string screen, " "
+  # recurse
+  var next-ah/eax: (addr handle word) <- get words-a, next
+  print-words screen, next-ah
+}
+
+fn print-words-in-reverse screen: (addr screen), _words-ah: (addr handle word) {
+  var words-ah/eax: (addr handle word) <- copy _words-ah
+  var words-a/eax: (addr word) <- lookup *words-ah
+  compare words-a, 0
+  break-if-=
+  # recurse
+  var next-ah/ecx: (addr handle word) <- get words-a, next
+  print-words screen, next-ah
+  # print
+  print-word screen, words-a
+  print-string screen, " "
+}
+
 # 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