Commit Graph

33 Commits

Author SHA1 Message Date
Kartik K. Agaram 24a6f99107 failing tests not printing since show-stack-state 2021-04-25 22:08:00 -07:00
Kartik K. Agaram 6e0f0bdf50 . 2021-04-25 22:00:00 -07:00
Kartik K. Agaram 7a7191cc3e clean up with the final bugfix 2021-04-22 09:09:23 -07:00
Kartik K. Agaram bd0410c993 snapshot
It took me _way_ too long to realize that I'm not checking for errors within
the loop, and that will cause it to manifest as an infinite loop as inner
evaluations fail to run.

Debugging notes, for posterity:
  printing one row of a chessboard pattern over fake screen (chessboard screen 4 0 0 15) gets stuck in an infinite loop halfway through
    debug pattern during infinite loop: VWEX. It's still in the loop but it's not executing the body
    raw (fill_rect screen 16 0 20 4 15) works fine
    same number of calls to fill_rect work fine
    replacing calls to fill_rect with pixel inside chessboard2 works fine
    at the point of the infinite loop it's repeatedly going through the hline loop
      -- BUT it never executes the check of the loop (< lo hi) with lo=20, hi=20. Something is returning 1, but it's not inside <
    stream optimization is not implicated

  simple test case with a single loop
    (
      (globals . (
        (foo . (fn () (screen i n)
                 (while (< i n)
                   (pixel screen 4 4 i)
                   (pixel screen 5 4 i)
                   (pixel screen 6 4 i)
                   (pixel screen 7 4 i)
                   (set i (+ i 1)))))
      ))
      (sandbox . (foo screen 0 100))
    )

  simpler (if you reset cursor position before every print):
    (
      (globals . (
        (foo . (fn () (screen i n)
                 (while (< i n)
                   (print screen i)
                   (set i (+ i 1)))))
      ))
      (sandbox . (foo screen 0 210))
    )

  I now believe it has nothing to do with the check. The check always works.
  Sometimes no body is evaluated. And so the set has no effect.
2021-04-22 09:05:11 -07:00
Kartik K. Agaram 4afe53d834 shell: non-recursive 'while' 2021-04-21 21:34:55 -07:00
Kartik K. Agaram a5e1a220fd shell: refuse to 'def' duplicate names 2021-04-21 20:54:18 -07:00
Kartik K. Agaram c54b7e9630 shell: separate 'def' from 'set'
'def' creates new bindings (only in globals)
'set' only modifies existing bindings (either in env or globals)
2021-04-21 20:53:38 -07:00
Kartik K. Agaram bfc6fa1876 slightly more responsive animation 2021-04-21 20:12:16 -07:00
Kartik K. Agaram d27994a9d7 shell: show screen state during evaluation
All highly experimental. Current constraints:

* No tail recursion elimination
* No heap reuse
* Keep implementation simple

So it's slow, and I don't want to complicate it to speed it up. So I'm
investing in affordances to help deal with the slowness. However, in the
process I've taken the clean abstraction of a trace ("all you need to do
is add to the trace") and bolted on call counts and debug-prints as independent
mechanisms.
2021-04-21 00:25:06 -07:00
Kartik K. Agaram 7b2d39b8d4 an interface approximating stack traces 2021-04-20 23:27:13 -07:00
Kartik K. Agaram fb34909b4e get bresenham line drawing working with a trace
(brline . (fn () (screen x0 y0 x1 y1 color)
                 ((fn (dx dy sx sy)
                    ((fn (err)
                       (brline1 screen x0 y0 x1 y1 dx dy sx sy err color))
                     (+ dx dy)))
                  (abs (- x1 x0))
                  (- 0 (abs (- y1 y0)))
                  (sgn (- x1 x0))
                  (sgn (- y1 y0)))))
    (brline1 . (fn () (screen x y xmax ymax dx dy sx sy err color)
                 (pixel screen x y color)
                 (if (andf (= x xmax) (= y ymax))
                   ()
                   ((fn (e2)
                      (brline1 screen
                        (if (>= e2 dy)
                          (+ x sx)
                          x)
                        (if (<= e2 dx)
                          (+ y sy)
                          y)
                        xmax
                        ymax
                        dx
                        dy
                        sx
                        sy
                        (+ err
                           (+
                             (if (>= e2 dy)
                               dy
                               0)
                             (if (<= e2 dx)
                               dx
                               0)))
                        color))
                    (* err 2)))))

