~jojo/Carth

ref: 0088875fe0b08bd1ddffe4c39c378884ae578550 Carth/src/Ast.hs -rw-r--r-- 9.5 KiB
Fix some trivial warnings
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
  (fun-match
    ((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!
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
issue.

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.
Fix codegen of strings

The type of the GlobalReference was wrong before, also we've removed
TStr in favor of a datatype built on `TPtr Nat8`.

Also, add a system for adding builtin datatypes that doesn't require
any ugly hacks with dummy-positions and stuff.
Add type `TPtr`

Useful for FFI, and will probably serve as a building block for GC /
owned pointers later.
Add primitive types Nat,{Nat,Int}{8,16,32}

Useful for FFI. No way of constructing them or casting between them
yet (except for FFI).
Add external item declarations

To test it out, change print-int from being a builtin to being an
extern function.
Add phantom param to Id to encode upper/lower case

Will be useful when instancing Arbitrary, to have separate instances
for each case.
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.
Impl genMatchPattern>PConstruction, genCtion
Improve what data about ctors&tdefs are passed from Check to Codegen

Codegen should have to do as little environment lookups and stuff as
possible, if it can be done earlier in Check and Mono. Now Check
manages to simplify what data is passed along for constructors. One
thing that is gone is the constructor name--only the index (which is
what matters) is preserved.
Minor changes
Minor fix in prettyTFun
instance Eq Pat & move stuff around

The eq for pat ignores srcpos
Next