tekknolagi / stackx

MIT License
2 stars 0 forks source link

Type checker #3

Open tekknolagi opened 7 years ago

tekknolagi commented 7 years ago

Simple type checker; should not be too complicated. Already sort of in the works in mb-parser.

tekknolagi commented 7 years ago

This would be probably better as a series of AST passes that get mapped over

KCreate commented 7 years ago

Agreed, type checking should just be a semantic pass not modifying the AST at all.

tekknolagi commented 7 years ago

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.

KCreate commented 7 years ago

I don't know how reason does it. Maybe write a basic example?

tekknolagi commented 7 years ago

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.

KCreate commented 7 years ago

I see.

tekknolagi commented 7 years ago

This is reasonably complete for a first pass.

tekknolagi commented 7 years ago

Requesting review from @akkartik and @KCreate

KCreate commented 7 years ago

What features are currently supported?

tekknolagi commented 7 years ago

The type checker checks types throughout the AST. The const checker checks assignment to const variables throughout the AST. That's about it.

KCreate commented 7 years ago

No, I meant what parts of the ast are being type-checked. Assignments, arithmetic, function calls?

tekknolagi commented 7 years ago

Everything!

tekknolagi commented 7 years ago

It's only ~100 lines; worth a look.