Open tekknolagi opened 7 years ago
This would be probably better as a series of AST passes that get mapped over
Agreed, type checking should just be a semantic pass not modifying the AST at all.
Sorry, what I mean is: if there are a number of passes that have the same API, we could just map them each over the AST, like https://github.com/facebook/reason/ does.
I don't know how reason does it. Maybe write a basic example?
Sure. It's sort of like this:
let type_check ast = ...
let const_check ast = ...
let passes = [const_check; type_check]
let () =
let ast = parse ... in
List.iter (fun p -> p ast) passes
but with the added ability for each particular pass to only match the parts of the AST that it wants to. If you want to read more, look into https://caml.inria.fr/pub/docs/manual-ocaml/libref/Ast_mapper.html. It took me a while to understand but it makes a lot of sense after messing with it for a couple months.
I see.
This is reasonably complete for a first pass.
Requesting review from @akkartik and @KCreate
What features are currently supported?
The type checker checks types throughout the AST. The const checker checks assignment to const variables throughout the AST. That's about it.
No, I meant what parts of the ast are being type-checked. Assignments, arithmetic, function calls?
Everything!
It's only ~100 lines; worth a look.
Simple type checker; should not be too complicated. Already sort of in the works in mb-parser.