ref: b1a31147fdef08e7538812603bbfbd31605326dc Carth/src/Infer.hs -rw-r--r-- 15.0 KiB
Allow patterns in parameter of fun

Refutable patterns will raise an error in the type checker.

Added bonus is that `fun` is now equivalent to a sugared, special case
of `fun-match`, and is desugared as such in Infer.
Allow Box in pattern to dereference
Delay StartNotDefined error until after typechecking
Fix fun-match globals not allowed to be recursive

;; This was and should be allowed
(define (foo x) (foo x))

;; This was and should be disallowed
(define foo foo)

;; This was disallowed, but should be allowed
(define foo
    ((case x
           (foo (deref x))))))
Allow integer and boolean literals in patterns

Could exploit the existing Match.PCon constructor to represent not
just datatypes, but these other enumerables as well. Didn't have to
make many additions/modifications at all -- quite nice!
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.
Fix some harmless warnings
Check that non-func var defs aren't recursive

Because we can't compile that with strict evaluation!
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.
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