tekknolagi / stackx

MIT License
2 stars 0 forks source link

Arbitrary AST passes #4

Open KCreate opened 7 years ago

KCreate commented 7 years ago

I'd like to discuss how we'll build the mechanism that allows for arbitrary AST passes. The passes would modify the AST in place, since we don't need any old versions of the AST.

I was thinking of something like this (pseudo-code):

let myAST : AST = parse(source);
semanticpass(myAST);
constantfolding(myAST);
deadcodeelimination(myAST);
KCreate commented 7 years ago

Passes could return some kind of status code or maybe throw exceptions (do we want to use exceptions?).

tekknolagi commented 7 years ago

Looks good! This exists already in master. Exceptions are heavily used in OCaml.

tekknolagi commented 7 years ago

(but mutability is not much used, so we'd probably fold the passes over the AST instead)

tekknolagi commented 7 years ago

Worth also checking out testast.ml in the project root and its use of polymorphic variants: screenshot from 2017-05-31 16-52-48