Commit Graph

430 Commits

Author SHA1 Message Date
Kartik K. Agaram
150db8d56a some boot-time heartbeat messages
This will help us with some common debug scenarios.
2021-05-07 12:27:20 -07:00
Kartik K. Agaram
dd192dd52c . 2021-05-07 12:11:59 -07:00
Kartik K. Agaram
e42ae8219e clean up all definitions 2021-05-07 12:08:07 -07:00
Kartik K. Agaram
d605ba1f9a clean up chessboard
We still benefit from some helpers here because of the unrolling and multiple
calls to helpers.
2021-05-07 11:56:43 -07:00
Kartik K. Agaram
d8298d1a2a clean up read_line 2021-05-07 11:37:48 -07:00
Kartik K. Agaram
91f76e6b22 clean up Bresenham line-drawing 2021-05-07 11:28:59 -07:00
Kartik K. Agaram
25eb9c580e . 2021-05-07 11:02:55 -07:00
Kartik K. Agaram
92fb55d50f no, we need hline1 for fill_rect 2021-05-07 10:14:51 -07:00
Kartik K. Agaram
c651bbeffc clean up hline and vline 2021-05-07 10:05:20 -07:00
Kartik K. Agaram
74be534e2b starting to implement first macros
Another commit, another bugfix.

Some snippets from my currently exploding todo list:

- always investigate lookup errors immediately. Beyond the root cause, they should never happen at the moment, while we aren't reclaiming memory.
  we should always return a more precise error message. Usually involving null pointer checks.

- on abort, print out stack trace
  - emit mapping of labels to addresses during survey
  - store a mapping of symbols somewhere in the code image

- stop allocating 1KB per token; expand space for tokens as needed
2021-05-07 09:49:16 -07:00
Kartik K. Agaram
7105b73fd3 give up on nested backquotes for now 2021-05-07 09:22:54 -07:00
Kartik K. Agaram
f791cd9da9 macros almost done
Just one case left: macros within unquote.
2021-05-06 22:09:30 -07:00
Kartik K. Agaram
57fd40d500 some more cases 2021-05-06 21:41:03 -07:00
Kartik K. Agaram
a1cfadc749 first passing test for macroexpand
In the process I spent a long time tracking down a stray TODO in 108write.subx
that I thought would abort but didn't since the switch to baremetal.

Then after I reintroduced that assertion I had to go track down a bunch
of buffer sizes. Stream sizes continue to be a huge mess.
2021-05-06 21:38:02 -07:00
Kartik K. Agaram
7c8ad5a419 more paranoia in shell/globals.mu 2021-05-06 19:38:54 -07:00
Kartik K. Agaram
edae464db5 shell: macroexpand outermost call 2021-05-06 18:13:27 -07:00
Kartik K. Agaram
1648a04cc0 literal macros
Current plan:
- some way to define macros. For now:
    (def f (litmac litfn () (a b) `(+ ,a , b)))
- macroexpand will expand calls by passing them through the cdr
    (f 3 4)
    macroexpand: ((litfn () (a b) `(+ ,a ,b)) 3 4)
      => (+ 3 4)
    eval: (+ 3 4) => 7
