about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-07-05 18:12:07 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-07-05 18:12:07 -0700
commitc7bedaf49b438977cee3398f87910ae8047f8ec0 (patch)
tree5f58f640101564d8123164a74159f8cd8a2356a1
parent5d8a858a6f0bbaaec13c39b503b8e180f11c5d6c (diff)
downloadmu-c7bedaf49b438977cee3398f87910ae8047f8ec0.tar.gz
replace 'vline' with Mu implementation
-rw-r--r--shell/data.limg6
-rw-r--r--shell/primitives.mu162
2 files changed, 162 insertions, 6 deletions
diff --git a/shell/data.limg b/shell/data.limg
index e4a5c8cb..c9c00dbc 100644
--- a/shell/data.limg
+++ b/shell/data.limg
@@ -122,14 +122,10 @@
      (while ,test
        ,@body
        ,update))])
-    (vline1 . [def (vline1 screen x y ymax color)
-  while (y < ymax)
-    (pixel screen x y color)
-    ++y])
     (hborder . [def (hborder scr y color)
   (hline scr y 0 (width scr) color)])
     (vborder . [def (vborder scr x color)
-  (vline1 scr x 0 (height scr) color)])
+  (vline scr x 0 (height scr) color)])
     (read_line . [def (read_line keyboard)
   ret str (stream)
     let c (key keyboard)
diff --git a/shell/primitives.mu b/shell/primitives.mu
index 6458684c..c8ded193 100644
--- a/shell/primitives.mu
+++ b/shell/primitives.mu
@@ -40,6 +40,7 @@ fn initialize-primitives _self: (addr global-table) {
   append-primitive self, "pixel"
   append-primitive self, "line"
   append-primitive self, "hline"
+  append-primitive self, "vline"
   append-primitive self, "width"
   append-primitive self, "height"
   # for keyboards
@@ -127,7 +128,7 @@ fn render-primitives screen: (addr screen), xmin: int, xmax: int, ymax: int {
   tmpx <- draw-text-rightward screen, "pixel graphics", tmpx, left-max, y, 7/fg=grey, 0xdc/bg=green-bg
   y <- increment
   var tmpx/eax: int <- copy xmin
-  tmpx <- draw-text-rightward screen, "  line hline pixel", tmpx, left-max, y, 0x2a/fg=orange, 0xdc/bg=green-bg
+  tmpx <- draw-text-rightward screen, "  line hline vline pixel", tmpx, left-max, y, 0x2a/fg=orange, 0xdc/bg=green-bg
   y <- increment
   var tmpx/eax: int <- copy xmin
   tmpx <- draw-text-rightward screen, "  width height", tmpx, left-max, y, 0x2a/fg=orange, 0xdc/bg=green-bg
@@ -449,6 +450,13 @@ fn apply-primitive _f: (addr cell), args-ah: (addr handle cell), out: (addr hand
     return
   }
   {
+    var vline?/eax: boolean <- string-equal? f-name, "vline"
+    compare vline?, 0/false
+    break-if-=
+    apply-vline args-ah, out, trace
+    return
+  }
+  {
     var width?/eax: boolean <- string-equal? f-name, "width"
     compare width?, 0/false
     break-if-=
@@ -2279,6 +2287,158 @@ fn apply-hline _args-ah: (addr handle cell), out: (addr handle cell), trace: (ad
   # return nothing
 }
 
+fn apply-vline _args-ah: (addr handle cell), out: (addr handle cell), trace: (addr trace) {
+  trace-text trace, "eval", "apply 'vline'"
+  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
+  {
+    var args-type/eax: (addr int) <- get args, type
+    compare *args-type, 0/pair
+    break-if-=
+    error trace, "args to 'vline' are not a list"
+    return
+  }
+  var empty-args?/eax: boolean <- nil? args
+  compare empty-args?, 0/false
+  {
+    break-if-=
+    error trace, "'vline' needs 5 args 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/eax: (addr int) <- get first, type
+    compare *first-type, 5/screen
+    break-if-=
+    error trace, "first arg for 'vline' 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/edi: (addr screen) <- copy _screen
+  # x = args->right->left->value
+  var rest-ah/eax: (addr handle cell) <- get args, right
+  var _rest/eax: (addr cell) <- lookup *rest-ah
+  var rest/esi: (addr cell) <- copy _rest
+  {
+    var rest-type/eax: (addr int) <- get rest, type
+    compare *rest-type, 0/pair
+    break-if-=
+    error trace, "'vline' encountered non-pair"
+    return
+  }
+  {
+    var rest-nil?/eax: boolean <- nil? rest
+    compare rest-nil?, 0/false
+    break-if-=
+    error trace, "'vline' needs 5 args but got 1"
+    return
+  }
+  var second-ah/eax: (addr handle cell) <- get rest, left
+  var second/eax: (addr cell) <- lookup *second-ah
+  {
+    var second-type/eax: (addr int) <- get second, type
+    compare *second-type, 1/number
+    break-if-=
+    error trace, "second arg for 'vline' is not a number (screen x coordinate)"
+    return
+  }
+  var second-value/eax: (addr float) <- get second, number-data
+  var x/edx: int <- convert *second-value
+  # y1 = rest->right->left->value
+  var rest-ah/eax: (addr handle cell) <- get rest, right
+  var _rest/eax: (addr cell) <- lookup *rest-ah
+  rest <- copy _rest
+  {
+    var rest-type/eax: (addr int) <- get rest, type
+    compare *rest-type, 0/pair
+    break-if-=
+    error trace, "'vline' encountered non-pair"
+    return
+  }
+  {
+    var rest-nil?/eax: boolean <- nil? rest
+    compare rest-nil?, 0/false
+    break-if-=
+    error trace, "'vline' needs 5 args but got 2"
+    return
+  }
+  var third-ah/eax: (addr handle cell) <- get rest, left
+  var third/eax: (addr cell) <- lookup *third-ah
+  {
+    var third-type/eax: (addr int) <- get third, type
+    compare *third-type, 1/number
+    break-if-=
+    error trace, "third arg for 'vline' is not a number (screen y coordinate of start point)"
+    return
+  }
+  var third-value/eax: (addr float) <- get third, number-data
+  var y1/ebx: int <- convert *third-value
+  # y2 = rest->right->left->value
+  var rest-ah/eax: (addr handle cell) <- get rest, right
+  var _rest/eax: (addr cell) <- lookup *rest-ah
+  var rest/esi: (addr cell) <- copy _rest
+  {
+    var rest-type/eax: (addr int) <- get rest, type
+    compare *rest-type, 0/pair
+    break-if-=
+    error trace, "'vline' encountered non-pair"
+    return
+  }
+  {
+    var rest-nil?/eax: boolean <- nil? rest
+    compare rest-nil?, 0/false
+    break-if-=
+    error trace, "'vline' needs 5 args but got 3"
+    return
+  }
+  var fourth-ah/eax: (addr handle cell) <- get rest, left
+  var fourth/eax: (addr cell) <- lookup *fourth-ah
+  {
+    var fourth-type/eax: (addr int) <- get fourth, type
+    compare *fourth-type, 1/number
+    break-if-=
+    error trace, "fourth arg for 'vline' is not a number (screen y coordinate of end point)"
+    return
+  }
+  var fourth-value/eax: (addr float) <- get fourth, number-data
+  var y2/ecx: int <- convert *fourth-value
+  # color = rest->right->left->value
+  var rest-ah/eax: (addr handle cell) <- get rest, right
+  var _rest/eax: (addr cell) <- lookup *rest-ah
+  rest <- copy _rest
+  {
+    var rest-type/eax: (addr int) <- get rest, type
+    compare *rest-type, 0/pair
+    break-if-=
+    error trace, "'vline' encountered non-pair"
+    return
+  }
+  {
+    var rest-nil?/eax: boolean <- nil? rest
+    compare rest-nil?, 0/false
+    break-if-=
+    error trace, "'vline' needs 5 args but got 5"
+    return
+  }
+  var fifth-ah/eax: (addr handle cell) <- get rest, left
+  var fifth/eax: (addr cell) <- lookup *fifth-ah
+  {
+    var fifth-type/eax: (addr int) <- get fifth, type
+    compare *fifth-type, 1/number
+    break-if-=
+    error trace, "fifth arg for 'vline' is not an int (color; 0..0xff)"
+    return
+  }
+  var fifth-value/eax: (addr float) <- get fifth, number-data
+  var color/eax: int <- convert *fifth-value
+  draw-vertical-line screen, x, y1, y2, color
+  # return nothing
+}
+
 fn apply-wait-for-key _args-ah: (addr handle cell), out: (addr handle cell), trace: (addr trace) {
   trace-text trace, "eval", "apply 'key'"
   var args-ah/eax: (addr handle cell) <- copy _args-ah