Commit graph

404 commits

Author SHA1 Message Date
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
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
dff7b0e9ac Another follow-up to 2f4f403 (lslcalc support)
Forgot to check for EOF.
2016-12-15 04:12:02 +01:00
Sei Lisa
9879d5f68b Follow-up to 2f4f403 (lslcalc support) 2016-12-15 03:38:51 +01:00
Sei Lisa
7fa691ead7 Activate 'optimize' option by default in lsloutput.
Failure to do so caused a regression test to fail. Harmless, because that option is overriden by main, but fixed.

Bug was introduced in commit 397dc89, with the requirement that the 'optimize' option be active for output optimizations to be applied, by forgetting to update the function header to add that default option.
2016-12-15 03:00:22 +01:00
Sei Lisa
2f4f403535 Add lslcalc support.
lslcalc is currently derived from a snapshot of PyOptimizer at some point in past, making it difficult to maintain when bug fixes are applied to the optimizer. Solve this by incorporating expression evaluation capabilities.
2016-12-15 02:48:39 +01:00
Sei Lisa
43beb767f2 Fix llBase64ToString's behaviour with invalid UTF-8.
llBase64ToString doesn't behave like llUnescapeURL wrt invalid UTF-8. First, the last NUL if any is removed, and the remaining NULs are converted to "?". Second, all overlong sequences are converted to a single "?", *including the 5- and 6-byte UTF-8*.

Implement this behavour and the corresponding unit tests.
2016-12-13 15:04:02 +01:00
Sei Lisa
e8201d6956 Err when invalid UTF-8 should have been generated in LSO mode.
LSO strings are byte arrays, but our strings are made for Mono which uses Unicode, and invalid UTF-8 sequences can't be stored in Unicode without using a custom representation.

One possible representation is to only use the codepoints 0-255 in the Unicode string, to avoid supporting multiple types for strings. Something to study in future.
2016-12-13 14:26:48 +01:00
Sei Lisa
b593141f9f Fix UTF-8 in the surrogate range passing as good.
Our UTF-8 validity checker failed to recognize that characters in the surrogate range (D800-DFFF) were invalid. Fortunately, Python 2 is happy about that, therefore it doesn't crash (Python 3 fixed that range too). Unfortunately, SL isn't, therefore we fix it.

Added corresponding unit tests.
2016-12-13 03:30:32 +01:00
Sei Lisa
ae984169ad Add llGetEnv to the partially computable functions.
Includes all known settings up to 16.12.03.322072 so far. It will be updated as new settings are added.
2016-12-12 22:58:12 +01:00
Sei Lisa
397dc896fb Fix --optimizer-options=-optimize still applying some optimizations.
This option normally takes effect through the base class in lsloptimize.py, which doesn't call the optimization techniques if deactivated. However, lsloutput.py is not called by it, and it applied some optimizations on its own.

Fixed on the reading of the optimization options, by filtering them by whether the optimize option is active.
2016-11-29 23:03:14 +01:00
Sei Lisa
52c38b0980 Fix embedded NUL in literal strings.
Literal strings were not conforming to Mono's strict "NUL is end-of-string" rules, so a file with an embedded NUL within a string literal would let the NUL be part of the string. Mostly academic, because it's probably not possible to upload a file with an embedded NUL to SL, but fixed it regardless.
2016-11-18 16:58:48 +01:00
Sei Lisa
da7b98b4ba Comment fix. 2016-11-15 01:25:35 +01:00
Sei Lisa
47013f87e2 Fix minor typo in a comment. 2016-11-14 03:10:29 +01:00
Sei Lisa
74115345f0 Fix blunder in operator priority
-a//-b did the wrong thing. Use -(a//-b) and add corresponding regression tests.
2016-11-06 04:09:43 +01:00
Sei Lisa
37483a72cb Fix void expressions in FOR loops.
As an enhancement over LSL, we trigger a Type Mismatch when there are void expressions in list constructors, because in LSL, while accepted, they trigger an ugly runtime exception.

This works fine, but then expression lists, where this are checked, are not exclusive of list constructor; they are used in other places. One of these places is the initializer and the iterator of FOR loops. As a consequence, we didn't allow void functions in the FOR initializer or iterator.

Fix by adding another possible value to the parameter 'expected_types' in Parse_expression_list. False means don't allow void either (what Null did before); Null now means allow anything. All callers to Parse_expression_list are changed accordingly. Added corresponding regression test.
2016-07-10 01:29:11 +02:00
Sei Lisa
e60457f00e Fix rare bug with breakcont and label scope.
This caused "Label not defined within scope" when breakcont was active:
  default{timer(){jump x;while(0)@x;}}
The problem was that breakcont opens a new scope for the case where it has to deal with a loop which is the single statement of an outer statement, e.g.
  default{timer(){if(1)while(1)break;}}
