Commit Graph

200 Commits

Author SHA1 Message Date
Kartik Agaram 257add0f7e 4421
Clean up the rat's nest that all my trace management globals had
gradually turned into.

  a) Get rid of 'Start_tracing'. Horryibly named, I don't know how I
  missed that until now.

  b) Never use START_TRACING_UNTIL_END_OF_SCOPE in main(). It's
  confusing to combine it with atexit(delete Trace_stream), because the
  atexit() never has to run. Instead we'll just manually initialize
  Trace_stream and let atexit() clean up.

  c) If we run tests we only want a trace for the test run itself. So
  delete the Trace_stream that was initialized at the top of main --
  once it's clear we had no load-time errors.

  d) Clean up horribly "Load Recipes" waypoints, combine them with the better
  name, "Mu Prelude".

Putting these together, we have the following manual tests:

  - CFLAGS=-g mu x.mu

    Should not create last_run.

  - CFLAGS=-g mu --trace x.mu

    Should create last_run.
    Should write it out exactly once.

  - CFLAGS=-g mu --trace x.mu  # when x.mu has an error

    Should create last_run.
    Should write it out exactly once.

  - CFLAGS=-g mu --trace test copy_literal  # C test

    Should create last_run.
    Should write it out exactly once.

  - CFLAGS=-g mu --trace test recipe_with_header  # Mu test

    Should create last_run.
    Should write it out exactly once.

I don't know how to automate these scenarios yet. We need a way to run
our build toolchain atop our stack.
2018-07-26 10:09:29 -07:00
Kartik Agaram b2e36ec827 4418
Use 'dump' consistently to mean 'to screen' (stderr), and 'save' to mean
'to disk'.
2018-07-26 09:03:13 -07:00
Kartik Agaram 15152795ce 4417
Audit poor uses of 'cout'.
2018-07-26 09:03:13 -07:00
Kartik Agaram 7f04b09a97 4267
Drop a stray hunk that is obsoleted by 'deaddress'.
2018-06-24 09:35:19 -07:00
Kartik Agaram 23d3a02226 4266 - space for alloc-id in heap allocations
This has taken me almost 6 weeks :(
2018-06-24 09:18:20 -07:00
Kartik Agaram ce9b2b0515 4258 - undo 4257 2018-06-15 22:16:09 -07:00
Kartik Agaram 0edd9b9fc6 4257 - abortive attempt at safe fat pointers
I've been working on this slowly over several weeks, but it's too hard
to support 0 as the null value for addresses. I constantly have to add
exceptions for scalar value corresponding to an address type (now
occupying 2 locations). The final straw is the test for 'reload':

  x:num <- reload text

'reload' returns an address. But there's no way to know that for
arbitrary instructions.

New plan: let's put this off for a bit and first create support for
literals. Then use 'null' instead of '0' for addresses everywhere. Then
it'll be easy to just change what 'null' means.
2018-06-15 22:12:03 -07:00
Kartik Agaram 1fb0cf9ef9 4243 2018-05-12 20:14:49 -07:00
Kartik K. Agaram 745a6dee78 4204 2018-02-15 20:36:16 -08:00
Kartik K. Agaram 472e4ce96d 4149 2017-12-07 13:48:51 -08:00
Kartik K. Agaram 08a8cb2a8c 4147 2017-12-07 13:42:27 -08:00
Kartik K. Agaram e8267f00bb 4140 2017-12-05 21:14:45 -08:00
Kartik K. Agaram d51abbf123 4139 2017-12-05 01:15:10 -08:00
Kartik K. Agaram 3b776ac384 4116 - support calling continuations with arguments
Surprisingly small change, considering how long it took me and how
mind-bending it was. 'return-continuation-until-mark' now behaves like
both call and return instructions, which made it hard to reason about.
2017-11-06 01:12:42 -08:00
Kartik K. Agaram a89c1bed26 4104
Stop hardcoding Max_depth everywhere; we had a default value for a
reason but then we forgot all about it.
2017-11-03 01:50:46 -07:00
Kartik K. Agaram 514f0e34aa 4089
Clean up how we reclaim local scopes.

It used to work like this (commit 3216):

  1. Update refcounts of products after every instruction, EXCEPT:

      a) when instruction is a non-primitive and the callee starts with
      'local-scope' (because it's already not decremented in 'return')

    OR:

      b) when instruction is primitive 'next-ingredient' or
      'next-ingredient-without-typechecking', and its result is saved to a
      variable in the default space (because it's already incremented at
      the time of the call)

  2. If a function starts with 'local-scope', force it to be reclaimed
  before each return. However, since locals may be returned, *very
  carefully* don't reclaim those. (See the logic in the old `escaping`
  and `should_update_refcount` functions.)

