-
Notifications
You must be signed in to change notification settings - Fork 15
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
Provide a command-line tool for linting and refactoring 007 code #14
Comments
I think this one would be great to tackle, because it would shake out relatively common patterns of dealing with code. Though linting and refactoring are still distinct from the kinds of analysis and manipulation a macro might want to do, they are in the same ballpark — chances are that making the API nicer for the former also makes it nicer for the latter. |
Though it's not a blocker by any means, it's intriguing to think that after we have #38, we might write this tool in 007 as well. That's not to say we shouldn't have a Perl 6 implementation first, of course. |
oh, and a code tidy-fierLike Perl::Tidy or gofmt.
|
Why wait until we have a 007 parser in 007? We can just parse using the Perl 6 parser, and then run the 007 script on the resulting Qtree. I'm having some further thoughts on the API layer here between 007 and the linter tool, though. More to follow. |
I wanted to say that the "before" here is interesting. It's not "source order", it's execution order. #160 is a good example of when the two differ:
In the above code, the Since #160 is a language-extending macro, this also indicates that macros (and similar) need to be "transparent" to control flow questions. In the best case this is as simple to the linter working on the expanded code in this case (as opposed to when it checks for macro usages, in which case it needs to work on the unexpanded code), and then we just declare how control flow works for all our language primitives. |
I slapped a "needs more design" on this issue, because that's my explanation of why it's stalled since its creation back in 2015 (gasp). Case in point, the previous comment points the way to the fact that even something as simple as use-before-assign relies on full Data flow analysis. The design must incorporate that. A case of "this feels pretty easy", and then the innards fairly intricate, but the tool hides that and is still quite easy to use. |
Just driving by to say (again) that this issue is "CFG-compete", in the sense that compete information about the CFG is required to do a sufficient analysis for linting. Which is why #379 and similar are useful for this. |
Call the command
spy
, to continue the 007 theme.It would have two major parts: a linter, and a refactoring tool.
linter
Called with
spy --lint script.007
, the tool could detect various things that are smells rather than errors in a 007 program:return
orthrow
, or code after conditions that is never reached)a ?? a !! b
, which could just bea || b
)while
loops that will never run+none
)if
statement and assigningnone
)refactoring tool
Being refactors, the actions that affect parameters should also make sure to do the "corresponding" things to arguments at all statically detectable call sites.
what's needed to get there
The compiler already generates a Qtree for consumption by the runtime. The thing that needs to be built on top of that is a layer of primitives for locating stuff in the Qtree, and to manipulate it. Also a greater awareness of the connection between Qtree and original source text is needed.
The text was updated successfully, but these errors were encountered: