Commit graph

426 commits

Author SHA1 Message Date
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
Sei Lisa
2327613423 Follow-up to ba9511e: Fix rounding of result. 2016-12-21 20:26:40 +01:00
Sei Lisa
6879037735 Fix type conversion on calling LSL functions.
We had a big chaos with type conversion. That caused a bug where passing a key to a function that required a string, or vice versa, crashed the script.

Diminish the chaos by modifying the parameters just prior to invocation (in lslfoldconst). We also remove the, now unnecessary, calls to force floats, either alone or within vectors or quaternions.
2016-12-21 06:01:03 +01:00
Sei Lisa
27eeec06cf Fix type of parameter not being adjusted after optimizing parameter. 2016-12-21 05:44:32 +01:00
Sei Lisa
5105cee2e4 We already had imported hashlib. 2016-12-21 02:45:17 +01:00
Sei Lisa
7ebd68c7b2 llGenerateKey() returns key, not string 2016-12-21 01:32:54 +01:00
Sei Lisa
ba9511e2ff Implement llFrand and llGenerateKey when in Calc mode. 2016-12-21 01:18:25 +01:00
Sei Lisa
1b7dbd9453 Fix llGetColor in lslextrafuncs.py
Too much copy-paste. The name of the parameter should have been 'face', not 'id'.
2016-12-21 00:41:08 +01:00
Sei Lisa
991e811f2d Fix Python gotcha with module globals, and missing 'cond' in lslextrafuncs.
The previous commit didn't work as expected. "from module import var" freezes the value at load time; changing it later has no effect. A reference to the module needs to be used.

Fix that and the similar problem with LSO. Also revert some "from lslcommon import *" introduced earlier.

That also revealed another bug about missing 'cond' in the import list of lslextrafuncs. This should fix all functions that return values on null key input.
2016-12-21 00:22:49 +01:00
Sei Lisa
7c2c09188d Change how LSLCalc is handled.
Instead of using an option in the command line, use a global in lslcommon, settable by the main program (only the main LSLCalc program, which differs from LSL-PyOptimizer's main, changes it).
2016-12-20 21:25:33 +01:00
Sei Lisa
1b6777e47b Comment the LSO and ELSONotSupported globals in lslcommon.py. 2016-12-20 21:19:48 +01:00
Sei Lisa
39261cbfc8 Make Unicode some strings that should be, and improve error reporting in builtins.txt
Also work towards the convention that strings that represent text (possibly translatable) are in double quotes, not single.
2016-12-20 20:13:53 +01:00
Sei Lisa
a124deb6b3 URL changed.
lsl.project.li is no longer available. Change it to lsl.project.zone.
2016-12-15 04:37:45 +01:00
Sei Lisa
0b0f10007b Update copyright year. 2016-12-15 04:37:33 +01:00
Sei Lisa
7a171a7391 Add notes on the meaning of the bug numbers in a comment. 2016-12-15 04:35:09 +01:00
Sei Lisa
52b97f168f Yet another follow-up to 2f4f403 (lslcalc support)
Add calcmain.py to .gitignore.
2016-12-15 04:15:26 +01:00