Commit graph

643 commits

Author SHA1 Message Date
Sei Lisa
e27ece3536 Deduplicate the float regex by adding a template 2024-10-27 12:22:35 +01:00
Sei Lisa
1d6bb809bf Fix bug in llListSortStrided producing incorrect results sometimes
It used `a = lst[i]` instead of taking the stride index into account (that is, it should have been `a = lst[i+idx]`). Anyway, the exact same value is in b, so use that instead.

Test case by Tapple Gao.
2024-10-09 01:40:19 +02:00
Sei Lisa
d03de9a6be Add --blacklist, to blacklist constants; defauls to NAK,JSON_*
Closes #30, but not the general problem of control characters in the source.
2024-05-28 20:19:10 +02:00
Sei Lisa
5841c2c17a Introduce 'c' (constant) as symbol kind
This is preparatory work for addressing issue #30. It also fixes a bug where --prettify made the constants writable.
2024-05-28 17:31:22 +02:00
Sei Lisa
28de23a03b Parser fix: Give error in state switch when ident is not a state 2024-05-25 20:04:33 +02:00
Sei Lisa
d70c914738 Fix wrong output leading to incorrect tokenization of minus signs
When the tree has a unary minus node (NEG) whose child is a product node (*), and the left operand of the product node starts with a minus sign but is not a NEG node, this produced at least two minus signs in sequence without any spaces.

Normally, OptSigns hides this problem, but when it is disabled, or when the left factor is a pre-decrement (--V) node, the problem is visible.

Fix by creating a function that detects all kinds of leading minus signs, and use it in place of the comparison with NEG.

Fixes #31. Reported by @KrsityKu, who also provided a repro.
2024-05-24 23:55:23 +02:00
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
c1c1b8c58d Further generalize the < operator
Use the node's min and max for both sides. Constants are just a special case where min = max = value.
2024-05-11 18:32:27 +02:00
Sei Lisa
d2e3b9a3bd Add getMin() and getMax(), which can detect constants 2024-05-07 00:35:47 +02:00
Sei Lisa
bf505220ac Calculate llFrand's min and max when possible 2024-05-07 00:07:17 +02:00
Sei Lisa
65326115d8 Fix/extend the < operator; promote min/max from symbol to node
- Fix case where CONST < FNCALL or FNCALL < CONST, when the function was marked as SEF but the args were not SEF, could result in the FNCALL being optimized out, thus failing to apply the side effects of the arguments.
- Copy the function's `min` and `max` present in the symbol table, to the node; use the node's `min` and `max` properties in the `<` operator instead of looking up the symbol and using that.
- Extend it to cover all cases where CONST < SEFexpr and SEFexpr < CONST where SEFexpr.min and SEFexpr.max are defined.
2024-05-06 23:55:55 +02:00
Sei Lisa
f5035ed62d Join InternalListFindList loops into one 2024-04-28 11:06:59 +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
ff85a1e837 Implement llListSortStrided
The only difference between this function and llListSort is the index, so llListSort is adapted to accept it.
2024-04-19 15:22:35 +02:00
Sei Lisa
5ee290deff Implement llListFindListNext and llListFindStrided 2024-04-19 13:47:26 +02:00
Sei Lisa
914b57f603 Fix llComputeHash on Python 3 2024-04-18 19:36:53 +02:00
Sei Lisa
14a97090bf LSO no longer returns -1 for llListFindList([], []) 2024-04-18 19:24:32 +02:00
Sei Lisa
002ef96a9d Implement llList2ListSlice 2024-04-18 18:08:57 +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
f854e94349 New copyright year 2024-04-14 11:40:21 +02:00
Sei Lisa
b8f9d8b632 Fix typo in llListFindStrided; downgrade llListSortStrided to TODO 2024-04-14 11:38:43 +02:00
Sei Lisa
8d4750b6d0 Add new functions and constants 2023-12-12 16:52:45 +01:00
Sei Lisa
28b42e7c6b LL fixed the overflow in llAbs() in Mono 2023-11-18 13:08:50 +01:00
Sei Lisa
152ede8cd0 Add new functions (no implementation yet) and constants 2023-07-15 11:05:53 +02:00
Sei Lisa
5f1062d378 Add llReplaceSubString calculation + tests 2023-04-09 12:28:59 +02:00
Sei Lisa
e4c9627772 llHMAC: Make more elaborate tests and allow running them 2023-04-09 11:08:20 +02:00
Sei Lisa
500a8bb751 llHMAC implementation (without importing hmac) 2023-04-09 11:08:20 +02: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
f2ab8d9d15 Don't try to track llGetEnv settings - it's too eror-prone 2023-02-03 14:33:29 +01:00
Sei Lisa
231c16b90e New copyright year 2023-02-03 13:06:18 +01:00
Sei Lisa
b13bb6d810 Add LinkSound functions and constants; disallow unstable in void
The unstable flag does not make sense in void functions; add warning.

