Commit graph

30 commits

Author SHA1 Message Date
Sei Lisa
a6cce58b5d Fix invocation of PythonType2LSL
Fixes #32. Thanks to @KrsityKu for the report and repro.
2024-05-24 20:28:26 +02:00
Sei Lisa
bf505220ac Calculate llFrand's min and max when possible 2024-05-07 00:07:17 +02:00
Sei Lisa
1e1f181b82 Fix deletion of if (SEF_expr) ;
Fixes #29. Thanks @KrsityKu for the test case, which was added to the test suite.
2024-04-20 20:11:01 +02:00
Sei Lisa
b7f16900ed Update to kwdb 0.0.20240415000
Quite some new functions and constants.
2024-04-15 16:15:56 +02:00
Sei Lisa
28b42e7c6b LL fixed the overflow in llAbs() in Mono 2023-11-18 13:08:50 +01:00
Sei Lisa
6e229313b1 Add regresion test for continue-in-for
Just to ensure that the third part of the for loop (the updater expression list) is correctly run every iteration when 'continue' is used.
2023-03-02 17:19:31 +01:00
Sei Lisa
d58217ad96 Fix llDumpList2String disaster with string addition
The node containing the separator was not being copied; if it was modified by a later optimization step, the modification propagated to all previous nodes that contained it, causing incorrect results.

Many thanks to @KrsityKu for reporting and providing a repro.

Fixes #23.
2023-02-26 09:46:54 +01:00
Sei Lisa
d6162dfcf2 Remove llGetEnv tests from tests; don't generate list in list
llGetEnv() is not computable now, so remove it from the computable functions unit test.

The test generated lists inside a list, and after the llGetEnv() change, that caused a weird side effect that hasn't been investigated (see test result of previous commit). To be on the safe side, take all list-generating results out of the list, into their own llSetPrimitiveParams call.
2023-02-03 21:47:37 +01:00
Sei Lisa
e3c1634724 Fix regression introduced with the latest changes to loadlib
In Python 2, function type names from buiiltins.txt were entered into the tables as Unicode, causing the output module to promote strings to Unicode, and causing trouble further down the line.

Entering them as str fixes the issue.

Thanks a lot to @PeterStindberg for reporting the issue and providing a script that reproduces it.

Fixes #21
2023-01-09 11:03:41 +01:00
Sei Lisa
08c429f22b Add IfElseSwap option
This enables an option that was being done unconditionally: to swap the `if` and `else` branches if the condition is shorter when negated.

Enabled by default.
2022-10-31 20:08:26 +01:00
Sei Lisa
e62b5ffcb6 Fix exception when a global references another without constfold
Fixes #19. Thanks to SaladDais for the report and test case.

With constant folding inactive, the dead code removal optimization was removing globals and their symbols when they were e.g. integer constants, without substituting them in other globals. This produced a crash when the output module tried to access said symbols.

For example, in this code:

```
integer A = 1;
integer B = A;
default{timer(){llBreakLink(B);}}
```

the line `integer A = 1` was being removed, as well as the `A` global symbol, but the line `integer B = A` was retained with the missing symbol, and the output module crashed when trying to look up the `A` symbol.

Apparently, it wasn't an issue when constant folding was active (which is why it went unnoticed for so long) because the constant folding code sets 'orig' in the symbol table to the original value the variable was being set to, which let the output module know what to output.

The fix is to replace the references to deleted symbols with their values in global definitions. In normal code that was already happening.
2022-10-31 18:42:19 +01:00
Sei Lisa
bc992e6182 LL change: the status of STATUS_DIE_AT_* is returned
As of Second Life Server 2022-09-09.574921, STATUS_DIE_AT_EDGE and STATUS_DIE_AT_NO_ENTRY return their corresponding settings rather than always FALSE.

Regression/coverage tests are clearly lacking in this area, as the change didn't trigger any test breakage, therefore add some unit tests.
2022-09-15 01:09:12 +02:00
Sei Lisa
281ff4d96a Strings representing denormals no longer give 0 when cast to float
This annoyance and discrepancy with LSO was finally fixed by Linden Lab. The change has prompted some modifications to the test suite to accommodate for the new results. A further improvement has been to make these tests more friendly to be run in SL, making it easier to verify the results.

Fixes #17.