2021-05-06 17:29:51 -07:00
Kartik K. Agaram
e9981404da . 2021-05-06 17:27:17 -07:00
Kartik K. Agaram
6df53d463c back to macros; switch macroexpand to operate in place 2021-05-06 17:00:18 -07:00
Kartik K. Agaram
a54c6f2ee7 belatedly migrate stale example definitions
Also bare-bones syntax highlighting for .limg files. Doesn't work when
.limg file is first file opened with Vim.
2021-05-06 16:42:08 -07:00
Kartik K. Agaram
effbe423a7 . 2021-05-06 15:10:56 -07:00
Kartik K. Agaram
ba5f556543 . 2021-05-04 20:20:03 -07:00
Kartik K. Agaram
5e0f459848 . 2021-05-04 20:09:07 -07:00
Kartik K. Agaram
0069028dae . 2021-05-04 20:00:03 -07:00
Kartik K. Agaram
9156823c5d shell: start implementing macros 2021-05-04 19:49:21 -07:00
Kartik K. Agaram
7465fbb19f . 2021-05-04 19:46:49 -07:00
Kartik K. Agaram
66c18fda1d shell: unquote splice 2021-05-04 04:28:04 -07:00
Kartik K. Agaram
bb9f4e4e1d shell: unquote 2021-05-04 03:53:00 -07:00
Kartik K. Agaram
de94891356 shell: start evaluating backquote 2021-05-03 21:01:50 -07:00
Kartik K. Agaram
1c69a13a88 . 2021-05-03 20:31:57 -07:00
Kartik K. Agaram
a08658f218 . 2021-05-03 18:16:15 -07:00
Kartik K. Agaram
1048729a6e . 2021-05-03 17:31:19 -07:00
Kartik K. Agaram
93f1bee02c reading and printing backquotes and unquotes 2021-05-03 12:02:12 -07:00
Kartik K. Agaram
71a04056a8 printing quoted expressions 2021-05-02 22:31:19 -07:00
Kartik K. Agaram
27691024c4 . 2021-05-02 22:25:47 -07:00
Kartik K. Agaram
83847e9f0a .
Clean up menus.
2021-05-01 16:20:44 -07:00
Kartik K. Agaram
d0e2d093f7 cleaner rendering of fake screens and keyboards
I don't understand why a second line in the keyboard is visible now where
it wasn't before. That whole aspect has unclear desires. What exactly do
I want to happen on newlines?
2021-05-01 16:12:49 -07:00
Kartik K. Agaram
719b6acf3d .
Use sandbox background in the top line on the right.
2021-05-01 15:54:02 -07:00
Kartik K. Agaram
c426cc0327 .
Clean up trace colors.
2021-05-01 15:49:48 -07:00
Kartik K. Agaram
2b616894fd move color scheme closer to Solarized dark
sed -i 's,0x12/bg=almost-black,0xdc/bg=green-bg,g' shell/*.mu
sed -i 's, 0/bg, 0xc5/bg=blue-bg,g' shell/*.mu
sed -i 's, 7/fg=trace, 0x38/fg=trace,g' shell/*.mu
sed -i 's, 7/bg=grey, 0x5c/bg=black,g' shell/*.mu

Still a few issues.

Thanks Adrian Cochrane and Zach DeCook.
  https://floss.social/@alcinnz/106152068473019933
  https://social.librem.one/@zachdecook/106159988837603417
2021-05-01 15:37:55 -07:00
Kartik K. Agaram
bf4c19f053 shell: squeeze menu 2021-04-30 00:00:55 -07:00
Kartik K. Agaram
3385febc11 shell: allow 'def' to overwrite 2021-04-29 23:53:28 -07:00
Kartik K. Agaram
d46c4b06b2 shell: comments 2021-04-29 23:48:36 -07:00
Kartik K. Agaram
24883b04f5 . 2021-04-29 23:43:17 -07:00
Kartik K. Agaram
772b7b6585 adjust fake screen aspect ratio for verisimilitude 2021-04-29 23:38:37 -07:00
Kartik K. Agaram
ca47215a6b keep the temporary progress screen off the keyboard 2021-04-29 20:38:18 -07:00
Kartik K. Agaram
24222b1735 make pixel borders of screen clear 2021-04-29 20:35:50 -07:00
Kartik K. Agaram
26eae87d3f make matching parens pop again 2021-04-29 16:47:26 -07:00
Kartik K. Agaram
c811754807 render definitions in 2 columns 2021-04-29 16:43:40 -07:00
Kartik K. Agaram
6503529627 white text everywhere by default 2021-04-29 16:27:43 -07:00
Kartik K. Agaram
5124feb31e tweak colors for definitions 2021-04-29 16:14:47 -07:00
Kartik K. Agaram
e13fd3e0a1 render in a narrow column 2021-04-29 16:11:23 -07:00
Kartik K. Agaram
05879d4f99 load large definitions 2021-04-29 16:10:30 -07:00
Kartik K. Agaram
b860f108f7 adjust some colors and padding 2021-04-29 15:10:17 -07:00
Kartik K. Agaram
dcb6a21a91 bugfix: initialize gap buffers before using them
I keep running into one hole in Mu's memory-safety since dropping the Linux
dependency: null pointers no longer error when dereferenced. Here the problem
manifests as aliasing: lots of gap buffers share the same exact data near
address 0, because it was never initialized.
2021-04-28 22:03:58 -07:00
Kartik K. Agaram
7fa356abef fix rendering 2021-04-28 17:54:02 -07:00
Kartik K. Agaram
b9c59a5f5b shell: load/store from/to disk with indent
Once I came up with the right approach, this worked on the first try once
I got the types and registers to line up!
2021-04-28 17:49:55 -07:00
Kartik K. Agaram
ef8dc999ca . 2021-04-28 17:08:15 -07:00
Kartik K. Agaram
d5d3e02ad4 shell: bugfix for stream literals
I was forgetting that callers sometimes reuse outputs between successive
tokens.
2021-04-28 16:34:40 -07:00
Kartik K. Agaram
9269234e46 start rendering definitions with indentation 2021-04-28 14:47:41 -07:00
Kartik K. Agaram
5b7f938733 start stashing and clearing sandbox after definitions 2021-04-28 13:55:10 -07:00
Kartik K. Agaram
e73f1a3b41 . 2021-04-28 12:21:51 -07:00
Kartik K. Agaram
a71ff2383a . 2021-04-28 09:45:39 -07:00
Kartik K. Agaram
55cde01edf shell: stream literals 2021-04-27 23:10:30 -07:00
Kartik K. Agaram
9e9e40c05a . 2021-04-27 23:04:20 -07:00
Kartik K. Agaram
409d26ca87 . 2021-04-27 23:03:23 -07:00
Kartik K. Agaram
6ecd9920ca shell: tokenizing stream (string) literals
We're calling them streams since they support appending.
2021-04-27 22:48:16 -07:00
Kartik K. Agaram
16f51dd76d . 2021-04-27 22:14:08 -07:00
Kartik Agaram
865f37aa9c . 2021-04-26 09:42:05 -07:00
Kartik K. Agaram
606c5681b7 bresenham circles
Known issue: circles of radius 9 crash. (Multiples of 9 overflow the trace.)
2021-04-25 22:33:26 -07:00
Kartik K. Agaram
7148f1222e bug in bresenham lines 2021-04-25 22:20:57 -07:00
Kartik K. Agaram
891083c44d shell: primitives 'and' and 'or' 2021-04-25 22:19:00 -07:00
Kartik K. Agaram
bd9c1e6a79 shell: primitive 'not' 2021-04-25 22:09:51 -07:00
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
ffe36c4050 . 2021-04-25 21:45:27 -07:00
Kartik K. Agaram
1a18c9e24b . 2021-04-25 21:35:14 -07:00
Kartik K. Agaram
a68ecc0184 . 2021-04-25 21:32:15 -07:00
Kartik K. Agaram
6bb70a236c shell: tab inserts two spaces 2021-04-25 21:03:14 -07:00
Kartik K. Agaram
cbebd548ca shell: use ctrl-m rather than tab to bounce to trace
We'll save tab for inserting graphemes.
2021-04-25 21:03:05 -07:00
Kartik K. Agaram
1323a6bb3a .
Show all builtins now that we have more space.
2021-04-25 17:57:19 -07:00
Kartik K. Agaram
8e89dd5a78 devote 2/3rds of screen to definitions 2021-04-25 17:55:17 -07:00
Kartik K. Agaram
35a6f3cc99 add some padding to the sandbox 2021-04-25 17:49:39 -07:00
Kartik K. Agaram
a761d0e4ef a troubleshooting note 2021-04-25 16:02:30 -07:00
Kartik K. Agaram
d56153d004 . 2021-04-25 15:58:03 -07:00
Kartik K. Agaram
22a95bd813 expand memory to 2GB
It requires more than 1GB to fill the screen with a chessboard pattern
using the definition in shell/iterative-definitions.limg.

I also speed up the chessboard program by clearing the screen up front
and then only rendering the white pixels.
2021-04-25 15:56:34 -07:00
Kartik Agaram
9c3e2821c1 .
Get rid of my experiment adding Game of Life to the shell.
2021-04-24 07:18:15 -07:00
Kartik Agaram
cb464c9378 bugfix; thanks Max Bernstein 2021-04-24 07:16:34 -07:00
Kartik Agaram
b7224ab44e . 2021-04-23 21:49:28 -07:00
Kartik Agaram
fa8d337d90 shell: some example definitions 2021-04-23 21:36:48 -07:00
Kartik K. Agaram
2ff86d9162 better error message on trace overflow 2021-04-22 10:13:19 -07:00
Kartik K. Agaram
8a66b59940 faster emulation
Thanks Maxwell Bernstein for pointing this out 🤦‍♂️
2021-04-22 09:16:48 -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
6842dddd68 . 2021-04-22 07:56:49 -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
bcd37c381a clear old output when new run is in progress
I'm currently doing this extremely naively/slowly/uglily. Not a bottleneck.
2021-04-21 20:06:46 -07:00
Kartik K. Agaram
bc4b6021de . 2021-04-21 19:56:32 -07:00
Kartik K. Agaram
5daa1f06d4 . 2021-04-21 19:45:02 -07:00
Kartik K. Agaram
9a5e94ce1f . 2021-04-21 19:44:06 -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
34596b6ee9 reimplement pixel graphics
Before: we always drew pixels atop characters, and we only drew pixels
that were explicitly requested.

After: we always draw pixels atop characters, and we only draw pixels that
don't have color 0.

Both semantics should be identical as long as pixels are never drawn atop
characters.
2021-04-19 21:05:57 -07:00
Kartik K. Agaram
f5ece0451b start cleaning up pixel graphics
Filling pixels isn't a rare corner case. I'm going to switch to a dense
rather than sparse representation for pixels, but callers will have to
explicitly request the additional memory.
2021-04-19 10:47:30 -07:00
Kartik K. Agaram
ad46997f95 . 2021-04-18 23:10:01 -07:00
Kartik K. Agaram
d94821d301 some primitives for monitoring code integrity 2021-04-18 11:56:10 -07:00
Kartik K. Agaram
e5adb2239c . 2021-04-17 23:59:30 -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
c11ea74442 . 2021-04-17 22:53:45 -07:00
Kartik K. Agaram
8be6fe2485 bump up the token limit again
Current state of code in the Mu computer:
  (
    (globals . (
      (hline1 . (fn () (screen y lo hi color)
                  (if (>= lo hi)
                    ()
                    ((fn ()
                       (pixel screen lo y color)
                       (hline1 screen y (+ lo 1) hi color))))))
      (vline1 . (fn () (screen x lo hi color)
                  (if (>= lo hi)
                    ()
                    ((fn ()
                       (pixel screen x lo color)
                       (vline1 screen x (+ lo 1) hi color))))))
      (hline . (fn () (screen y color)
                 (hline1 screen y 0 (width screen) color)))
      (vline . (fn () (screen y color)
                 (vline1 screen y 0 (height screen) color)))
      (andf . (fn () (a b)
                (if a
                  (if b
                    1
                    ())
                  ())))
      (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)))))
      (read_line_2 . (fn () (keyboard stream)
                       ((fn (c)
                         (if (= c 10)
                           stream
                           (if (= c 0)
                             stream
                             (read_line_2 keyboard (write stream c)))))
                        (key keyboard))))
      (read_line . (fn () (keyboard)
                     (read_line_2 keyboard (stream))))
      (fill_rect . (fn () (screen x1 y1 x2 y2 fill_color)
                     (if (>= y1 y2)
                       ()
                       ((fn ()
                          (hline1 screen y1 x1 x2 fill_color)
                          (fill_rect screen x1 (+ y1 1) x2 y2 fill_color))))))
      (chessboard . (fn () (screen px)
                      (chessboard1 screen px 0 15)))
      (chessboard1 . (fn () (screen px y color)
                      (if (>= y (height screen))
                        ()
                        ((fn ()
                           (chessboard2 screen px y 0 color)
                           (chessboard1 screen px (+ y px) (- 15 color)))))))
      (chessboard2 . (fn () (screen px y x color)
                      (if (>= x (width screen))
                        ()
                        ((fn ()
                           (fill_rect screen x y (+ x px) (+ y px) color)
                           (chessboard2 screen px y (+ x px) (- 15 color)))))))
    ))
    (sandbox . (chessboard screen 8))
  )
2021-04-17 22:35:35 -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
1154db7a74 load sandbox even if there are no globals 2021-04-17 19:35:02 -07:00
Kartik K. Agaram
412ec38f30 heh, the current state actually overflows 2KB
It only works because the part that's truncated is cleanly the sandbox.

I need better error-checking in `read`.
2021-04-17 09:09:32 -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
1354161a36 tmp: debugging why brline prints no pixels
Among other things, we turned off the trace to significantly speed up the
debug cycle.

State as of https://merveilles.town/@akkartik/106079258606146213

Ohhh, as I save the commit I notice a big problem: I've been editing the
disk image directly because writes to the Mu disk lose indentation. But
I've been forgetting that the state in the Mu disk needs to be pre-evaluated.
So function bindings need extra parens for the environment. The `pixel`
calls in the previous commit message are the first statement in the body,
and they aren't actually considered part of the body right now. No wonder
they don't run.

There are lots of other problems, but this will clarify a lot.
2021-04-17 08:34:48 -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
6d9a1e6abc . 2021-04-17 08:23:55 -07:00
Kartik K. Agaram
33f5eb632a new primitives: abs, sgn 2021-04-16 20:40:02 -07:00
Kartik K. Agaram
f774677854 . 2021-04-16 20:26:56 -07:00
Kartik K. Agaram
f66de61392 handle drawing 16*4 = 64 pixels
Previously we'd only drawn 8*5 = 40 pixels.

Current contents of data.img:

  (
    (globals . (
      (hline . (fn () (screen y) (hline1 screen y 0 (width screen))))
      (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))))))
    ))
    (sandbox . (vline1 screen 5 0 (height screen)))
  )
2021-04-16 20:26:56 -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
cec0d9553b open question: animations in the fake screen
Right now we just render the state of the screen at the end of an evaluation.
2021-04-15 23:20:00 -07:00
Kartik K. Agaram
6aedf5dc59 . 2021-04-15 23:17:15 -07:00
Kartik K. Agaram
735636c7da . 2021-04-15 23:15:47 -07:00
Kartik K. Agaram
c975f29a0c . 2021-04-15 23:12:46 -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
de993bc0cd shell: primitives for screen size 2021-04-15 22:00:03 -07:00
Kartik K. Agaram
5b20f177b6 shell: restore bindings after restart 2021-04-15 21:40:48 -07:00
Kartik K. Agaram
9d367ec2ed shell: start persisting global bindings 2021-04-15 21:05:55 -07:00
Kartik K. Agaram
0f760bd60c . 2021-04-15 20:56:52 -07:00
Kartik K. Agaram
b2e0ce69ef . 2021-04-15 20:15:22 -07:00
Kartik K. Agaram
0192e2031f . 2021-04-15 20:12:36 -07:00
Kartik K. Agaram
91e30acbd8 . 2021-04-15 20:07:07 -07:00
Kartik K. Agaram
04da8ff8b0 add some structure to the serialization format 2021-04-15 19:56:16 -07:00
Kartik K. Agaram
613b1d5734 parse dotted lists 2021-04-15 19:47:01 -07:00
Kartik K. Agaram
2e06991834 . 2021-04-15 19:17:13 -07:00
Kartik K. Agaram
c414b9626f . 2021-04-15 19:13:01 -07:00
Kartik K. Agaram
d41917290a . 2021-04-15 19:12:07 -07:00
Kartik K. Agaram
849f80ac22 . 2021-04-15 18:42:14 -07:00
Kartik K. Agaram
fced134f8f . 2021-04-15 17:41:55 -07:00
Kartik K. Agaram
60ef3caa4d shell: starting to parse dotted lists 2021-04-15 17:38:14 -07:00
Kartik K. Agaram
d0578257cd shell: dot token 2021-04-15 08:48:53 -07:00
Kartik K. Agaram
126a0390f5 . 2021-04-15 08:47:58 -07:00
Kartik K. Agaram
262290a4e8 . 2021-04-15 08:45:09 -07:00
Kartik K. Agaram
2359e5ed63 shell: load data disk as s-expr rather than string 2021-04-14 22:04:42 -07:00
Kartik K. Agaram
8db35826e6 shell: starting to work on persistent globals 2021-04-14 21:52:57 -07:00
Kartik K. Agaram
5a46430e0e . 2021-04-14 21:47:59 -07:00
Kartik K. Agaram
98715a829e shell: primitives for comparison, cursor movement 2021-04-14 21:26:16 -07:00
Kartik K. Agaram
0b00cacac6 shell: more detailed description of primitives 2021-04-14 20:56:48 -07:00
Kartik K. Agaram
31b4368079 shell: word/line navigation 2021-04-14 20:09:25 -07:00
Kartik K. Agaram
76fb62a16d . 2021-04-14 15:26:04 -07:00
Kartik K. Agaram
bbabe8bd1a shell: pixel graphics 2021-04-13 22:27: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
b0096cd6a6 shell: streams that you can append graphemes to 2021-04-10 23:05:16 -07:00
Kartik K. Agaram
f38c2a1502 . 2021-04-10 22:38:02 -07:00
Kartik K. Agaram
1afc02113a shell: fake keyboard 2021-04-10 22:28:24 -07:00
Kartik K. Agaram
e93bbec63b shell: start jumping to keyboard using Tab 2021-04-10 22:14:20 -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
a509279aea shell: start on support for fake keyboard 2021-04-10 20:49:20 -07:00
Kartik K. Agaram
400574f956 shell: move fake screen to sandbox 2021-04-10 20:44:26 -07:00
Kartik K. Agaram
6fa86619b2 shell: tweaks for fake screens
- make them more discoverable
- clear them between commands
2021-04-10 20:09:18 -07:00
Kartik K. Agaram
17f77da27d shell: fake screens
I just realized Mu has a pretty big weakness: writes to null pointers don't
error out. Perhaps writes to address 0 do, but address 1 and so on don't?

I need a slightly more sophisticated page table.
2021-04-10 18:32:27 -07:00
Kartik K. Agaram
90748fa45d shell: render fake screens
'print' turns out to not be working yet.
2021-04-10 17:42:35 -07:00
Kartik K. Agaram
f6aeecdc48 . 2021-04-10 17:15:42 -07:00
Kartik K. Agaram
97cffa20d4 shell: start of 'print' primitive 2021-04-10 15:59:40 -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
630a7396c5 shell: highlight matching paren for cursor 2021-04-09 21:57:40 -07:00
Kartik K. Agaram
5094473b2f shell: highlight matching close-paren 2021-04-09 20:39:53 -07:00
Kartik K. Agaram
f5defca117 . 2021-04-09 20:10:47 -07:00
Kartik K. Agaram
fd0e9b5b68 shell: render primitives at the bottom 2021-04-08 23:04:30 -07:00
Kartik K. Agaram
f21e224fcd . 2021-04-08 23:04:30 -07:00
Kartik K. Agaram
c3069ab818 shell: start rendering globals 2021-04-08 23:04:30 -07:00
Kartik K. Agaram
d6d28b8c94 shell: create space to display globals 2021-04-08 22:19:24 -07:00
Kartik K. Agaram
119aea6d06 shell: ctrl-u to clear sandbox 2021-04-06 19:39:09 -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
6ef0eabdcf shell: now we can start adding primitives 2021-04-06 09:07:25 -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
9142cd8519 . 2021-04-05 23:23:41 -07:00
Kartik K. Agaram
07bc1eeb90 shell: save repl input to disk before running 2021-04-05 23:09:05 -07:00
Kartik K. Agaram
4861c39474 shell: ctrl-a/e 2021-04-05 22:39:37 -07:00
Kartik K. Agaram
143cce94ee support for arrow keys
Mu's keyboard handling is currently a bit of a mess, and this commit might
be a bad idea.

Ideally keyboards would return Unicode. Currently Mu returns single bytes.
Mostly ASCII. No support for international keyboards yet.

ASCII and Unicode have some keyboard scancodes grandfathered in, that don't
really make sense for data transmission. Like backspace and delete. However,
other keyboard scancodes don't have any place in Unicode. Including arrow keys.

So Mu carves out an exception to Unicode for arrow keys. We'll place the
arrow keys in a part of Unicode that is set aside for implementation-defined
behavior (https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C1_controls):

  0x80: left arrow
  0x81: down arrow
  0x82: up arrow
  0x83: right arrow

The order is same as hjkl for mnemonic convenience. I'd _really_ to follow
someone else's cannibalization here. If I find one later, I'll switch to
it.

Applications that blindly assume the keyboard generates Unicode will have
a bad time. Events like backspace, delete and arrow keys are intended to
be processed early and should not be in text.

With a little luck I won't need to modify this convention when I support
international keyboards.
2021-04-05 22:37:27 -07:00
Kartik K. Agaram
463878a4a4 shell: clean up unimplemented menu items 2021-04-05 19:46:47 -07:00
Kartik K. Agaram
8a31a087b0 . 2021-04-05 19:41:46 -07:00
Kartik Agaram
f9e8b0c784 . 2021-04-05 13:56:02 -07:00
Kartik K. Agaram
18ef136b2c . 2021-03-28 08:36:03 -07:00
Kartik K. Agaram
1a43d12b15 explicitly pass screen and keyboard to main 2021-03-26 23:07:35 -07:00
Kartik K. Agaram
21263b2edd bochs support for disk drives 2021-03-23 21:53:41 -07:00
Kartik K. Agaram
62a2442110 writes to disk now working
Tested by inserting a call into the shell, but we can't leave it in because
every test ends up clobbering the disk. So it's now time to think about
a testable interface for the disk.
2021-03-23 00:32:49 -07:00
Kartik K. Agaram
c0607ecca8 . 2021-03-22 22:56:33 -07:00
Kartik K. Agaram
b2e9887b83 . 2021-03-22 22:28:35 -07:00
Kartik K. Agaram
02b0317c3b shell: gracefully handle missing data disk 2021-03-22 22:21:51 -07:00
Kartik K. Agaram
e6b42204ef shell: read initial expression from secondary disk
See shell/README.md for (extremely klunky) instructions.
2021-03-21 23:10:55 -07:00
Kartik K. Agaram
fe72699390 . 2021-03-08 21:14:06 -08:00
Kartik K. Agaram
38ab33a18d . 2021-03-08 21:04:38 -08:00
Kartik K. Agaram
3ef3d46d72 . 2021-03-08 21:04:03 -08:00
Kartik K. Agaram
2e58ffd653 . 2021-03-08 21:03:15 -08:00
Kartik K. Agaram
0810c7b77e readme for the Mu shell 2021-03-08 20:57:11 -08:00
Kartik K. Agaram
aaf2941bfe . 2021-03-08 18:05:36 -08:00
Kartik K. Agaram
d124be9cb6 strip spaces when tokenizing
Thanks Max Bernstein for reporting this.
2021-03-08 17:54:07 -08:00
Kartik K. Agaram
e58980b4c8 get rid of ctrl-d/ctrl-u when browsing trace
Also clean up the menu. Mode-specific stuff goes after Tab.
2021-03-08 16:27:41 -08:00
Max Bernstein
96e75f1070 Add j/k keybindings for navigating trace
These are familiar for Vim users.
2021-03-08 15:40:49 -08:00
Kartik Agaram
1a1a1671ed 7866 2021-03-07 19:46:21 -08:00
Kartik Agaram
e5b8721ca4 7865 2021-03-07 19:29:54 -08:00
Kartik K. Agaram
65e22a3628 7864 - shell: clean up the trace some more 2021-03-07 14:18:24 -08:00
Kartik K. Agaram
d2b7e3f44f 7863 - shell: anonymous fn calls 2021-03-07 11:05:03 -08:00
Kartik K. Agaram
5b50feaeee 7862 - shell: more informative traces for eval
Also a bugfix in dealing with streams in cells that is becoming part of
a pattern.
2021-03-07 10:55:11 -08:00
Kartik K. Agaram
410782c79e 7861 - shell: anonymous fn calls without args
((fn () (+ 1 1)))
2021-03-07 08:53:31 -08:00
Kartik K. Agaram
477e58f0b2 7860 2021-03-06 23:38:46 -08:00
Kartik K. Agaram
8f01e2d553 7859 2021-03-06 23:15:27 -08:00
Kartik K. Agaram
7fef31d272 7858 - shell: anonymous fn expressions 2021-03-06 23:03:23 -08:00
Kartik K. Agaram
bcde6be528 7857 - shell: first function call 2021-03-05 15:18:46 -08:00
Kartik K. Agaram
e4fc67ee44 7856 - shell: primitive functions 2021-03-05 09:30:15 -08:00
Kartik K. Agaram
d3b508b16c 7855 2021-03-05 09:02:56 -08:00
Kartik K. Agaram
2454f72c8a 7854 - shell: symbol lookup 2021-03-05 06:19:21 -08:00
Kartik K. Agaram
275a652402 7853 2021-03-05 06:07:50 -08:00
Kartik K. Agaram
3417a0b32a 7852 2021-03-05 05:42:27 -08:00
Kartik K. Agaram
091a4e4001 7851 - shell snapshot: symbol lookup 2021-03-05 05:28:28 -08:00
Kartik K. Agaram
e5ff0c39a6 7849 - shell: literal numbers 2021-03-04 22:05:39 -08:00
Kartik K. Agaram
71e4f38129 7842 - new directory organization
Baremetal is now the default build target and therefore has its sources
at the top-level. Baremetal programs build using the phase-2 Mu toolchain
that requires a Linux kernel. This phase-2 codebase which used to be at
the top-level is now under the linux/ directory. Finally, the phase-2 toolchain,
while self-hosting, has a way to bootstrap from a C implementation, which
is now stored in linux/bootstrap. The bootstrap C implementation uses some
literate programming tools that are now in linux/bootstrap/tools.

So the whole thing has gotten inverted. Each directory should build one
artifact and include the main sources (along with standard library). Tools
used for building it are relegated to sub-directories, even though those
tools are often useful in their own right, and have had lots of interesting
programs written using them.

A couple of things have gotten dropped in this process:
  - I had old ways to run on just a Linux kernel, or with a Soso kernel.
    No more.
  - I had some old tooling for running a single test at the cursor. I haven't
    used that lately. Maybe I'll bring it back one day.

The reorg isn't done yet. Still to do:
  - redo documentation everywhere. All the README files, all other markdown,
    particularly vocabulary.md.
  - clean up how-to-run comments at the start of programs everywhere
  - rethink what to do with the html/ directory. Do we even want to keep
    supporting it?

In spite of these shortcomings, all the scripts at the top-level, linux/
and linux/bootstrap are working. The names of the scripts also feel reasonable.
This is a good milestone to take stock at.
2021-03-03 22:21:03 -08:00