Commit graph

441 commits

Author SHA1 Message Date
Sei Lisa
68902c20f4 Make llGetAgentList more specific.
Testing shows that AGENT_LIST_xxx values are not used as a bitfield, but as an enum. There are only three possible valid values. Check only those three.
2017-01-16 23:23:34 +01:00
Sei Lisa
1a06bf4eb9 Fix minus zero in llFrand().
llFrand returns minus zero when given a negative denormal.
2017-01-16 20:37:11 +01:00
Sei Lisa
9d63e7268d Fix reference to vector components in llEdgeOfWorld. 2017-01-16 19:34:04 +01:00
Sei Lisa
2a76b26e13 Remove more duplicate tests. 2017-01-15 03:18:50 +01:00
Sei Lisa
c8aa679da0 Emphasize that byte strings are byte strings. 2017-01-15 02:35:06 +01:00
Sei Lisa
1e017b5c56 Remove duplicate test. 2017-01-15 01:49:26 +01:00
Sei Lisa
742532d48e Run llFrand test just once.
It doesn't make sense to check the output multiple times. It would if lslcommon.IsCalc were set to True, because then it wouldn't be distinguishable from a randomly obtained value. But in non-calc mode, it would raise ELSLCantCompute if it were unpredictable, so it's OK to check just once because if it doesn't raise, it's predictable and can be checked.
2017-01-14 03:56:33 +01:00
Sei Lisa
2b0633e2f9 Expand llPow results table to test indeterminates too. 2017-01-13 01:45:09 +01:00
Sei Lisa
c08d1edb5d Fix nested lists disabling list mode.
Lists can't contain lists at runtime, but they can at parse time, so the optimizer must behave properly when handling nested lists. And it didn't, because it neglected to preserve the previous state of self.listmode. So we fix that.
2017-01-13 00:36:09 +01:00
Sei Lisa
133c1572f6 Remove unnecessary activation of LSO mode in a test. 2017-01-12 19:02:58 +01:00
Sei Lisa
983808f022 Remove dot from floats when there are no decimals and there's an exponent. 2017-01-12 17:41:34 +01:00
Sei Lisa
2cf5ede817 Fix optimization of -0.0.
It was optimized to ((float)0) because integers are cheaper. But that loses the sign, so that needed to be fixed.
2017-01-12 15:36:08 +01:00
Sei Lisa
4ec9396688 (float)"-NaN" should produce NaN, not Indet.
But (vector)"<-NaN, 0, 0>" produces Indet, not NaN.
2017-01-12 03:29:38 +01:00
Sei Lisa
5fff5f37d0 Expand help text on --prenodef. 2017-01-12 02:03:39 +01:00
Sei Lisa
a961fee1c3 Minor formatting fix for calculator.
Don't output a newline before a list constant if in calculator mode. While we're there, make a comparison more compact.
2017-01-12 01:57:40 +01:00
Sei Lisa
e5ffe56fec Add command line option -y/--python-exception, revert previous commit.
By default, catch exceptions and report them without a stack trace. When this option is specified, raise an actual Python exception (should show a strack trace).

Note: diff for this patch is best seen with -b (ignore-whitespace-change).
2017-01-12 01:55:52 +01:00
Sei Lisa
26b49b0807 Fix problem with parsing erroneous options that contain UTF-8. 2017-01-11 01:36:24 +01:00
Sei Lisa
3afd961cf7 Fix functions with side effects being erroneously optimized.
The function's SEF status was not taken into account when substituting functions with their values. This affected llModPow and llXorBase64Strings, both of which have a delay, and were erroneously substituted.

But allow them to be substituted when in calculator mode.
2017-01-08 05:53:10 +01:00
Sei Lisa
8b9fe7693e Change option --scriptname to --shortname and change help text.
Option --scriptname did nothing, because the program expected --shortname instead. --scriptname is far more confusing, given that it's intended as the value that lands in the __SHORTFILE__ macro, so it has been renamed.

Improve the help text regarding that option; also fix the wording for what -O help does and add an example of how to use -O.
2017-01-08 05:23:50 +01:00
Sei Lisa
b623d6ae5c Remove duplicate test, add test for LSO llListFindList
The test for two empty lists passed to llListFindList was duplicated. That case generates -1 under LSO, and that wasn't tested, so we add that as a test now. Check also that another corner case behaves properly under LSO.
2017-01-07 23:33:50 +01:00
Sei Lisa
19dec1d79e Allow llModPow and llXorBase64Strings to work in calculator mode.
e16fad0 was somewhat hurried. Revert it and use ELSLCantCompute, which is intended exactly for that purpose.
2017-01-07 20:46:14 +01:00
Sei Lisa
ab8f8a28a9 'default' is also a switch keyword.
This is academic, because 'default' is also an LSL keyword, which is why it wasn't included, but just for correctness' sake, we add it.
2017-01-07 20:24:28 +01:00
Sei Lisa
63e4425cd5 Fix corner case with labels.
When 'if', 'for', and 'while' statements have a label as the sub-statement, e.g. `while (FALSE) @label;`, the label was improperly removed in some cases, causing a potential compilation failure.

Why someone would want to do that, one never knows, but just to be sure, it has been fixed.
2017-01-05 02:55:06 +01:00
Sei Lisa
c7e8c04349 Tentatively add support for an LSO quirk with global lists.
When a global list includes a reference to a global variable of type key, the corresponding list entry type is string, not key (SCR-295, possibly caused by SVC-1710 or SVC-4485).