Reported by SaladDais@users.noreply.github.com - thanks!
2022-05-17 13:48:05 +02:00
Sei Lisa
53e8bd659a The Base64 functions that used to produce garbage no longer do 2021-03-21 19:05:37 +01:00
Sei Lisa
e1bcccb979 All tests pass now 2020-11-10 02:14:15 +01:00
Pedro Gimeno
4c49e87f4c Add -y to test entries without an .err file; improve consistency 2020-11-08 19:07:07 +01:00
Sei Lisa
f3037df055 Forgot to add the test case for the previous commit 2020-06-01 20:56:31 +02:00
Sei Lisa
d6bf0c390e Fix two issues in the dead code removal module
1. When the last statement of a function is a RETURN statement which is syntactically required, it could still be deleted.
2. The child of a RETURN statement could be removed if the statement was not executed.

This commit fixes both issues.

Bug report and test case provided by @Tonaie. Fixes #14.
2020-06-01 20:49:48 +02:00
Sei Lisa
0affbf13dd Fix "" + list_expr producing list_expr
The type checks were not strong enough. While on it, strengthen other similar checks as well.

Reported by @Tonaie. Fixes #13.
2020-04-23 13:47:57 +02:00
Sei Lisa
4d75f0f792 Future-proof of list-plus-elem.lsl and list-plus-elem.out 2020-04-23 13:47:51 +02:00
Sei Lisa
1ab9dd69b4 Fix optimization of fn > -1 and fn < 0 when fn's minimum is -1 in conditions
E.g. llSubStringIndex(...) > -1 was converted into !~llSubStringIndex(...) which is incorrect. We even had a test case for it... with a wrong expected response file.

Bug report and test case by Sinha Hynes (thanks!)
2019-07-16 01:58:19 +02:00
Sei Lisa
1bdaff32ab When optimizing nonconst * const, cast the result to the type of the operator.
Per bug report by @Welcius.

Fixes #8.
2019-07-02 15:40:20 +02:00
Sei Lisa
ec509b3840 Fix parenthesization of unary minus
The algorithm for adding parentheses around unary operators was not working properly. It converted a * (-b) * c into a * -b * c, which LSL handles as a * -(b * c).

Fix and add test cases for that. One of the test cases shows an example where the difference matters: 0 * (-1e20) * 1e20 should result in 0.0, but if wrongly parenthesized, it gives NaN, because 1e20*1e20 gives infinity due to float overflow, and minus infinity times 0 is indeterminate.

The addition of parentheses has been improved, but it still does not eliminate every redundant parenthesis.

Also fix the horrendous typo of using "operands" where it should be "operators".
2019-05-04 23:20:20 +02:00
Sei Lisa
9d540798b4 Allow returning void expressions where state changes are allowed
In the same places as state changes are allowed, i.e. in places where a parent of the AST node is a WHILE/DO/FOR or an IF without ELSE, it's allowed to use return statements with expressions that return void, e.g. llDie(), provided the function itself is declared as returning void.

The construction, when found, is rewritten to '{<void expression>; return;}' because the optimizer is not designed to deal with these monsters.

We've renamed the variable SuspiciousStSw to PruneBug, because it's used for both purposes now, though a better name might have been PruneBugPendingChecks, because these are only errors if the IF has an ELSE. We've also added the exception to raise as part of the data stored in the list.

Per report by Tonaie Resident.
2019-05-01 04:28:58 +02:00
Sei Lisa
2c94905f1e Add regression test for the keyerror bug 2019-02-26 02:28:21 +01:00
Sei Lisa
128005e889 Fix bug in inlining of empty for() initializer
It was causing an exception. Fixed now.

Thanks to Cindy Reynaud for reporting the problem and sending a backtrace.
2019-02-02 00:50:05 +01:00
Sei Lisa
352f410d12 Add forgotten unit tests for the identifier substitution fiasco 2019-01-11 21:20:21 +01:00
Sei Lisa
42f47d38f0 Fix swaps and other misoptimizations
This undoes 454d44e85f
2019-01-11 02:09:15 +01:00
Sei Lisa
1b3c8a4d89 Check min and max to determine truth value of condition
Also added some min/max values for a few functions.

This allows optimizing things like:

  ! llGetNumberOfPrims()  ->  0
2019-01-07 00:15:38 +01:00
Sei Lisa
1867dc78e7 Add the new test suite.
This test suite has been in use for a long time now, in place of the obsolete and unmanageable testparser.py and testfuncs.py. It verifies the complete optimizer output to stdout and stderr, to ensure that the output matches the expectations.

See unit_tests/README.txt for more info.
2019-01-04 20:27:36 +01:00