about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--shell/global.mu38
1 files changed, 38 insertions, 0 deletions
diff --git a/shell/global.mu b/shell/global.mu
index f341be99..46c43234 100644
--- a/shell/global.mu
+++ b/shell/global.mu
@@ -30,6 +30,7 @@ fn initialize-globals _self: (addr global-table) {
   append-primitive self, "cons"
   # for screens
   append-primitive self, "print"
+  append-primitive self, "clear"
   append-primitive self, "lines"
   append-primitive self, "columns"
   append-primitive self, "up"
@@ -473,6 +474,13 @@ fn apply-primitive _f: (addr cell), args-ah: (addr handle cell), out: (addr hand
     return
   }
   {
+    var is-clear?/eax: boolean <- string-equal? f-name, "clear"
+    compare is-clear?, 0/false
+    break-if-=
+    apply-clear args-ah, out, trace
+    return
+  }
+  {
     var is-lines?/eax: boolean <- string-equal? f-name, "lines"
     compare is-lines?, 0/false
     break-if-=
@@ -1126,6 +1134,36 @@ fn apply-print _args-ah: (addr handle cell), out: (addr handle cell), trace: (ad
   copy-object second-ah, out
 }
 
+fn apply-clear _args-ah: (addr handle cell), out: (addr handle cell), trace: (addr trace) {
+  trace-text trace, "eval", "apply clear"
+  var args-ah/eax: (addr handle cell) <- copy _args-ah
+  var _args/eax: (addr cell) <- lookup *args-ah
+  var args/esi: (addr cell) <- copy _args
+  # TODO: check that args is a pair
+  var empty-args?/eax: boolean <- nil? args
+  compare empty-args?, 0/false
+  {
+    break-if-=
+    error trace, "'clear' needs 1 arg but got 0"
+    return
+  }
+  # screen = args->left
+  var first-ah/eax: (addr handle cell) <- get args, left
+  var first/eax: (addr cell) <- lookup *first-ah
+  var first-type/ecx: (addr int) <- get first, type
+  compare *first-type, 5/screen
+  {
+    break-if-=
+    error trace, "first arg for 'clear' is not a screen"
+    return
+  }
+  var screen-ah/eax: (addr handle screen) <- get first, screen-data
+  var _screen/eax: (addr screen) <- lookup *screen-ah
+  var screen/ecx: (addr screen) <- copy _screen
+  #
+  clear-screen screen
+}
+
 fn apply-up _args-ah: (addr handle cell), out: (addr handle cell), trace: (addr trace) {
   trace-text trace, "eval", "apply up"
   var args-ah/eax: (addr handle cell) <- copy _args-ah