-
Notifications
You must be signed in to change notification settings - Fork 46
Rust Engine: print infrastructure #1600
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
Conversation
46306f4 to
af84fbc
Compare
clementblaudeau
left a comment
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 PR addresses a real issue of verbosity when writing backends. It will make the code more concise and provide better error messages when parts of the ast are unsupported.
3d8ec14 to
0ae2e7a
Compare
0ae2e7a to
643423e
Compare
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.
Clément already brought up a lot of things I wanted to ask about, and you already addressed those.
I have, as usual, some questions, but I think the code is good!
|
Thanks @clementblaudeau and @jschneider-bensch for your reviews! :) |
This PR adds a improves the printing and backend infrastructure.
The
PrettyAsttraitThe main change of this PR in the introduction of the
PrettyAsttrait, that reduces boilerplate.Instead of implementing
pretty::Prettyfor every type of the AST, one must only implementPrettyAst, which has default methods.The default methods print debugging information that makes it easy to iterate when writting a printer.
Helper macros
The
prettylibrary we are using for pretty printing uses an explicit allocator: whenever we must render a node, the allocator needs to be specified expclitely.As it is visible in the existing lean printer, this is very verbose.
This PR introduces
pretty_ast::install_pretty_helpers!, a macro that hides this allocator away. This macro basically creates partial applications of the allocator method using a local variable.Instead of doing:
You can do:
We also introduce the macro
prepend_associated_functions_with!(something)that prependssomethingto each body of associated function.Combining the trait
PrettyAst, the macroprepend_associated_functions_withand the macros given byinstall_pretty_helpers, we get implicit allocator across entire printers.See
backends::rustfor an example.Rust Printer
This PR introduces a dummy placeholder Rust printer.