Commit Graph

37 Commits

Author SHA1 Message Date
Kartik Agaram
dd66068298 4261 - start using literals for 'true' and 'false'
They uncovered one bug: in edit/003-shortcuts.mu
  <scroll-down> was returning 0 for an address in one place where I
  thought it was returning 0 for a boolean.

Now we've eliminated this bad interaction between tangling and punning
literals.
2018-06-17 00:29:22 -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 K. Agaram
4a48bedcd1 4134 - 'input' = 'ingredient' 2017-12-03 23:25:40 -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
459cdb3da5 4091 2017-10-29 12:23:34 -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
636837e7d9 4086 - back to cleaning up delimited continuations 2017-10-18 20:08:05 -07:00
Kartik K. Agaram
2b25071710 3877 2017-05-26 17:36:16 -07:00
Kartik K. Agaram
5e320aa049 3876
Thanks Ella Couch for reporting this issue.
2017-05-21 22:19:28 -07:00
Kartik K. Agaram
f8b0b04da1 3833
Loosen type-checking slightly to accomodate type abbreviations.
2017-04-18 18:04:50 -07:00
Kartik K. Agaram
09125ea216 3802 - more accurate sandbox results
Thanks Lakshman Swaminathan for reporting this issue.
2017-03-20 12:55:36 -07:00
Kartik K. Agaram
b5f2a629c2 3752 - fix a couple of segfaults
Thanks Ella Couch for running into these.
2017-03-02 22:41:18 -08:00
Kartik K. Agaram
3c4c9c0807 3744
Undo 3743. Really any time we create new instructions from whole cloth
during rewriting or transform, the whole notion of 'original name' goes
out the window. Pointless trying to fight that fact of life.
2017-02-07 00:07:16 -08:00
Kartik K. Agaram
d9e39b3b1c 3743
One way to ensure we always set old_name is to create a method to
initialize names as opposed to just assigning them.

Still not ideal because we still assign directly most of the time, so
it's easy to forget.
2017-02-07 00:05:38 -08:00
Kartik K. Agaram
c8f2ff1392 3657 - better error message
Thanks Ella Couch for reporting this.
2016-11-10 10:34:16 -08:00
Kartik K. Agaram
f116818c7c 3656
Periodic cleanup to replace 'reply' with 'return' everywhere in the
repo.

I use 'reply' for students to help reinforce the metaphor of function
calls as being like messages through a pipe. But that causes 'reply' to
get into my muscle memory when writing Mu code for myself, and I worry
that that makes Mu seem unnecessarily alien to anybody reading on
Github.

Perhaps I should just give it up? I'll try using 'return' with my next
student.
2016-11-10 10:24:14 -08:00
Kartik K. Agaram
91f220ae69 3598 - 'use before set' errors were too cryptic 2016-10-27 09:10:38 -07:00
Kartik K. Agaram
ae9db5a45f 3587
Another CI fix.
2016-10-24 08:57:45 -07:00
Kartik K. Agaram
61880904a2 3576
More helpful messages when people forget 'load-ingredients'.
2016-10-23 22:07:14 -07:00
Kartik K. Agaram
d8509b4175 3555 2016-10-22 16:10:23 -07:00
Kartik K. Agaram
3b107f1863 3554 - flag unexpected header for recipe 'main'
As long as Mu operates atop Unix, we need to make these assumptions.

Thanks Ella Couch for finding this loophole.
2016-10-22 16:04:47 -07:00
Kartik K. Agaram
2d29369f92 3541 2016-10-21 09:17:35 -07:00
Kartik K. Agaram
66abe7c1bd 3539
Always check if next_word() returned an empty string (if it hit eof).

Thanks Rebecca Allard for running into a crash when a .mu file ends with
'{' (without a following newline).

Open question: how to express the constraint that next_word() should
always check if its result is empty? Can *any* type system do that?!
Even the usual constraint that we must use a result isn't iron-clad: you
could save the result in a variable but then ignore it. Unless you go to
Go's extraordinary lengths of considering any dead code an error.
2016-10-21 01:13:27 -07:00
Kartik K. Agaram
6c96a437ce 3522 2016-10-19 22:10:35 -07:00
Kartik K. Agaram
38e96056e4 3437
Drop an ancient case of premature optimization: skipping transform for
recipes without bodies. These days recipes also have headers that need
transforming.

Thanks Caleb Couch for running into this issue.
2016-10-04 09:13:25 -07:00
Kartik K. Agaram
0f2781f8a2 3393 2016-09-17 14:43:13 -07:00
Kartik K. Agaram
a0331a9b0e 3390 2016-09-17 13:00:39 -07:00
Kartik K. Agaram
760f683f27 3389 2016-09-17 12:55:10 -07:00
Kartik K. Agaram
7a84094adb 3385 2016-09-17 10:28:25 -07:00
Kartik K. Agaram
08f4628e8b 3379
Can't use type abbreviations inside 'memory-should-contain'.
2016-09-17 00:31:55 -07:00
Kartik K. Agaram
59e47aca14 3341
Process type abbreviations in function headers.

Still a couple of places where doing this causes strange errors. We'll
track those down next.
2016-09-12 10:00:43 -07:00
Kartik K. Agaram
cdf0f349d1 3324 - completely redo type abbreviations
The old approach with '&' and '@' modifiers turned out to be a bad idea
because it introduces notions of precedence. Worse, it turns out you
want different precedence rules at different times as the old test
alluded:

  x:@number:3  # we want this to mean (address number 3)
  x:address:@number  # we want this to mean (address array number)

Instead we'll give up and focus on a single extensible mechanism that
allows us to say this instead:

  x:@:number:3
  x:address:@:number

In addition it allows us to shorten other types as well:

  x:&:@:num

  type board = &:@:&:@:char  # for tic-tac-toe

Hmm, that last example reminds me that we don't handle abbreviations
inside type abbreviation definitions so far..
2016-09-11 17:50:36 -07:00
Kartik K. Agaram
8d72e56521 3120
Always show instruction before any transforms in error messages.

This is likely going to make some errors unclear because they *need* to
show the original instruction. But if we don't have tests for those
situations did they ever really work?
2016-07-21 19:22:03 -07:00
Kartik K. Agaram
2b4eb0cc63 3062 2016-06-19 09:55:29 -07:00
Kartik K. Agaram
9dcbec398c 2990
Standardize quotes around reagents in error messages.

I'm still sure there's issues. For example, the messages when
type-checking 'copy'. I'm not putting quotes around them because in
layer 60 I end up creating dilated reagents, and then it's a bit much to
have quotes and (two kinds of) brackets. But I'm sure I'm doing that
somewhere..
2016-05-20 22:11:34 -07:00
Kartik K. Agaram
be92feb761 2987 2016-05-20 12:49:31 -07:00