Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Optimization of constants does not work in all cases #60

Open
rweber89 opened this issue Jan 14, 2016 · 1 comment
Open

Optimization of constants does not work in all cases #60

rweber89 opened this issue Jan 14, 2016 · 1 comment

Comments

@rweber89
Copy link

if(MAIN_MENU == TRUE && cmd == "TEST_TRUE")
{
llOwnerSay("TEST TRUE");
}
else if(MAIN_MENU == FALSE && cmd == "TEST_FALSE")
{
llOwnerSay("TEST FALSE");
}


Consider this for a moment, where MAIN_MENU is a constant integer passed in at module inclusion. Now the problem is that instead of optimizing this away (as we have no preprocessor directives to work with) - it does this:


if ((1 && (cmd == "TEST_TRUE")))
{
llOwnerSay("TEST TRUE");
}
else if ((0 && (cmd == "TEST_FALSE")))
{
llOwnerSay("TEST FALSE");
}


The compiler could check if an If( ... ) will always return 0 and then optimize it away. The same goes for 1 &&. So there could be a particular rule for optimizing away anything execution inside of an "0 &&" and removing an "1 &&" as that is completely redundant.

@furroy
Copy link

furroy commented Jul 2, 2017

i don't think it can do this because LSL does not short circuit when executing boolean expressions, so you would get different behavior between forge and LSL in cases where expressions have side-effects.

however, this is a quirk with strings and i often use this to my advantage. if i have a toggle setting i want to strip away code i'll make a variable integer DEBUG=TRUE; and if (Debug) but sometimes i want to be able to flip this back and forth inside the generated LSL script. in these cases i'll do string DebugLSL="1"; and if (DebugLSL=="1") and this code will still appear in the final LSL.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants