about summary refs log tree commit diff stats
path: root/020run.cc
Commit message (Collapse)AuthorAgeFilesLines
* 4204Kartik K. Agaram2018-02-151-1/+10
|
* 4149Kartik K. Agaram2017-12-071-1/+4
|
* 4147Kartik K. Agaram2017-12-071-2/+6
|
* 4140Kartik K. Agaram2017-12-051-1/+1
|
* 4139Kartik K. Agaram2017-12-051-7/+5
|
* 4116 - support calling continuations with argumentsKartik K. Agaram2017-11-061-0/+2
| | | | | | 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.
* 4104Kartik K. Agaram2017-11-031-2/+2
| | | | | Stop hardcoding Max_depth everywhere; we had a default value for a reason but then we forgot all about it.
* 4089Kartik K. Agaram2017-10-221-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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).
* 3987Kartik K. Agaram2017-09-011-1/+1
|
* 3966Kartik K. Agaram2017-07-091-1/+1
|
* 3965 - get rid of the teardown() functionKartik K. Agaram2017-07-091-2/+1
| | | | | | 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).
* 3906Kartik K. Agaram2017-06-101-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* 3888 - beginnings of a profilerKartik K. Agaram2017-05-281-21/+48
| | | | Time to make my ad hoc commented out code fragments a first-class feature.
* 3887 - clean up early exits in interpreter loopKartik K. Agaram2017-05-281-10/+18
| | | | | | | | | | 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.
* 3877Kartik K. Agaram2017-05-261-3/+3
|
* 3872Kartik K. Agaram2017-05-201-0/+1
| | | | Starting to look for lack of organization in the edit/ app.
* 3841Kartik K. Agaram2017-04-271-3/+3
| | | | | Use the real original instruction in error messages. Thanks Ella Couch.
* 3821Kartik K. Agaram2017-04-131-0/+1
| | | | Fix CI.
* 3819Kartik K. Agaram2017-04-131-2/+5
| | | | | | | 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.
* 3814Kartik K. Agaram2017-04-061-0/+1
| | | | | | 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.
* 3811Kartik K. Agaram2017-04-041-1/+1
|
* 3758Kartik K. Agaram2017-03-061-0/+1
|
* 3756 - start of some improvements to the trace browserKartik K. Agaram2017-03-051-1/+1
|
* 3707Kartik K. Agaram2016-12-121-3/+9
| | | | | | | | | | | | | | | | | | 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.)
* 3701Kartik K. Agaram2016-11-291-0/+1
| | | | Gracefully handle yet another typo.
* 3682Kartik K. Agaram2016-11-221-3/+5
| | | | | Clean up the flow of "mu --trace" followed by "mu browse-trace interactive".
* 3675Kartik K. Agaram2016-11-151-2/+2
|
* 3655Kartik K. Agaram2016-11-081-1/+1
|
* 3653Kartik K. Agaram2016-11-081-1/+4
| | | | | | | | | 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."
* 3652Kartik K. Agaram2016-11-081-0/+10
| | | | | size_of(type_tree*) is a mess; clean it up with an eye to the final tangled version.
* 3643Kartik K. Agaram2016-11-071-3/+3
| | | | | Standardize on calling literate waypoints "Special-cases" rather than "Cases". Invariably there's a default path already present.
* 3630 - generate trace for a single scenarioKartik K. Agaram2016-11-061-3/+3
| | | | | | | | To do so, run: $ ./mu --trace test <scenario name> The trace will then be in file 'interactive'.
* 3596Kartik K. Agaram2016-10-251-0/+3
| | | | Fix CI.
* 3561Kartik K. Agaram2016-10-221-4/+4
|
* 3555Kartik K. Agaram2016-10-221-1/+1
|
* 3522Kartik K. Agaram2016-10-191-9/+9
|
* 3446Kartik K. Agaram2016-10-061-1/+3
| | | | | | | | | | Better warning if I try: mu test --test-only-app sandbox instead of: mu --test-only-app test sandbox
* 3435Kartik K. Agaram2016-10-041-0/+3
|
* 3380Kartik K. Agaram2016-09-171-11/+11
| | | | | One more place we were missing expanding type abbreviations: inside container definitions.
* 3358Kartik K. Agaram2016-09-151-0/+4
|
* 3335Kartik K. Agaram2016-09-111-2/+6
| | | | | | | | 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.
* 3334Kartik K. Agaram2016-09-111-2/+1
| | | | Clean up one long-standing bit of ugliness.
* 3309Kartik K. Agaram2016-09-091-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rip out everything to fix one failing unit test (commit 3290; type abbreviations). This commit does several things at once that I couldn't come up with a clean way to unpack: A. It moves to a new representation for type trees without changing the actual definition of the `type_tree` struct. B. It adds unit tests for our type metadata precomputation, so that errors there show up early and in a simpler setting rather than dying when we try to load Mu code. C. It fixes a bug, guarding against infinite loops when precomputing metadata for recursive shape-shifting containers. To do this it uses a dumb way of comparing type_trees, comparing their string representations instead. That is likely incredibly inefficient. Perhaps due to C, this commit has made Mu incredibly slow. Running all tests for the core and the edit/ app now takes 6.5 minutes rather than 3.5 minutes. == more notes and details I've been struggling for the past week now to back out of a bad design decision, a premature optimization from the early days: storing atoms directly in the 'value' slot of a cons cell rather than creating a special 'atom' cons cell and storing it on the 'left' slot. In other words, if a cons cell looks like this: o / | \ left val right ..then the type_tree (a b c) used to look like this (before this commit): o | \ a o | \ b o | \ c null ..rather than like this 'classic' approach to s-expressions which never mixes val and right (which is what we now have): o / \ o o | / \ a o o | / \ b o null | c The old approach made several operations more complicated, most recently the act of replacing a (possibly atom/leaf) sub-tree with another. That was the final straw that got me to realize the contortions I was going through to save a few type_tree nodes (cons cells). Switching to the new approach was hard partly because I've been using the old approach for so long and type_tree manipulations had pervaded everything. Another issue I ran into was the realization that my layers were not cleanly separated. Key parts of early layers (precomputing type metadata) existed purely for far later ones (shape-shifting types). Layers I got repeatedly stuck at: 1. the transform for precomputing type sizes (layer 30) 2. type-checks on merge instructions (layer 31) 3. the transform for precomputing address offsets in types (layer 36) 4. replace operations in supporting shape-shifting recipes (layer 55) After much thrashing I finally noticed that it wasn't the entirety of these layers that was giving me trouble, but just the type metadata precomputation, which had bugs that weren't manifesting until 30 layers later. Or, worse, when loading .mu files before any tests had had a chance to run. A common failure mode was running into types at run time that I hadn't precomputed metadata for at transform time. Digging into these bugs got me to realize that what I had before wasn't really very good, but a half-assed heuristic approach that did a whole lot of extra work precomputing metadata for utterly meaningless types like `((address number) 3)` which just happened to be part of a larger type like `(array (address number) 3)`. So, I redid it all. I switched the representation of types (because the old representation made unit tests difficult to retrofit) and added unit tests to the metadata precomputation. I also made layer 30 only do the minimal metadata precomputation it needs for the concepts introduced until then. In the process, I also made the precomputation more correct than before, and added hooks in the right place so that I could augment the logic when I introduced shape-shifting containers. == lessons learned There's several levels of hygiene when it comes to layers: 1. Every layer introduces precisely what it needs and in the simplest way possible. If I was building an app until just that layer, nothing would seem over-engineered. 2. Some layers are fore-shadowing features in future layers. Sometimes this is ok. For example, layer 10 foreshadows containers and arrays and so on without actually supporting them. That is a net win because it lets me lay out the core of Mu's data structures out in one place. But if the fore-shadowing gets too complex things get nasty. Not least because it can be hard to write unit tests for features before you provide the plumbing to visualize and manipulate them. 3. A layer is introducing features that are tested only in later layers. 4. A layer is introducing features with tests that are invalidated in later layers. (This I knew from early on to be an obviously horrendous idea.) Summary: avoid Level 2 (foreshadowing layers) as much as possible. Tolerate it indefinitely for small things where the code stays simple over time, but become strict again when things start to get more complex. Level 3 is mostly a net lose, but sometimes it can be expedient (a real case of the usually grossly over-applied term "technical debt"), and it's better than the conventional baseline of no layers and no scenarios. Just clean it up as soon as possible. Definitely avoid layer 4 at any time. == minor lessons Avoid unit tests for trivial things, write scenarios in context as much as possible. But within those margins unit tests are fine. Just introduce them before any scenarios (commit 3297). Reorganizing layers can be easy. Just merge layers for starters! Punt on resplitting them in some new way until you've gotten them to work. This is the wisdom of Refactoring: small steps. What made it hard was not wanting to merge *everything* between layer 30 and 55. The eventual insight was realizing I just need to move those two full-strength transforms and nothing else.
* 3279Kartik K. Agaram2016-08-291-8/+8
| | | | | Stop inlining functions because that will complicate separate compilation. It also simplifies the code without impacting performance.
* 3263Kartik K. Agaram2016-08-271-1/+1
| | | | Commit 3171 which added '--trace' broke 'Save_trace'.
* 3259Kartik K. Agaram2016-08-261-2/+2
| | | | | | | | | | | Prefer preincrement operators wherever possible. Old versions of compilers used to be better at optimizing them. Even if we don't care about performance it's useful to make unary operators look like unary operators wherever possible, and to distinguish the 'statement form' which doesn't care about the value of the expression from the postincrement which usually increments as a side-effect in some larger computation (and so is worth avoiding except for some common idioms, or perhaps even there).
* 3246Kartik K. Agaram2016-08-251-1/+1
|
* 3245 - refuse to run programs with errorsKartik K. Agaram2016-08-221-0/+1
| | | | | | | | | | | | | | I started out incredibly lax about running past errors (I even used to call them 'warnings' when I started Mu), but I've been gradually seeing the wisdom of Go and Racket in refusing to run code if it doesn't pass basic integrity checks (such as using a literal as an address). Go is right to have no warnings, only errors. But where Go goes wrong is in even caring about unused variables. Racket and other languages perform more aggressive integrity checks so that the can optimize more aggressively, and I'm starting to realize I don't know enough to disagree with them.
* 3223Kartik K. Agaram2016-08-181-1/+4
|
* 3201Kartik K. Agaram2016-08-161-1/+1
|