However, this approach had issues. We needed two separate commands for
'local-scope' (reclaim locals on exit) and 'new-default-space'
(programmer takes charge of reclaiming locals). The hard-coded
reclamation duplicated refcounting logic. In addition to adding
complexity, this implementation failed to work if a function overwrites
default-space after setting up a local-scope (the old default-space is
leaked). It also fails in the presence of continuations. Calling a
continuation more than once was guaranteed to corrupt memory (commit
3986).

After this commit, reclaiming local scopes now works like this:

  Update refcounts of products for every PRIMITIVE instruction.
  For non-primitive instructions, all the work happens in the `return`
  instruction:
    increment refcount of ingredients to `return`
      (unless -- one last bit of ugliness -- they aren't saved in the
      caller)
    decrement the refcount of the default-space
      use existing infrastructure for reclaiming as necessary
      if reclaiming default-space, first decrement refcount of each
      local
        again, use existing infrastructure for reclaiming as necessary

This commit (finally!) completes the bulk[1] of step 2 of the plan in
commit 3991. It was very hard until I gave up trying to tweak the
existing implementation and just test-drove layer 43 from scratch.

[1] There's still potential for memory corruption if we abuse
`default-space`. I should probably try to add warnings about that at
some point (todo in layer 45).
2017-10-22 23:48:03 -07:00
Kartik K. Agaram 7d07cd1de8 3987 2017-09-01 01:50:10 -07:00
Kartik K. Agaram ec99eb7a2a 3966 2017-07-09 14:34:17 -07:00
Kartik K. Agaram 6573fe1f1a 3965 - get rid of the teardown() function
Instead of setup() and teardown() we'll just use a reset() function from
now on, which will bring the machine back to a good state before each
test or run, and also before exit (to avoid memory leaks).
2017-07-09 14:25:48 -07:00
Kartik K. Agaram df0f36fb40 3906
Yet another attempt at decomposing incremental edits in some clean way.
The new idea now is that I need to only modify the screen using a
restricted vocabulary of actions:
  render-all
  render-recipe-side
  render-sandbox-side
  render-recipe-errors
  render-line-from-cursor
  render-line-from-start
  erase-line-from-cursor
  render-character-at-cursor
  erase-character-at-cursor

However, decomposing insert-at-cursor is challenging; how to manipulate
cursor-row and cursor-column without also pretending to print to screen?
Do I need to decompose `editor` into multiple containers so that I can
keep cursor-row and cursor-column with screen modifications? Here's what
`editor` looks like after all layers:

  container editor [
    data:&:duplex-list:char
    top-of-screen:&:duplex-list:char
    bottom-of-screen:&:duplex-list:char
    before-cursor:&:duplex-list:char
    left:num
    right:num
    bottom:num
    cursor-row:num
    cursor-column:num
    indent?:bool
    undo:&:list:&:operation
    redo:&:list:&:operation
  ]

It's not obvious that there's a clean way to split all these fields.
2017-06-10 23:56:37 -07:00
Kartik K. Agaram b2f699e14f 3888 - beginnings of a profiler
Time to make my ad hoc commented out code fragments a first-class feature.
2017-05-28 23:57:19 -07:00
Kartik K. Agaram 5987486862 3887 - clean up early exits in interpreter loop
It's always confusing when `break` refers to a `switch` but `continue`
refers to the loop around the `switch`. But we've done ugly things like
this and `goto` for expedience. However, we're starting to run into cases
where we now need to insert code at every `continue` or `continue`-mimicking
`goto` inside the core interpreter loop. Better to make the loop single-entry-single-exit.
Common things to run after every instruction will now happen inside the
`finish_instruction` function rather than at the `finish_instruction` label.
2017-05-28 23:00:47 -07:00
Kartik K. Agaram 2b25071710 3877 2017-05-26 17:36:16 -07:00
Kartik K. Agaram 14d6f9f395 3872
Starting to look for lack of organization in the edit/ app.
2017-05-20 02:09:58 -07:00
Kartik K. Agaram b8263692a6 3841
Use the real original instruction in error messages.
Thanks Ella Couch.
2017-04-27 09:07:53 -07:00
Kartik K. Agaram 6a7ff61cb9 3821
Fix CI.
2017-04-13 23:18:06 -07:00
Kartik K. Agaram f404eb5572 3819
Yet another attempt at trying to clean up commit 3216. I think this solution
might finally let me stop agonizing over the problem. State variables for
distinguishing call-sites are a reasonable mechanism, orthogonal to waypoints
and the hook functions to hold them.
2017-04-13 22:04:52 -07:00
Kartik K. Agaram e317da73b0 3814
Initial baby steps at trying to understand why rendering to screen is so
slow in Mu. I'd forgotten about this old "poor man's profiler" I'd added
back in 2015.
2017-04-06 09:51:00 -07:00
Kartik K. Agaram ba1fb981f6 3811 2017-04-04 10:49:13 -07:00
Kartik K. Agaram e777ce0c3e 3758 2017-03-06 09:13:44 -08:00
Kartik K. Agaram 215cf3c2d8 3756 - start of some improvements to the trace browser 2017-03-05 23:24:19 -08:00
Kartik K. Agaram 49620728e8 3707
Be more disciplined about tagging 2 different concepts in the codebase:

a) Use the phrase "later layers" to highlight places where a layer
doesn't have the simplest possible self-contained implementation.

b) Use the word "hook" to point out functions that exist purely to
provide waypoints for extension by future layers.

Since both these only make sense in the pre-tangled representation of
the codebase, using '//:' and '#:' comments to get them stripped out of
tangled output.

(Though '#:' comments still make it to tangled output at the moment.
Let's see if we use it enough to be worth supporting. Scenarios are
pretty unreadable in tangled output anyway.)
2016-12-12 10:07:59 -08:00
Kartik K. Agaram 07c594ebdd 3701
Gracefully handle yet another typo.
2016-11-29 18:33:46 -08:00
Kartik K. Agaram 6f69d5d9af 3682
Clean up the flow of "mu --trace" followed by "mu browse-trace
interactive".
2016-11-22 11:39:05 -08:00
Kartik K. Agaram 4cec4143d3 3675 2016-11-15 22:22:11 -08:00
Kartik K. Agaram b771d375d3 3655 2016-11-08 12:39:34 -08:00
Kartik K. Agaram 4ecab1821e 3653
Don't crash on bad types.

I need to be more careful in distinguishing between the two causes of
constraint violations: bad input and internal bugs. Maybe I should
create a second assert() to indicate "this shouldn't really be an
assert, but I'm too lazy to think about it right now."
2016-11-08 10:31:48 -08:00
Kartik K. Agaram f4647409b5 3652
size_of(type_tree*) is a mess; clean it up with an eye to the final
tangled version.
2016-11-08 10:20:49 -08:00
Kartik K. Agaram 1211a3ab30 3643
Standardize on calling literate waypoints "Special-cases" rather than
"Cases". Invariably there's a default path already present.
2016-11-07 09:10:48 -08:00
Kartik K. Agaram 838b1afce9 3630 - generate trace for a single scenario
To do so, run:

  $ ./mu --trace test <scenario name>

The trace will then be in file 'interactive'.
2016-11-06 01:05:22 -07:00
Kartik K. Agaram 07b54625f7 3596
Fix CI.
2016-10-25 13:33:51 -07:00
Kartik K. Agaram 9a81d7460f 3561 2016-10-22 16:56:07 -07:00
Kartik K. Agaram d8509b4175 3555 2016-10-22 16:10:23 -07:00
Kartik K. Agaram 6c96a437ce 3522 2016-10-19 22:10:35 -07:00
Kartik K. Agaram 6d6c37feeb 3446
Better warning if I try:

  mu test --test-only-app sandbox

instead of:

  mu --test-only-app test sandbox
2016-10-06 10:54:47 -07:00
Kartik K. Agaram 8a92ada807 3435 2016-10-04 08:18:43 -07:00
Kartik K. Agaram 192d59d3bb 3380
One more place we were missing expanding type abbreviations: inside
container definitions.
2016-09-17 00:43:20 -07:00
Kartik K. Agaram 58a08ed3e7 3358 2016-09-15 11:22:36 -07:00
Kartik K. Agaram ccba671853 3335
Clean up rest of long-standing bit of ugliness.

I'm growing more confident now that I can use layers to cleanly add any
functionality I want. All I need is hook functions. No need to ever put
'{' on their own line, or add arguments to calls.
2016-09-11 20:26:46 -07:00
Kartik K. Agaram b3899909d6 3334
Clean up one long-standing bit of ugliness.
2016-09-11 20:02:28 -07:00