Sei-Lisa / LSL-PyOptimizer

Optimizes a LSL2 script, folding constants, removing unused code and more. Adds new syntax features too.
GNU General Public License v3.0
35 stars 11 forks source link

Integration with Firestorm preprocessor conditional defines #16

Closed PeterStindberg closed 2 years ago

PeterStindberg commented 2 years ago

I am using the Firestorm preprocessor conditional defines quite extensively. So my workflow looks like this:

  1. Edit code in Visual Studio Code
  2. Paste it into SL and let it compile
  3. Grab the preprocessed output
  4. Run the preprocessed output through PyOptimizer
  5. Paste the preprocessed and optimized code into SL again and let it compile

It would be nice if that workflow could be reduced a bit if PyOptimize would recognize the FS conditional defines.

rweber89 commented 2 years ago

That sounds insanely tedious. I've actually got an IDE that opens up, supports including relative library files, and never have to go and copy paste things inbetween. I guess I should probably look at making it possible to hook PyOptimizer into that at some point. It only does minor const optimizations at this stage, the big benefit is eliminating all of the usual hassle around scripting.

Sei-Lisa commented 2 years ago

The FS conditional defines are provided by a C language preprocessor embedded into Firestorm. LSL-PyOptimizer includes support for a C preprocessor; you don't need to use Firestorm's. Look into the documentation for how to enable the preprocessor; you'll need an external program for that. There is also a branch that provides a built-in preprocessor, see https://github.com/Sei-Lisa/LSL-PyOptimizer/tree/preprocessor , but it's not merged into master because it depends on an external library which would complicate installation.

My personal workflow is to have the script in Firestorm be just a single line:

#include "/path/filename.lsl"

Then I use a Makefile to automate the build, so after saving the file in the (external) editor, I type make and that triggers the preprocessing and optimization. Some editors allow you to have that as a shortkey, but I haven't configured mine for that. Then I click "Recompile" in Firestorm and test. So, testing consists basically of three very simple steps: save, execute make, click Recompile. No need to copy/paste anything back and forth, because the #include reads the file from your disk, and the preprocessor takes care of the conditional defines.

You may need to configure the include path in Firestorm for #include to be able to find the file in your disk. Also, it's best to use forward slashes rather than backslashes for the paths. It may not matter in this case but it's good practice.

If you have trouble with Makefiles, you can also use a batch file. There's a (somewhat complex) Makefile in the AVsitter repository that uses a preprocessor; you can use it as an example: https://github.com/AVsitter/AVsitter/blob/master/AVsitter2/Makefile