ref: 0088875fe0b08bd1ddffe4c39c378884ae578550 Carth/src/Subst.hs -rw-r--r-- 2.4 KiB
Scale datatype tag size by n of variants. 1 variant => no tag

Types with only 1 variant have no tag. Types with <=2^n variants have
n-bit tag.
Rename main to start & fix start-related stuff

First, the reason for the rename. Having both an "outer" and an
"inner" main named main (with LLVM kindly generating some suffix to
separate them) was just not very pretty looking. Another problem was
that, while not possible before, e.g. recursing in main would not
work, as the main found would not be the inner main, but the outer
main. Renaming the inner (user defined) main to start alleviates this

Another approach we could've taken is to rename the outer main, and
tell the linker (via GCC/Clang) that we have another entrypoint than
main. I started working on this, but just appending a "-e outer_main"
flag was no good. The problem was that the entrypoint changed was not
main to outer_main, but rather _start to outer_main. This was no good,
as _start usually sets up some things before calling main, and the
result was segfaults.

Also, now start (main) is treated more like any other global def, and
you can call main from other functions and recurse etc. I had to fix
how main is typechecked a bit for this to work correctly.
Fix not substituting tvars in DLeaf VarBindings
Add `box` and `deref`

Heap allocation and pointer dereferencing. Required for recursive
datatypes like lists.
Check that no type vars are left after infer & subst

Crappy implementation -- just wanted it done asap. The error doesn't
tell what part of the type is still ambiguous, and some of
the (position, type) combinations of the check are kind of arbitrary.
Separate module Infer from Check
Separate desugaring stage

I think it will be particularly useful later when adding a check for
type vars being bound after inference. Also, will be nice if more
sugar is added later.
Consider wildcard expressions and patterns
Impl simplified C calling convention

Pass structs (other than unit) by reference in parameters and return
them via `sret` out parameters.
Add type `TPtr`

Useful for FFI, and will probably serve as a building block for GC /
owned pointers later.
Add external item declarations

To test it out, change print-int from being a builtin to being an
extern function.
Integrate Match with rest of compiler

Until now, the Match module was just kind of for "testing". It wasn't
actually used in the rest of the compiler. This commit replaces my
earlier, quite bad implementation of pattern matching to decision
trees with Sestofts one.

One major change made along the way was to how sub-matchees are
accessed in the code-generator and interpreter. Previously, the
decision tree was assumed to be structured such that we could simply
extract sub-matchees and put them on a stack. As far as I understand
it, that way is incompatible with Sestofts trees, as they can "skip"
steps that are known to be irrefutable in context. As such, I have
chosen to augment the `Access` type with some additional information,
such that the value of a sub-matchee can simply be generated from the
Access-path as needed, with memoization in the Selections module. See
Impl pattern matching w decision trees & check for redundancy

TODO: Check for exhaustiveness. TODO: Use the stratergy in that paper
on "good decision trees" for picking columns instead of just building
the tree left-to-right.

Sorry for the big commit. This wasn't the easiest thing to
implement. Took a while to understand how the whole thing would work,
and had lots of small problems along the way. However, I'm mostly
satistied with the result.