This implementation is fishy, because it hard-codes the type in the node regardless of the child types. But in some quick experimenting, it seemed to work. And since the main purpose is to document LSO's behaviour, rather than actually being usable, it's OK like that.
2017-01-04 05:10:12 +01:00
Sei Lisa
06edf8f152 Add undocumented -O options 'LSO' and 'Expr'.
For unit testing.
2017-01-04 05:08:09 +01:00
Sei Lisa
35687f1b0f Expand a comment. 2017-01-04 05:07:50 +01:00
Sei Lisa
8609c38451 In LSO, lists of 1 element also evaluate to false (SVC-689). 2017-01-04 05:06:56 +01:00
Sei Lisa
b04df456cb Output 1 instead of -1 on constant true conditions.
The rationale for using -1 was that it had all bits set, but that's a pretty weak argument, really. Lack of optimization of the sign could be worse, so we change it to 1, which is the value of the constant TRUE.

Also change the wording of a comment, for clarity.
2017-01-04 00:41:08 +01:00
Sei Lisa
b8a27bbcd2 Check that the file exists instead of raising an ugly Python exception. 2016-12-26 03:00:22 +01:00
Sei Lisa
e3632d8a64 Create a list of valid optimizer options and check against it.
Validating the input options was badly needed.
2016-12-25 21:34:42 +01:00
Sei Lisa
e2ad14ee1b Fix a few violations of our guidelines for Unicode handling.
Also use e.args[0] instead of e[0].
2016-12-25 20:49:56 +01:00
Sei Lisa
1162c202c4 Give informative error messages when exiting with an error. 2016-12-25 20:47:54 +01:00
Sei Lisa
0137d1ae52 Check -O help only when we're done processing options. 2016-12-25 20:43:24 +01:00
Sei Lisa
32840f4ad6 Add Clear to --optimizer-options, to unset all options. 2016-12-25 20:40:15 +01:00
Sei Lisa
b76063821b Check for valid UTF-8 unconditionally.
The input script must be encoded in UTF-8. We had a check that was only activated when the preprocessor was called. Activate it always, as not doing so triggers an unhandled exception later on.
2016-12-25 20:29:43 +01:00
Sei Lisa
6f474c09d2 Fix wording of WarnTabs option
When we changed 'nofoldtabs' to 'warntabs', we changed the meaning to the opposite. However, the wording was still the old one. Make it right.
2016-12-25 19:21:16 +01:00
Sei Lisa
e16fad0366 llXorBase64Strings and llModPow are not safe to precompute.
The reason is they have an embedded delay. A script might rely on it, therefore substituting the call with its value is not equivalent to leaving the call. They were both already excluded from the SEF table for the same reason.
2016-12-25 05:25:24 +01:00
Sei Lisa
505f7777d4 Pass command line arguments to main function.
As opposed to reading them from sys.argv. That will facilitate unit testing of main() later.
2016-12-25 01:12:17 +01:00
Sei Lisa
a68bbeac23 Check that the tests distinguish 0.0 and -0.0. 2016-12-25 01:11:12 +01:00
Sei Lisa
7ca81020a0 Fix llGetAgentList function name in lslextrafuncs.py.
For some reason, llGetListEntryType slipped in there. The prototype and behaviour were both correct, though.
2016-12-25 01:01:28 +01:00
Sei Lisa
f222289673 Fix crash on non-computable function.
When we reduced the scope of the try block in commit a823158, we introduced a bug because the tree modification was attempted even if no value was assigned (when the exception was triggered). Returning when the function is not computable ensures that this won't happen.

Scaringly, there was no check that caught this.
2016-12-25 00:56:50 +01:00
Sei Lisa
d54ba42330 Fix more test failures on Windows.
On Windows, float('nan') produces Indeterminate. To fix, set Indet first and then set NaN to the opposite.
2016-12-22 06:05:47 +01:00
Sei Lisa
efcf1cb1df Fix llListSort problem on Windows.
Apparently, under Windows, Python does a UTF-16 word-by-word comparison when comparing two strings:

>>> u'\ud700' < u'\U0001d41a'
True
>>> u'\ue000' < u'\U0001d41a'
False

Fix it by encoding as UTF-32 big endian before comparison, when that happens.
2016-12-22 05:50:18 +01:00
Sei Lisa
e8d7dd50f3 Test NaN behaviour in more detail. 2016-12-22 05:30:39 +01:00
Sei Lisa
91fd9734c8 Fix llRot2Fwd/llRot2Left/llRot2Up and add regression tests. 2016-12-22 03:06:56 +01:00
Sei Lisa
a8231586c1 Reduce the scope of the try...except block to only cover the call.
Major indentation changes, but minor actual changes.
2016-12-22 01:24:44 +01:00
Sei Lisa
44a9c9a40c Fix test case that caused an exception. 2016-12-22 01:22:11 +01:00
Sei Lisa
14488ddd92 Improve behaviour of llAtan2 to make it closer to SL's.
Especially regarding NaN inputs. Add regression tests.
2016-12-22 01:08:07 +01:00
Sei Lisa
159fae90bf Improve llFrand.
- Remove it from lslextrafuncs, and move all the code to lslbasefuncs.
- Make it behave like SL's more accurately. Denormals return 0 always in SL.
- Use int() for truncation rather then floor/ceil.
- Add test cases.
2016-12-22 01:05:21 +01:00
Sei Lisa
fc97ce42df Be explicit about corner cases for llFrand.
inf and nan already did the right thing in Python, but just in case that doesn't happen in all platforms, we handle them explicitly. Also, that will make it more immune to bugs in future.
2016-12-21 21:49:43 +01:00