-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ast #273
Conversation
Also puts this stuff in thorin::ast
Also: switched role of LamDecl/LamExpr
* better error messages
* added warning * polished error handling
@NeuralCoder3, @fodinabor: bump |
Why is this necessary? |
This way, we can better restrict and control what an external declaration is. E.g., we can't have a curried function or a function taking type variables as arguments as external declaration. Note that |
This PR adds a proper AST that the parser constructs before emitting actual Thorin code.
While this adds some boilerplate it also reduces a lot of weird hacks/workarounds in the parser as we can now do one thing at a time and we don't have to do everything from left to right; we can traverse the AST as many times as we want and in any order we want. Finally, I want to add in a future PR a proper Thorin -> Thorin-AST decompilation for a proper output.
Rn, the pipeline looks like this:
ast::IdExpr
with itsast::Decl
and does some other minor semantic checksChanges in the Frontend
Parentheses for filters are not mandatory anymore:
fn (a: A)@(.tt): B
->fn (a: A)@.tt: B
Removed
!
for specifying filters.There were only a handful of
!
s in our code base that we actually needed. Changing those few instances to@.tt
isn't a big deal and having two ways for specifying filters just adds confusion and code complexity on our side.Declaration expression:
d* e
This makes block expressions superfluous as you can simply use a (possibly parenthesized) declaration expression instead. For this reason, the parser emits a warning that block expressions are deprecated. On top of that, you can use declaration expressions in other useful occasions like this:
Where expression:
e .where d* .end
This is a reverse declaration expression: The declarations are bound first (in reverse order), than the expression is bound.
Example:
.Pi F: T = Π /*...*/
->.rec F: T = Π /*...*/
.Sigma S: T = [/*...*/]
->.rec S: T = [/*...*/]
In addition:
.rec f = .lm /*...*/
=lam f /*...*/
.Same for
.cn
/.con
.fn
/.fun
.and
clause for mutual recursion:Or for mutual recursive types:
No more forward decls for
.lm
/.lam
,.cn
/.con
,.fn
/.fun
or types.Use
.let
,.where
,.rec
,.and
instead.For declaring C-Functions that you want to link later on use new
.ccon
/.cfun
decl:Or more low-level:
New output:
./thorin --output-ast -
that directly emits the AST representation.Here is still work to do but I will address this in future PRs.
Other Changes
thorin::fe
->thorin::ast
Loc
of thorinDef
s inemit