How does Purescript Compiler work?

Since there is no documentation for complier.

Is the general flow of the program like this?
Tokenize --> Pattern match on tokens --> Create JS AST --> Parse AST --> Get JS code?

I see that the patterns are being matched in CodeGen/JS.hs file, especially the binderToJs' functon.
Is there a PS AST as well?

Can someone briefly help me with the big picture and structure of the Compiler?

2 Likes

I would describe the compiler pipeline as follows:

Tokenize -> Parse CST -> Convert to AST -> Desugar -> Type check -> Convert to CoreFn -> Convert to JS

The desugaring step handles things like do notation and name resolution, and generally puts the AST into a simpler form so that it’s easier to type check. Let me know if I can provide more clarity on any of the others.

3 Likes

Lately I’ve been studying some parts of the purescript typechecker a lot. It would be useful to have some sort of list with all the papers it implements!

Did you see Academic / theoretical basis of the PureScript type system?

1 Like