sandbox: (brline screen 1 1 5 5 12)

There are two ideas stemming from this commit:
  - I need an extremely compact on-screen trace to underlie the trace UX
  - perhaps we should start truncating trace lines
2021-04-20 19:47:57 -07:00
Kartik K. Agaram fb3967876c deemphasize fn arg evaluation slightly 2021-04-19 21:19:56 -07:00
Kartik K. Agaram d94821d301 some primitives for monitoring code integrity 2021-04-18 11:56:10 -07:00
Kartik K. Agaram 97df52bf2f shell: ctrl-r runs on real screen without a trace
We run out of memory fairly early in the course of drawing a chessboard
on the whole screen.
2021-04-17 23:52:52 -07:00
Kartik K. Agaram c026dba006 shell: reenable the trace
We now have a couple of protections:
  - if we get close to running out of space in the trace we drop in an
    error
  - if we run out of space in the trace we stop trying to append
  - if there are errors we cancel future evaluations

This is already much nicer. You can't do much on the Mu computer, but at
least it gracefully gives up and shows its limitations. On my computer
the Mu shell tries to run computations for about 20s before giving up.
That seems at the outer limit of what interactivity supports. If things
take too long, test smaller chunks.
2021-04-17 22:33:28 -07:00
Kartik K. Agaram 60cab88ace evaluating fns is too similar to its input
When I edit disk images directly, it's easy to forget a pair of parens.
Then the first expression of the body never executes.
2021-04-17 20:58:36 -07:00
Kartik K. Agaram 5908943f47 Bresenham line-drawing now working
I can't run tests right now, and the trace is disabled. Still, progress.

https://merveilles.town/@akkartik/106081486035689980

Current state of the disk image:
  (
    (globals . (
      (hline1 . (fn () (screen y lo hi)
                  (if (>= lo hi)
                    ()
                    ((fn ()
                       (pixel screen lo y 12)
                       (hline1 screen y (+ lo 1) hi))))))
      (vline1 . (fn () (screen x lo hi)
                  (if (>= lo hi)
                    ()
                    ((fn ()
                       (pixel screen x lo 12)
                       (vline1 screen x (+ lo 1) hi))))))
      (hline . (fn () (screen y)
                 (hline1 screen y 0 (width screen))))
      (vline . (fn () (screen y)
                 (vline1 screen y 0 (height screen))))
      (andf . (fn () (a b)
                (if a
                  (if b
                    1
                    ())
                  ())))
      (brline . (fn () (screen x0 y0 x1 y1)
                   ((fn (dx dy sx sy)
                      ((fn (err)
                         (brline1 screen x0 y0 x1 y1 dx dy sx sy err))
                       (+ dx dy)))
                    (abs (- x1 x0))
                    (- 0 (abs (- y1 y0)))
                    (sgn (- x1 x0))
                    (sgn (- y1 y0)))))
      (brline1 . (fn () (screen x y xmax ymax dx dy sx sy err)
                   (pixel screen x y 12)
                   (if (andf (= x xmax) (= y ymax))
                     ()
                     ((fn (e2)
                        (brline1 screen
                          (if (>= e2 dy)
                            (+ x sx)
                            x)
                          (if (<= e2 dx)
                            (+ y sy)
                            y)
                          xmax
                          ymax
                          dx
                          dy
                          sx
                          sy
                          (+ err
                             (+
                               (if (>= e2 dy)
                                 dy
                                 0)
                               (if (<= e2 dx)
                                 dx
                                 0)))))
                      (* err 2)))))
    ))
    (sandbox . (brline screen 1 1 5 5))
  )
