Commit Graph

131 Commits

Author SHA1 Message Date
Kartik K. Agaram 158b53eb8f first attempt doesn't work
I was aware of some complications. The various indexes and y coordinates
in the trace's cache would be unstable and need to be recomputed. But it's
surprising that the trace _completely disappears_.
2021-05-30 09:23:36 -07:00
Kartik K. Agaram 1496548287 start progressively increasing trace depth
The goal: the sandbox initially maintains a shallow trace. As you expand
into the trace, the environment reruns the sandbox at greater depth as
needed.

The challenge: expanding happens within edit-trace, which doesn't have
the whole sandbox needed to re-run the sandbox. We'll either need to expand
the trace's capabilities to include the whole sandbox, or duplicate some
logic to decide when to run the sandbox.
2021-05-30 08:51:58 -07:00
Kartik K. Agaram 7fa0163941 disable ctrl-s when browsing trace
We're soon going to be dynamically rerunning the sandbox in other ways
when browsing the trace.
2021-05-23 22:18:51 -07:00
Kartik K. Agaram d3103378c5 . 2021-05-23 22:17:05 -07:00
Kartik K. Agaram 7a04c8104d shell: reduce trace depth in sandbox
We'll gradually make this more dynamic.
2021-05-22 10:28:21 -07:00
Kartik K. Agaram e2ab1b30b1 disallow null traces
We now use traces everywhere for error-checking. Null traces introduce
the possibility of changing a functions error response, and therefore its
semantics.
2021-05-19 20:56:37 -07:00
Kartik K. Agaram ec2dab7801 shell: traces track a maximum depth to record 2021-05-19 01:26:25 -07:00
Kartik K. Agaram 837926751a shell: add a lot of error-checking 2021-05-18 20:01:11 -07:00
Kartik K. Agaram 19dd573a92 . 2021-05-07 20:02:01 -07:00
Kartik K. Agaram d3f17627d8 an often-overflowing stream when running brcircle
We really need to systematically check our trace streams.
2021-05-07 15:12:56 -07:00
Kartik K. Agaram c5f50f05b7 . 2021-05-07 12:46:41 -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 6df53d463c back to macros; switch macroexpand to operate in place 2021-05-06 17:00:18 -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 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 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 772b7b6585 adjust fake screen aspect ratio for verisimilitude 2021-04-29 23:38:37 -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 6503529627 white text everywhere by default 2021-04-29 16:27:43 -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 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 5b7f938733 start stashing and clearing sandbox after definitions 2021-04-28 13:55:10 -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 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 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 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 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 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 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 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 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 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 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 0192e2031f . 2021-04-15 20:12:36 -07:00
Kartik K. Agaram 91e30acbd8 . 2021-04-15 20:07:07 -07:00
Kartik K. Agaram 613b1d5734 parse dotted lists 2021-04-15 19:47:01 -07:00
Kartik K. Agaram 5a46430e0e . 2021-04-14 21:47:59 -07:00
Kartik K. Agaram 31b4368079 shell: word/line navigation 2021-04-14 20:09:25 -07:00
Kartik K. Agaram bbabe8bd1a shell: pixel graphics 2021-04-13 22:27:59 -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 90748fa45d shell: render fake screens
'print' turns out to not be working yet.
2021-04-10 17:42:35 -07:00
Kartik K. Agaram 97cffa20d4 shell: start of 'print' primitive 2021-04-10 15:59:40 -07:00
Kartik K. Agaram f21e224fcd . 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 26a1849895 shell: quote 2021-04-06 09:40:13 -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 07bc1eeb90 shell: save repl input to disk before running 2021-04-05 23:09:05 -07:00
Kartik K. Agaram 463878a4a4 shell: clean up unimplemented menu items 2021-04-05 19:46:47 -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 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
Kartik K. Agaram 477e58f0b2 7860 2021-03-06 23:38:46 -08:00
Kartik K. Agaram 2454f72c8a 7854 - shell: symbol lookup 2021-03-05 06:19:21 -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