would add braces to jump to the correct break point:
  default{timer(){if(1){while(1)jump brk;@brk;}}
To avoid excessive complication, a new scope was always opened for the whole statement in each of the loops, regardless of whether we needed braces later on or not. That should be transparent most of the time, but then if the statement was a label declaration, the label would be in a new scope that would be invisible outside the loop.

Fix that by checking explicitly for a label to temporarily get rid of the new scope in that case, and add a test case for it.
2016-07-09 23:41:27 +02:00
Sei Lisa
9d0eb307e1 Explain the purpose of PushScope() in loops when breakcont is active. 2016-07-09 22:50:18 +02:00
Sei Lisa
30a07db4fb Mark a couple bugs found to not lose track, and add a regression test. 2016-06-28 03:47:48 +02:00
Sei Lisa
0c3ad9b938 Change skippreproc -> processpre, add #pragma option processing.
Usage:

Options are case insensitive.
2016-06-28 03:20:21 +02:00
Sei Lisa
a13b1cb77e Expand warning text 2016-06-27 22:38:19 +02:00
Sei Lisa
5ad68906e9 Name the groups of keywords.
This is in preparation for having pragmas/defines to select compliation options on the fly within the code.
2016-06-27 20:33:47 +02:00
Sei Lisa
8488254d53 Generate labels sequentially rather than randomly. 2016-06-27 20:32:59 +02:00
Sei Lisa
79dff25769 Update copyright years of some files; add legalese to seftable.txt 2016-06-27 20:06:41 +02:00
Sei Lisa
8fc4240142 Ignore preprocessor commands while scanning for globals.
The pragma warnings were duplicated, one during globals scan, another during actual parsing. This should fix it.

This is somewhat potentially dangerous, as some directives (pragmas, notably) could in future affect the global scan phase by changing the language.
2016-06-27 19:07:20 +02:00
Sei Lisa
633c31df6c The RE wasn't correct, since we want to isolate the directive.
Also check for pragma and emit a warning.
2016-06-27 18:38:40 +02:00
Sei Lisa
fb83279706 Add infrastructure to process preprocessor directives.
Also check that they appear at the beginning of the line.
2016-06-27 16:50:09 +02:00
Sei Lisa
ee091c63a6 Someone's been misusing Python's re.match... O:) 2016-06-26 22:33:10 +02:00
Sei Lisa
893bcf177b Remove dead code.
Commit b73805e introduced lazy lists in assignments only. Commit 890e960 generalized it, allowing any identifier to be followed by brackets, removing the need for assignment-specific treatment. However, we forgot to remove the assignment-specific code parsing, so do it now.
2016-06-26 17:21:52 +02:00
Sei Lisa
f32489a5a8 Distinguish indeterminates and improve infinities in output.
'(float)"-nan"' doesn't return Indet in LSL:
  llOwnerSay(llList2CSV([(float)"-nan"])); // outputs "nan", not "-nan"
Therefore, for the output to yield the correct result we have to use a different strategy to generate an indeterminate. We choose '(1e40*0)' which is shorter than the rest.

Also, we don't output infinites as '(float)"[-]inf"' but alwas as '1e40' or '(float)-1e40' (or just '-1e40' if we're in globals).
2016-05-26 20:00:11 +02:00
Sei Lisa
51a7e6d199 Fix bug with reduction, and remove useless code.
Oops, we have to reduce *after* testing for range!

Also, the special cases for the tangent are unnecessary, because the results are already correct.
2016-05-21 04:16:34 +02:00
Sei Lisa
9cf9478270 Improve the (in)accuracy of llSin, llCos, llTan
All three functions have in SL the Intel problem of inaccuracy with high values. Since we work in single precision, it's barely detectable usually, but for large input numbers the difference between the imprecise results of SL and the more accurate results of recent glibc become more obvious.

This change brings back the Intel inaccuracy, even across systems (different versions of Python/C might behave differently otherwise).

Reference:
https://randomascii.wordpress.com/2014/10/09/intel-underestimates-error-bounds-by-1-3-quintillion/
2016-05-21 03:56:27 +02:00
Sei Lisa
e40c52075b Make ForceFloat more robust on non-float input.
It was designed so that only ints and floats should be accepted. But for safety, and for reuse, make that "any non-float" so that long integers are also truncated to F32.
2016-05-21 03:10:31 +02:00
Sei Lisa
13663ff077 -0x1p63 is not included in the valid range of trig functions. 2016-05-21 02:50:55 +02:00
Sei Lisa
7b70bfe55f Fix precision error in llTan special values. 2016-05-21 02:27:15 +02:00
Sei Lisa
4172f02439 One more way to transform a float to single (commented out) 2016-05-21 01:59:05 +02:00
Sei Lisa
60f257279b Use math.copysign to distinguish indeterminates
We were using a very dubious method to distinguish an indeterminate from a NaN, via struct.unpack. Turns out that math.copysign gets the job done and seems more robust.
2016-05-15 19:55:45 +02:00
Sei Lisa
b06ac33b5f Fix misspelling in the latest commit. 2016-05-15 18:44:45 +02:00
Sei Lisa
23b27bd3af Produce more math errors in division
Besides dividing by zero, any result producing NaN including inf/inf, NaN/anything, anything/NaN causes a math error as well. We only contemplated NaN/anything and neglected the rest, so we generalize it.
2016-05-15 18:21:24 +02:00
Sei Lisa
28a8f0757c Check the scope as well as the label name, for academic correctness' sake. 2016-05-08 04:14:32 +02:00