about summary refs log tree commit diff stats
path: root/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-07-26 02:27:32 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-07-26 02:27:32 -0700
commit46441d7204cb14e14bc25ff3c43a912281035a1c (patch)
tree615ee983f8c6ed7b62dc6d7c8e66bd6fe38d21dc /shell
parent81c3678515e9fe848daeec129918a7baf929bf96 (diff)
downloadmu-46441d7204cb14e14bc25ff3c43a912281035a1c.tar.gz
.
Smoked out some issues by rendering a single frame of Game of Life.
Incredibly slow.
Diffstat (limited to 'shell')
-rw-r--r--shell/data.limg35
-rw-r--r--shell/primitives.mu13
2 files changed, 39 insertions, 9 deletions
diff --git a/shell/data.limg b/shell/data.limg
index a0dc33c7..88e81da6 100644
--- a/shell/data.limg
+++ b/shell/data.limg
@@ -66,10 +66,6 @@
       (list (list (car xs)))
       (cons (list (car xs) (cadr xs))
             (pair (cddr xs)))])
-    (grid . [def (grid m n val)
-  ret g (populate n ())
-    for i 0 (< i n) ++i
-      iset g i (populate m val)])
     (with . [mac (with bindings . body)
   `((fn ,(map1 car (pair bindings))
       ,@body)
@@ -124,6 +120,14 @@
      (while ,test
        ,@body
        ,update))])
+    (grid . [def (grid m n val)
+  ret g (populate n ())
+    for i 0 (< i n) ++i
+      iset g i (populate m val)])
+    (indexgrid . [def (indexgrid g x y)
+  (index (index g y) x)])
+    (isetgrid . [def (isetgrid g x y val)
+  iset (index g y) x val])
     (hborder . [def (hborder scr y color)
   (hline scr y 0 (width scr) color)])
     (vborder . [def (vborder scr x color)
@@ -162,6 +166,27 @@
         (pixel screen x y (palette Greys x*y))])
     (main . [def (main screen keyboard)
   (pat screen)])
+    (lifreres . [define liferes 8])
+    (life . [def (life screen)
+  let g (grid (/ (width screen) liferes)
+              (/ (height screen) liferes)
+              0)
+    isetgrid g 5 5 1
+    isetgrid g 6 5 1
+    isetgrid g 4 6 1
+    isetgrid g 5 6 1
+    isetgrid g 5 7 1
+    while 1
+      steplife g
+      renderlife screen g])
+    (steplife . [def (steplife g)
+  ])
+    (renderlife . [def (renderlife screen g)
+  with (w (width screen)
+        h (height screen))
+    for y 0 (< y h) ++y
+      for x 0 (< x w) ++x
+        (pixel screen x y (indexgrid g x/liferes y/liferes))])
   ))
-  (sandbox . [pat screen])
+  (sandbox . [life screen])
 )
diff --git a/shell/primitives.mu b/shell/primitives.mu
index daf62fe4..b511cc01 100644
--- a/shell/primitives.mu
+++ b/shell/primitives.mu
@@ -3641,14 +3641,19 @@ fn apply-index _args-ah: (addr handle cell), out: (addr handle cell), trace: (ad
     return
   }
   var second-value/eax: (addr float) <- get second, number-data
-  var index/edx: int <- convert *second-value
+  var index/edx: int <- truncate *second-value
   var data-ah/eax: (addr handle array handle cell) <- get first, array-data
   var data/eax: (addr array handle cell) <- lookup *data-ah
   {
     var len/eax: int <- length data
     compare index, len
     break-if-<
-    error trace, "too few elements in array"
+    error trace, "index: too few elements in array"
+    compare index, len
+    {
+      break-if-<=
+      error trace, "foo"
+    }
     return
   }
   var offset/edx: (offset handle cell) <- compute-offset data, index
@@ -3716,13 +3721,13 @@ fn apply-iset _args-ah: (addr handle cell), out: (addr handle cell), trace: (add
     return
   }
   var second-value/eax: (addr float) <- get second, number-data
-  var idx/eax: int <- convert *second-value
+  var idx/eax: int <- truncate *second-value
   # offset based on idx after bounds check
   var max/edx: int <- length array
   compare idx, max
   {
     break-if-<
-    error trace, "too few elements in array"
+    error trace, "iset: too few elements in array"
     return
   }
   var offset/edx: (offset handle cell) <- compute-offset array, idx