-
Notifications
You must be signed in to change notification settings - Fork 14
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
Feature/compile pattern matching #187
Conversation
@@ -139,7 +139,7 @@ object Transformer { | |||
case lifted.App(lifted.BlockVar(id), List(), args) => | |||
// TODO deal with BlockLit | |||
id match { | |||
case symbols.UserFunction(_, _, _, _, _, _, _) => | |||
case symbols.UserFunction(_, _, _, _, _, _, _) | symbols.TmpBlock(_) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The matching here on symbols here is a smell. What is it that you really need here?
}; | ||
transform(scrutinee).run { value => | ||
Switch(value, constructors.map { | ||
constructor => clauses.find { _._1 == constructor } match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary anymore, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://llvm.org/docs/LangRef.html#id39
switch i32 %val, label %otherwise [ i32 0, label %onzero
i32 1, label %onone
i32 2, label %ontwo ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The machine Switch just also needs a default label:
Currently:
case Switch(scrutinee: Variable, clauses: List[Clause])
Proposed:
case Switch(scrutinee: Variable, clauses: List[(Int, Clause)], default: Clause)
Note, that each clause also has an integer value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Over the weekend, I implemented a first draft of a match compiler. This should make life easier for all backend developers,
including LLVM (@phischu), JIT (@marzipankaiser), and MLTon (@JonathanStarup).
The match compiler is based on these notes by Jules Jacobs (@julesjacobs -- thanks a lot for these notes!):
https://julesjacobs.com/notes/patternmatching/patternmatching.pdf
Right now, the only implemented backend is JS (so LLVM and Chez are still missing for the tests to pass).