2021-04-17 09:01:22 -07:00
Kartik K. Agaram 1a74c3a1e6 loosening a few more buffers
Mu computer now has more code in it:

  (
    (globals . (
      (hline1 . (fn () (screen y lo hi) (if (>= lo hi) () ((fn () (pixel screen lo y 12) (hline1 screen y (+ lo 1) hi))))))
      (vline1 . (fn () (screen x lo hi) (if (>= lo hi) () ((fn () (pixel screen x lo 12) (vline1 screen x (+ lo 1) hi))))))
      (hline . (fn () (screen y) (hline1 screen y 0 (width screen))))
      (vline . (fn () (screen y) (vline1 screen y 0 (height screen))))
      (andf . (fn (a b)
                (if a
                  (if b
                    1
                    ())
                  ())))
      (brline . (fn (screen x0 y0 x1 y1)
                   ((fn (dx dy sx sy)
                      ((fn (err)
                         (brline1 screen x0 y0 x1 y1 dx dy sx sy err))
                       (+ dx dy)))
                    (abs (- x1 x0))
                    (- 0 (abs (- y1 y0)))
                    (sgn (- x1 x0))
                    (sgn (- y1 y0)))))
      (brline1 . (fn (screen x y xmax ymax dx dy sx sy err)
                   (pixel screen x y 12)
                   (if (andf (= x xmax) (= y ymax))
                     ()
                     ((fn (e2)
                        (brline1 screen
                          (if (>= e2 dy)
                            (+ x sx)
                            x)
                          (if (<= e2 dx)
                            (+ y sy)
                            y)
                          xmax
                          ymax
                          dx
                          dy
                          sx
                          sy
                          (+ err
                             (+
                               (if (>= e2 dy)
                                 dy
                                 0)
                               (if (<= e2 dx)
                                 dx
                                 0)))))
                      (* err 2)))))
    ))
    (sandbox . (brline screen 1 1 5 5))
  )
2021-04-17 08:29:43 -07:00
Kartik K. Agaram 21a6f5539b data.img now has more than one sector of data 2021-04-16 20:26:56 -07:00
Kartik K. Agaram 6392f1fde9 first session programming _within_ the Mu computer
I tried building a function to draw a horizontal line across the screen.
Here's what I have in data.txt:

  (
    (globals . (
      (horline . (fn () (screen y)
                    (horline_1 screen y 0 (width screen))))
      (horline_1 . (fn () (screen y lo hi)
                      (if (>= lo hi)
                        ()
                        ((fn ()
                          (pixel screen lo y 12)
                          (horline_1 screen y (+ lo 1) hi))))))
    ))
    (sandbox . (horline_1 screen 0 0 20))
  )

$ dd if=/dev/zero of=data.img count=20160
$ cat data.txt |dd of=data.img conv=notrunc
$ ./translate shell/*.mu  &&  qemu-system-i386 -hda disk.img -hdb data.img

Result: I can't call (horline screen 0) over a fake screen of width 40.
Some stream overflows somewhere after all the tweaks to various fixed-size
buffers scattered throughout the app. Calling horline_1 gets to a 'hi'
column of 20, but not to 30.
2021-04-15 22:56:59 -07:00
Kartik K. Agaram fea45ccbea shell: full closures 2021-04-10 23:47:19 -07:00
Kartik K. Agaram 12569711c9 apply doesn't need caller env in lexical scope 2021-04-10 23:38:23 -07:00
Kartik K. Agaram 1c4e8fe775 shell: none of our primitives need to be closures 2021-04-10 23:32:38 -07:00
Kartik K. Agaram f38c2a1502 . 2021-04-10 22:38:02 -07:00
Kartik K. Agaram 770cac9412 shell: UI now showing fake keyboard
But we don't actually support fake keyboards anywhere yet.
2021-04-10 21:20:46 -07:00
Kartik K. Agaram 400574f956 shell: move fake screen to sandbox 2021-04-10 20:44:26 -07:00
Kartik K. Agaram 1d724f9260 shell: structural equality check
Mu can now compute (factorial 5)
2021-04-09 22:51:24 -07:00
Kartik K. Agaram b3c6dddcd4 shell: if 2021-04-09 22:21:00 -07:00
Kartik K. Agaram 7032a92cf2 shell: 'set' for defining globals
Currently stateful, but still good for things.
2021-04-06 10:00:23 -07:00
Kartik K. Agaram 26a1849895 shell: quote 2021-04-06 09:40:13 -07:00
Kartik K. Agaram b9656ea881 shell: look up globals 2021-04-06 07:51:56 -07:00
Kartik K. Agaram 0db683ffdb shell: extensible array of globals
I'm not bothering with full dynamic scope for now.
2021-04-05 23:55:13 -07:00
Kartik K. Agaram 8a31a087b0 . 2021-04-05 19:41:46 -07:00