tomhrr / dale

Lisp-flavoured C
BSD 3-Clause "New" or "Revised" License
1.02k stars 48 forks source link

Output Macro Expansions #181

Open BitPuffin opened 7 years ago

BitPuffin commented 7 years ago

I was thinking about how to make a nice auto completion thingy for Dale. And figured that it should be pretty easy to add a side module to the compilation and use the compile-time introspection to probe for a bunch of information like what types there are and what fields they have and what functions exist, where they are (so you can jump to definition).

One thing that probably seems impossible to do from the viewpoint of the program being compiled, is to find all the places where there are macro invocations, and get a text representation of what it was expanded to. This would be really useful information to have in your editor. Just select the code you have written and ask for what it looks like after expansion.

So either it should be possible to figure this out with macro expansion some how. Or a flag can be added to the compiler which spits out a file that contains all the macro expansions in text for all the locations in the program. Which seems to me like the best option for that. But then it almost starts feeling like you may as well implement all these "IDE" tools in the compiler itself if you're already gonna do this. So not sure about the introspection approach (though it is cooler and nice to write it in Dale itself).

BitPuffin commented 7 years ago

Seems like #110 is related to this issue. If that suggested way of implementing it I'm not sure how it would aid with this issue. Hmm. But either way, solving either issue should make it possible to share a lot of code for implementing the functionality wanted in these issues.

tomhrr commented 6 years ago

Or a flag can be added to the compiler which spits out a file that contains all the macro expansions in text for all the locations in the program. Which seems to me like the best option for that.

There is the --print-expansions compilation flag, which will cause all macro expansion details to be printed to standard output. Does that look like it will do the job?

BitPuffin commented 6 years ago

Hmm maybe! Would have to give it a run to see what it prints..

BitPuffin commented 6 years ago

Gave it a test run with the macro example. I think this could do what I had in mind. I might do some experimentation with it when I have time!