ref: ae1d242d7d48292779dcbd953e5864bb4211e1ca Carth/src/Misc.hs -rw-r--r-- 3.4 KiB
Update stackage release & use default-extensions in cabal file

Also, fix some minor breakages caused by ghc update, fix the
literate.org example, fix some new warnings, and get rid of the need
for a bunch of Data implementations by using basic parsing functions
in SystemSpec.hs.
Add patterns & declaration of literals in macros

Example of a do-notation-like macro using the new features:

    (defmacro do (<-)
      (case (do-bind ma) ma)
      (case (do-bind (<- a ma) mbs ...)
            (do-bind (fun (a) (do do-bind mbs ...)) ma))
      (case (do-bind ma mbs ...)
            (do-bind (fun (_) (do do-bind mbs ...)) ma)))

which can be used like

    (do list/bind
        (<- i (list 1 2 3))
        (<- j (list 1 2 3))
        (if (< i j)
            (list/singleton [i j])
Make some strict Map:s lazy, and some lazy State:s strict

No great reason. Just seemed more reasonable. No obvious performance impact.
Make parser act on token trees instead of chars
Begin work on lexer

I feel like adding a token(tree)izer for mainly two reasons.

1. Separation of concerns. Parsing code will be simpler if we can
   separate out the lexing part.

2. In preparation for macros. Macros should act on token trees, so
   creating an in-between step is pretty much needed.

Currently, Lex.hs and Lexd.hs work and feel pretty much done, but
they're not connected to the rest of the compiler. What remains is to
rewrite Parse.hs to act on TokenTree:s instead of parsing text from
Fix partitionWith reversing lists. Caused def order issue in genInit

genInit must genDefineGlobVar:s in topological order, but an earlier
call to partitionWith had accidentally reversed the topological order,
causing this to break:

    (define (main r) (bar r))
    (define bar bar1)
    (define bar1 foo)
    (define (foo r) [Unit r])
Test that good programs produce expected output

For the programs in test/tests/good/, compile and run the program,
capturing stdout. If the string of stdout matches the text in the
first comment of the file, the test passes.
Generalize `augment` to work on any lens to Monoid
Change formatting: 90 cols, IndentPolicyFree, etc. Add brittany.yaml

Most people have pretty wide and high res screens at this point. I
can't fit two windows with 100 line length next to eachother with my
font size, but 90 works and most people have smaller font size than me
I think.

Also, change brittanys indentation policy to Free. This almost always
looks better. I just had to disable formatting of imports -- I don't
want to align those, but IndentationPolicyFree insists.

Finally, actually add a project-local brittany config file, so that
anyone (or me in the future / on another computer) can use the same
formatting rules.
Add global variables

Previously, top-level definitions could only be functions. Now,
non-function variables are initialized with `carth_init` in `main`.

Could be interesting to initialize them at compile time instead, using
some kind of compile-time evaluation mechanism, probably using the JIT.
Refactor global & let definitions

Instead of jumbling together function and var defs and just checking
which is which at the end in Codegen, treat them very separately and
remember the grouping for recursive defs.

For now, just moves around complexity really. I don't remember how
exactly, but I thought this would be necessary for the next feature,
which is allowing patterns in left hand side of var defs.
Use Inferred.builtinExterns to expose builtins both to user and Gen

Gen.builtinsHidden - Builtins only usable with Gen.callBuiltin

Inferred.builtinExterns - Available both to the user and
Gen.callBuiltin. Passed through the stages to end up as
Fix wrong fixity of .*, .**
Preserve topolog. order from Infer to Codegen. Important in genLet

Unlike for global definitions, the bindings of a `let` may be
non-function variables. In the generated code, these variabled must be
defined in topological order, as they'll just be reading undefined
stuff otherwise.
Add convenience function `locallySet l = locally l . const`
Check user-written types in Infer

Basically, do `checkType` for user-written types. It detects
references to undefined types. Also, separete AnnotAst.Type from
Ast.Type to help enforce that this is done. This whole ordeal required
some refactoring.
Remove not-really-needed deps llvm-hs-pretty & prettyprinter

They weren't unused, but very unimportant. We can do things in a very
slightly worse way if it means simplifying our dependency graph!
Substitute dep `lens` with `microlens-platform`. Faster to build.

`lens` is quite a large dep, while `microlens-platform` is quite a bit
smaller but still has most of the stuff I need. I just needed to
reimplement `locally`, `scribe`, and `(<<+=)`, but they're all one
liners so nbd. Also needed to change some `{views,uses} l f` to
`{view,use} (l . to f)`. Minor stuff.
Move a couple of defs from Misc to PrettyAst