Also, new upstream version of builtins.txt with new functions that have been added to fndata.txt.
2023-02-03 12:57:58 +01:00
Sei Lisa
91b3186245 Microoptimizations; minor fix
The microoptimizations do nothing at all, but it was poor style before them.

The fix is a missing u for a Unicode string.
2023-01-31 20:41:37 +01:00
Sei Lisa
8e20a06912 Other minor fixes to lslloadlib
Fix many comparisons of unicode to str.
2023-01-09 11:12:20 +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
dc655e3501 Monkey-patch some string functions in narrow string builds
The official distribution of Python 2.7 on Windows is built with "narrow strings" (UTF-16 strings with no proper indexing or length). This makes some tests fail. "Fix" this by monkey-patching a few functions and using a wrapping unicode class, as we can't monkey-patch the actual unicode type.

This is very fragile code, but it's the best we could do given the limitations.
2022-12-11 23:22:42 +01:00
Sei Lisa
cc55c4c23e Revamp encoding handling in lslloadlib
There were multiple encoding issues, especially on Windows. Address them by loading the file in binary and converting to Unicode for internal use. This means that the function/event tables are now Unicode.

Originally reported by @Tonaie (see #20).
2022-12-08 17:19:19 +01:00
Sei Lisa
0b7d04e5ff Deal with changes in llChar, strengthen some tests
Previously, llChar formed an UTF-8-1993 string with the given code and converted that, resulting in multiple question marks when the conversion to Unicode forced by Mono caused errors in multiple characters. They have changed the implementation and now it also considers U+FFFF invalid, and only returns one U+FFFD character if the input is invalid, and LSO behaves the same as Mono (no UTF-8-1993 anymore).

We've also detected problems with Windows (who else would it be) for the Unicode "astral" planes (planes beyond the Basic Multilingual Plane), so now there are new tests that include characters > U+FFFF. And since some builds of Python 2 use UTF-16 internally, we also check llSubString and friends with positions after an astral plane character. This is currently failing under Windows, as there are numerous encoding and line ending problems happening on that OS, especially with Python 3.
2022-12-08 13:22:54 +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
1df05ed0d7 The grammar comment for simple_expr_except_list was missing IDENT 2022-10-31 17:20:25 +01:00
Sei Lisa
9c281dec64 New function, llSHA256String
Implement it in lslbasefuncs.py, and add tests. Also add more test vectors for llMD5String and llSHA1String.
2022-10-14 18:39:04 +02:00
Sei Lisa
8966b9de97 New upstream function: llGetObjectLinkKey 2022-10-01 01:18:12 +02: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
95d0fb4b13 New upstream version of builtins.txt; minor fix
Add comment to llGetStatus and make it more future-proof by adding unused flags.
2022-08-26 12:51:02 +02:00
Sei Lisa
8d413f910e Forgot to update copyright year 2022-06-07 19:46:31 +02:00
Sei Lisa
fb61e00780 Minor cleanup 2022-06-07 19:39:26 +02:00
Sei Lisa
9dedabfa71 Don't rely on Python generating Indet on (float)"-nan"
We did the same for vectors. We don't have enough guarantee that Python will return Indet when evaluating float(u"-nan").
2022-05-19 14:42:01 +02:00
Sei Lisa
07cf4fe30f LSO does not force positive zero in llDumpList2String
And minor aesthetic change.
2022-05-19 14:29:14 +02:00
Sei Lisa
828b020b8c Remove disabled code 2022-05-17 22:30:07 +02:00
Sei Lisa
d2e64e25a6 Rewrite Mono float to string conversion; fix llDumpList2String
llDumpList2String has changed its behaviour with respect to minus zero. Now it converts -0.0 to a string without the minus sign.

While testing this, we noticed several mismatches in the float to string conversions; the existing routine did not properly convert some values because as we discovered later, it is subject to double rounding; one of them is the built-in round-to-nearest-or-even while getting the first 7 significant digits, and the other is just an increment when the digit is a 5 or more, so round to nearest, ties away from zero, and is performed on the digit past the five or six visible digits that LSL shows.

The new code is a tad easier to understand and more robust.

A first variant of the new code is left commented out for history's sake, and will be removed in the next commit.
2022-05-17 22:28:49 +02:00