The optimization in sslc is broken. Crazy side effects are observed like merging variables when they shouldn't be merged... It would be cool to be able to set optimize level in Script editor and inside sslc itself, don't merge variables or other crazy unstable stuff at optimize level 1 for example... I don't want to remove optimization altogether, there are useful features like removing unused procedures.
Can I have an example script that optimization is breaking please? Different optimization levels sounds like the sort of quick short term fix I'd actually have time for, but if I get a chance later I'd like the fix the actual problem.
I need some time to find and identify all problems and then refine them to simplest example functions... I'm sure there was one problem with variable merging (optimizer somehow merged variable that was used later) and maybe something about deleted code after conditional return statement. Too bad I forgot the details and could not reproduce it right now... Fact is, some of my scripts was not working with enabled optimization and work perfectly when disabled (I think Mr.Fixit mod is affected).
However, I have a suggestion. You already have -O parameter that defines optimization level. Why don't you make it so level 1 optimization will only do DecendUnusedProcedures(prog); and EliminateUnreferencedGlobals(prog); and level 2 enables the complex stuff?
I did my version of sslc back then, commented out fancy optimization and left only removing unused stuff - that really improved my scripting as I became more confident in creating many procedures in libraries and compiler only include procedures that I actually use (unnecessary stuff removed from my compiled scripts).
Here is my changed code if you interested:
View attachment sslc src.zip (it also prints message if optimize or backwardcompat was enabled, in console)
I also urge you to take a look at script parser in GUI script editor, if you'll have time. It crashes badly in several cases (I think it's compiler crashing causing GUI to show .NET error dialogs), for example if you write function declaration without definition. That really bugged me when I was writing scripts as this parser seem to execute itself once in a while. Expected behavior: ignore such declarations without crashing on parse, only print error on actual compiling.
Other thing related to parser - when I edit multiple scripts (let's say a.ssl and b.ssl), sometimes when b.ssl is active tab, treeview shows procedures from a.ssl (when I click them - it takes me to other tab), that's really confusing.
I think I've found a serious problem with list_as_array(LIST_CRITTERS) function.
<snip>
That's... weird. The only thing if(crit) would protect against would be crit being null, but that would have crashed inside sfall while building up the array, because sfall would be accessing each object to check if it's a critter. And even if crit did end up null, debug_msg("crit: "+crit) would just print 'crit: 0' rather than crashing... Maybe crit is ending up with the wrong attached type? :/
I just did a few tests myself, but I couldn't get any odd behaviour loading up a few saves, killing a few critters, exiting the map, coming back later, waiting for corpses to decay, etc. Do you have a reliable way to reproduce it?
It's related to a specific map you're in. Try EPA maps from latest RP. I'm sure some of them had this problem when I was debugging my traps (I cycle through all critters to do manual explosion). I have a savegame near EPA but it requires my mod to load...
PS: thank you again for all the great tools and modifications. I'm your fan