Commit graph

643 commits

Author SHA1 Message Date
Sei Lisa
ea9711642c Add type casting comparison to CompareTrees.
It can now resolve e.g. (string)llGetPermissions() == (string)llGetPermissions() to TRUE.
2017-10-21 11:03:43 +02:00
Sei Lisa
dc117c2cbf Use CompareTrees to optimize the == operator.
Now we can.
2017-10-21 11:02:38 +02:00
Sei Lisa
e6b23a2d7a Fix CompareTrees to not compare unstable functions as equal. 2017-10-21 10:44:09 +02:00
Sei Lisa
4d92cc8838 Mark user functions as unstable.
Maybe in future we can perform further analysis to find some that are stable.
2017-10-21 10:42:46 +02:00
Sei Lisa
cdacc45bb0 Make functions unstable by default, for safety.
That ensures that if there's no data about a function, it is not optimizable.
2017-10-21 10:32:56 +02:00
Sei Lisa
ee8c2cde98 Cosmetic fixes. 2017-10-21 10:32:41 +02:00
Sei Lisa
b7700b7aab Remove debug code and seftable.txt 2017-10-21 10:29:12 +02:00
Sei Lisa
214d4a8a57 Add and read function properties table.
This solves a long-standing issue where we needed more data about LSL functions than just whether it's side-effect-free.

There's still some debug code, which is kept for history purposes.
2017-10-21 10:00:31 +02:00
Sei Lisa
3f6f8ed8ad Internal code reorganization.
- Separate library loading code into a new module. parser.__init__() no longer loads the library; it accepts (but does not depend on) a library as a parameter.
- Add an optional library argument to parse(). It's no longer mandatory to create a new parser for switching to a different builtins or seftable file.
- Move warning() and types from lslparse to lslcommon.
- Add .copy() to uses of base_keywords, to not rely on it being a frozen set.
- Adjust the test suite.
2017-10-20 18:19:48 +02:00
Sei Lisa
1a1531cb40 Use sys.getfilesystemencoding() to determine filename encoding. 2017-10-20 13:59:02 +02:00
Sei Lisa
cf3e4c21ec Comment fix.
Specify the name of the last llGetObjectDetails constant, to simplify manual checking.
2017-10-20 10:18:44 +02:00
Sei Lisa
36e336beee Add llGetStatus to lslextrafuncs. 2017-10-20 09:58:49 +02:00
Sei Lisa
3164a28c9b Add llGetAttachedList to lslextrafuncs.
Returns (list)"NOT FOUND" when passed a null key.
2017-10-18 21:57:33 +02:00
Sei Lisa
96a0aebe3a Fix the logic in llDetectedTouchST/UV.
They were returning TOUCH_INVALID_TEXCOORD for num <= idx <= 15 in detection events which were not touch events. That is incorrect.

Now it correctly returns:

- ZERO_VECTOR when idx < 0 or idx > 15 or the event is known not to be a detection event.
- TOUCH_INVALID_TEXCOORD when idx == 0 and the event is known to be a detection event that is not a touch event.
- Raises ELSLCantCompute otherwise.
2017-10-18 21:56:35 +02:00
Sei Lisa
028b244a9e lslbasefuncs: Rewrite some things in a different way.
Also some formatting changes. No functionality changes.
2017-10-18 15:20:19 +02:00
Sei Lisa
ea28e13e4a Implement llClearLinkMedia's known return values. 2017-10-18 13:43:53 +02:00
Sei Lisa
e051d49338 llAsin and llAcos return indet for indet input. 2017-10-18 02:42:58 +02:00
Sei Lisa
e8fb659592 Allow -2147483648 to count as a power of 2 in an optimization.
A case we oversought when implementing absorption of more than two flag tests into a single number.
2017-10-18 00:04:35 +02:00
Sei Lisa
2bee2db148 Remove duplicate check for '|'
Removed the 'if' and applied an indentation change; no further changes are done.
2017-10-17 23:59:41 +02:00
Sei Lisa
be767f24f0 Move things around to better places; undo 8d33746.
We oversought that the optimization that 8d33746 applied was already present, so no need to duplicate it.

A better place for handling '|' was under the code that already did so. No functionality change involved.
2017-10-17 23:53:24 +02:00
Sei Lisa
b4749d8fa4 Add debug code to display a subtree in a friendlier format than repr(). 2017-10-17 23:32:33 +02:00
Sei Lisa
4cbdbefe1b Fold again after applying distributibity or absortion.
Failure to do so was blocking some constant folding, like in:

if (a&1 || a&2 || a&4) -> if (a&(3|4))

Fixed. Now it correctly outputs if (a&7).
2017-10-17 23:28:14 +02:00
Sei Lisa
6c73ba95c2 Allow (x&r) && (x&s) && (x&t) to be collapsed into a single number.
This is an addendum to 3a849fe that allows more than two tests to be chained and optimized.
2017-10-17 23:26:13 +02:00
Sei Lisa
8d337467cb Fold the children of | as conditions when | is folded as condition. 2017-10-17 23:25:26 +02:00
Sei Lisa
a6a16c6e8f Fold ==0, ==1, ==-1 in general expressions, not just in conditions.
Also add a couple FIXMEs.
2017-10-17 02:38:08 +02:00
Sei Lisa
82081b2206 Fix crash when variables appear inside global lists.
Fixes #3.
2017-10-16 02:22:52 +02:00
Sei Lisa
cc96850f66 Fix bug where list elements of global declarations were removed.
CleanNode was too greedy, because children of global declarations (particularly lists) are not marked executable. Make a special case for them and don't recurse, since what matters is whether the declaration itself is executed. Its contents can't be cleaned up.
2017-10-16 02:22:40 +02:00
Sei Lisa
f77590df67 Fix sign of NaN*Indet and NaN/Indet.
In Python, NaN*Indet in any order returns the second operand, and NaN/Indet in any order returns the first operand. LSL consistently returns NaN in all cases.
2017-10-14 15:16:18 +02:00
Sei Lisa
0dc8629007 Raise ELSLInvalidType on invalid type passed to cond(). 2017-10-14 14:17:42 +02:00
Sei Lisa
a5ec12c9e9 Change (float)"NaN" to (-1e40*0) in output.
Solves both an inconsistency and the need to create a string.
2017-10-14 13:05:14 +02:00
Sei Lisa
6faa7816e6 Change ELSLInvalidType to ELSLTypeMismatch where appropriate.
The force type functions ff(), fi(), fs()... should normally trigger ELSLTypeMismatch when the input is not in the expected range of types, rather than ELSLInvalidType, which is reserved for the case where the type is not a valid LSL type.
2017-10-14 11:33:18 +02:00
Sei Lisa
3a849fe4b9 Optimize a common condition of (x & flag1) && (x & flag2)
It can't be done always: flag1 and flag2 must be nonzero powers of two. In that case, we can transform it to:

!~(x|~(flag1|flag2)) = !~(x|constant)

The -2147483648 case has trouble with the sign hack detector and I couldn't trigger it.
2017-10-13 02:59:32 +02:00
Sei Lisa
6ad2ef04d7 Add support for function calls in CompareTrees. 2017-10-13 00:30:47 +02:00
Sei Lisa
7ae7fa4396 Apply two optimizations to bitwise operations.
Based on basic Boolean algebra: distributive and absorption laws.
2017-10-12 22:48:43 +02:00
Sei Lisa
9e7a5d1cdf Change strategy for the checking of function input types.
Rather than assert that the types are correct, use the force type functions on the parameters:
ff, fk, fs, q2f, v2f, and the new fi, fl.

These functions have also been modified to ensure that the input type supports an implicit typecast to the target type and perform it, or emit ELSLInvalidType otherwise, rather than an assertion failure. fl in particular returns the original list if it isn't changed, or a copy if it is.

A couple bugs were found in testfuncs.py as a result, which have been fixed as well. A test has been added to ensure that the exception that caught these bugs remains in place.

The isxxxx functions are no longer necessary, so they are removed. Same goes for the painful cast handling process in foldconst, which was basically performing this task, and not necessarily well.

This approach is much more robust and should have been used since the beginning, but I didn't figure it out then.
2017-10-12 17:16:16 +02:00
Sei Lisa
41d2c68cf8 Add some more functions with predictable results.
Also minor reformatting forgotten in a previous commit.
2017-10-12 12:43:54 +02:00
Sei Lisa
1071941301 Implement accurate error reporting through #line directives.
Also simplify and fix the matching expression for #line (gcc inserts numeric flags at the end).

It still has many problems. It's O(n^2). It's calculated at every EParse, and EParse can be triggered and ignored while scanning vectors or globals. UniConvScript doesn't read #line at all, thus failing to report a meaningful input line. But at least it's a start.
2017-10-11 05:04:13 +02:00
Sei Lisa
4ba0518353 Report EParseReturnIsEmpty at return, EParseReturnShouldBeEmpty at expression.
Also change idpos to savepos, for consistency, and add note on why EParseReturnShouldBeEmpty is named like that.
2017-10-09 11:35:59 +02:00
Sei Lisa
4633c87a7c Report EParseUndefined at the identifier causing it.
It was being reported at the next token in some cases, due to needing to resolve the scope.
2017-10-05 18:51:53 +02:00
Sei Lisa
c544b51e37 Rewrite ReportError() and change EParse to report columns in chars.
ReportError() needed to account for terminal encodings that don't support the characters being printed. It was also reporting an inaccurate column number and its corresponding marker position, because the count was in bytes, not in characters, so that has been fixed.

Now EParse.__init__() calls a new function GetErrLineCol() that calculates the line and column corresponding to an error position.

The algorithm for finding the start of the line has also been changed in both ReportError() and EParse.__init__(); as a result, function fieldpos() has been removed.

The exception's lno and cno fields have been changed to be 1-based, rather than 0-based.

Thanks to @Jomik for the report. Fixes #5.
2017-10-05 18:50:45 +02:00
Sei Lisa
08c69eee0f Simplify a = a = b -> a = b 2017-09-22 16:14:50 +02:00
Sei Lisa
bdd42199eb Fix bug where assignments were treated as statements.
This caused e.g. b = a = a to raise an exception, when a = a was folded into a ';' which isn't an expression.
2017-09-22 16:04:44 +02:00
Sei Lisa
a0d4c77081 Minor cleanups; no functional changes.
lslcleanup: Variables renamed, order changed, comments added.

Other changes: remove semicolon at end of sentence, use self.Cast instead of creating a CAST node on the fly.
2017-09-22 15:42:42 +02:00
Sei Lisa
0a7e2a9e1d Optimize llDeleteSubList(expr, 0, -1) to [] if expr is SEF
It also applies to llListReplaceList with [] as replacement.
2017-09-15 23:13:59 +02:00
Sei Lisa
a6a08fe3f3 Implement transformation of lists into additions.
If the list in brackets is SEF:
  [a, b, ...]  ->  (list)a + b + ...
  ListExpr + [a, b, ...]  ->  ListExpr + a + b + ...
2017-09-15 22:30:22 +02:00
Sei Lisa
de29a9aa07 Fix for,while,if,do condition test during optimization.
That's exactly what 'cond' is for. Things like a loop with a constant zero vector condition should be recognized.

It was correct before just by chance, because FoldCond currently transforms a constant node into an integer node, but let's not rely on that.
2017-09-15 01:36:13 +02:00
Sei Lisa
b97b2a78e8 Fix return value for some detection functions.
When the index is good, on non-touch functions:
 - llDetectedTouchFace returns -1.
 - llDetectedTouchST and llDetectedTouchUV return TOUCH_INVALID_TEXCOORD.

We were returning 0 and ZERO_VECTOR respectively.
2017-08-30 19:23:38 +02:00
Sei Lisa
62eebb8bef Remove line no longer used from lsloptimizer.py. 2017-08-30 19:22:12 +02:00
Sei Lisa
2edd139a5c Fix copy/paste error in comment. 2017-08-25 20:45:24 +02:00
Sei Lisa
03c0e326c6 Remove "OK" from llDialog button list when it's the only element.
"OK" is the default; an empty list works just the same.
2017-08-25 20:35:24 +02:00
Sei Lisa
6738615360 Separate library function optimization into a different file.
No other functional changes. This required quite some reorganization affecting many files. As a side effect, PythonType2LSL and LSLType2Python aren't duplicate anymore.
2017-08-25 20:35:24 +02:00
Sei Lisa
36947b7b12 Rename lslfuncparams.py -> lslfuncopt.py
This is preparation work for splitting function optimization into a separate file, which will be the same that currently is lslfuncparams.py.
2017-08-25 20:35:24 +02:00
Sei Lisa
3ec460539e Implement the equivalent of GetObjectDetails for GPP/GLPP.
Removes the TODO item added in the last commit.
2017-08-25 20:35:24 +02:00
Sei Lisa
2a6e065c66 Optimize some llList2XXXX functions.
- Resolve for lists that aren't constants, but that are SEF, and reference a constant element, e.g. llList2String([llGetKey(), 5], 1) -> 5.
- Make it work with invalid conversions, if they are SEF.
- Simplify invalid conversions when the list argument is a llGetObjectDetails call and SEF.
- Simplify llList2String(llGetObjectDetails(id, [single_element]), 0) (or -1) to (string)llGetObjectDetails...; same with llList2Key and llList2Integer, converting it to (integer)((string)llGetObjectDetails...).
- Add TODO item to do it similarly for llGet[Link]PrimitiveParams.

Adds auxiliary functions to return a node or constant from a list in any of its forms, its length, and a constant for a node or constant.

Adds some utility members for LSL<->Python type conversion (one of them duplicated from lslparse.py).

Needs maintenance of the types returned by llGetObjectDetails.
2017-08-25 20:35:24 +02:00
Sei Lisa
906e76ea47 Format LIST nodes; don't add indent to CONST list in calc mode
LIST nodes will be pretty-printed with newlines between elements if they have 5 elements or more.

List constants won't be indented when in calc mode.
2017-08-25 20:35:24 +02:00
Sei Lisa
9a820a62d0 Simplify (type)sametype_expr -> sametype_expr. 2017-08-25 20:35:09 +02:00
Sei Lisa
2e09a3a986 Make some simplifications and keep PyFlakes happy. 2017-08-23 11:55:37 +02:00
Sei Lisa
ca3885c549 Expand conditions of types other than integer, string, key.
if(list!=[]) is always better than if(list), which compiles to if(!(list==[])).
if(float) can't be optimized, but it is equivalent to if(float!=0.0) which can. Same for vector, rotation.
2017-08-17 01:58:30 +02:00
Sei Lisa
a2e793df02 Parentheses around chained assignments are not necessary.
We follow the precedence and associativity rules, though.
2017-08-17 00:40:03 +02:00
Sei Lisa
2e29cc9131 Try to do better with the propagation of FoldCond.
Negation, specifically, didn't propagate to children. This might be redundant, though.
2017-08-16 22:02:11 +02:00
Sei Lisa
c5b5a8303c Add TODO item to lslrenamer. 2017-08-16 22:00:16 +02:00
Sei Lisa
6693022dfb Add !llStringLength(s) -> s == "" optimization. 2017-08-15 13:19:07 +02:00
Sei Lisa
0d76e09567 Propagate some SEF flags that we forgot 2017-08-15 13:19:07 +02:00
Sei Lisa
7c88acfe61 Fix type of != in llGetListLength substitution.
It was returning list instead of integer, causing inconsistencies in some comparisons depending on whether llGetListLength(L) or (L!=[]) was used.
2017-08-15 13:19:07 +02:00
Sei Lisa
fe574bb462 Bump copyright year.
'bout time.
2017-08-09 19:45:46 +02:00
Sei Lisa
e0fa1678a7 Optimize list addition when one list is known to have one element.
list + [element]  ->  list + element
list + (list)element  ->  list + element
[element] + list  ->  element + list
(list)element + list  ->  element + list
2017-08-09 16:41:36 +02:00
Sei Lisa
44e0db96d2 Optimize bool|1, bool&1 when possible.
a & 1 is always a, if a is boolean.

a | 1 is always 1, if a is boolean, but it can only be optimized out if a is side effect-free.
2017-08-02 01:40:48 +02:00
Sei Lisa
3f61e6f7bf Make IsBool smarter when finding whether an expression is boolean.
It was failing with a && b && c where a, b, c were known to be bools. It managed to simplify them to a & b & -c but that's not optimal.

Now it recurses on some operators that may return bool when used with bool operands: &, |, ^, * (in the case of &, it's bool if either operand is; for the rest, it's bool if both are). As a result, the above now simplifies to a & b & c, which is optimal.
2017-08-02 01:15:25 +02:00
Sei Lisa
61565470a2 New upstream version of builtins.txt, and minor code style changes. 2017-06-15 21:11:54 +02:00
Sei Lisa
b5994b79fe Optimize llDumpList2String(expr, "") to (string)expr.
It works on all VMs and it's always a gain, so it's not worth adding an option to deactivate it.
2017-05-31 14:39:42 +02:00
Sei Lisa
f1b05dd2ff Give more meaningful errors when break/continue parameter is wrong.
Adds a new EParseInvalidBrkContArg exception. Previously it raised EParseInvalidBreak or EParseInvalidCont, whose text was misleading for this type of error.
2017-04-29 13:47:45 +02:00
Sei Lisa
84e4543300 Allow empty list as constant in builtins.txt, for testing purposes. 2017-04-29 03:32:16 +02:00
Sei Lisa
0af2349ef9 Add command-line options to change default builtins and SEF table files. 2017-04-28 23:43:15 +02:00
Sei Lisa
2d78239d23 print returns the same type as the argument. 2017-04-28 23:04:42 +02:00
Sei Lisa
9a1421aeeb Fix (float)"nan" and (vector)"<nan,-nan..." on Windows.
We were letting Python typecast, and that causes the wrong result on Windows. Return the correct result explicitly when "nan" is found in the string.

Also, small reformatting of an else if -> elif.
2017-02-12 06:05:57 +01:00
Sei Lisa
9f8441bc65 Fix lslparse.DoesSomething.
It was non-funcional because of a copy/paste error.
2017-02-04 04:08:18 +01:00
Sei Lisa
c71b0eea2f Fix error type on non-var global identifier in expression.
The error message should be EParseUndefined, not EParseTypeMismatch.
2017-01-30 06:07:52 +01:00
Sei Lisa
7419ac4982 Don't run dead code removal when in calc mode. Add TODO item.
Running 'main.py -O expr' without disabling DCR led to an immediate crash, due to it trying to access the default state.
2017-01-28 06:36:49 +01:00
Sei Lisa
250090f418 Downgrade a FIXME item to TODO. 2017-01-28 05:04:26 +01:00
Sei Lisa
3686d490a2 Improve savings in ShrinkNames.
The reusable names table was being emptied as identifiers were used. This was sub-optimal for function parameters, because new identifiers would need to be created when exhausted.

Reset the reusable names list to a saved copy every time a new parameter list is started, in a similar fashion to what we did with the sequentially generated identifiers.
2017-01-28 03:36:25 +01:00
Sei Lisa
7659eb1654 Use frozenset for keywords; allow Pop.
Rather than using tuples for set belonging, use a frozen set. That eliminates the need to separate them by lengths.

Also, 'Pop' is not a reserved word. It's perfectly valid as a possible substitution identifier, so allow it. If used, it will go to the used words anyway and thus will be skipped by the sequential name generator.
2017-01-28 03:13:25 +01:00
Sei Lisa
37a4c86516 Change the llRotBetween algorithm.
The former ones don't match LSL's behaviour, in particular llRotBetween(<1,0,0>,<-1,0,0>) should return <0,0,1,0> but it didn't. Fix by using an algorithm that is closer to the one used by the sim.
2017-01-27 19:50:05 +01:00
Sei Lisa
48e1035ac3 Minor comment fix. 2017-01-26 03:01:34 +01:00
Sei Lisa
813bdf36e9 Comment out Moon Metty's llRotBetween algorithm. 2017-01-25 19:29:57 +01:00
Sei Lisa
f0c115f924 Add optimizer option 'listlength' to optimize llGetListLength.
llGetListLength(arg) was transformed to arg!=[] whenever constant folding was active. This option allows disabling that optimization.
2017-01-25 19:22:36 +01:00
Sei Lisa
e8852ad124 Fix llFabs with corner cases.
Minus zero is returned unchanged. Indet and NaN are returned unchanged too.
2017-01-24 06:02:45 +01:00
Sei Lisa
27adfdbfb9 Fix llRound behaviour in corner cases.
We had too much precision. In LSL, llRound(0.49999997) gives 1, not 0, because the loss of precision after adding 0.5 to that makes the result 1. Fixed by converting to F32 prior to flooring.
2017-01-24 05:50:07 +01:00
Sei Lisa
80cbaf8fd5 Fix llEuler2Rot's sign.
LL's algorithm for llEuler2Rot involves calculating a rotation matrix from the Eulers, then transforming the rotation matrix to quaternion. This generates sign discrepancies with our direct quaternion calculation algorithm.

Fixed by making only the necessary calculations to find the correct sign. Unfortunately, they are still heavy (notably, six more trig functions).
2017-01-24 05:45:42 +01:00
Sei Lisa
390de46bdb Fix more issues with llRot2Euler.
Mainly, the input quaternion wasn't being normalized prior to using it for calculations, and that broke compatibility. But even then, sometimes the arc sine of a value greater than 1 could be calculated, so we clamp it.
2017-01-23 18:55:30 +01:00
Sei Lisa
250438dfe9 Simplify the llRot2Euler equations.
We save a few multiplications by dividing both atan2 arguments by 2.
2017-01-23 16:41:56 +01:00
Sei Lisa
6ac02854aa Fix llRot2Euler's return types.
It didn't return Vector in the singularity case. Also, it neglected to truncate the result to single precision.
2017-01-23 16:39:58 +01:00
Sei Lisa
84648dadea Fix a couple mismatches of llAxes2Rot with actual behaviour.
For all zeros input, the result was <1,0,0,0> but we were producing <0,0,0,.5> because the first branch was taken. Fixed.

We forgot to take the square root when calculating the magnitude of the quaternion while normalizing. Fixed.

Use qnz instead of special casing.
2017-01-23 02:06:16 +01:00
Sei Lisa
2cca835ae9 Fix evaluation order for vectors, rotations and lists.
Vectors, rotations and lists are evaluated left-to-right.
2017-01-23 01:18:50 +01:00
Sei Lisa
13c7b0ef17 Convert output of llAxes2Rot to F32. 2017-01-23 01:18:19 +01:00
Sei Lisa
dd1b7ed594 Fix llAngleBetween when given a quaternion with all zeros.
LSL behaves as if it was ZERO_ROTATION instead, so we fix it by creating a function that returns ZERO_ROTATION when given <0,0,0,0>. Use it for llRot2{Fwd,Left,Up} as well.
2017-01-23 00:08:24 +01:00
Sei Lisa
1262934baf Fix llAbs raising a run-time exception in Mono.
llAbs(-2147483648) raises this:
 System.OverflowException: Value is too small.
  at System.Math.Abs (Int32 value) [0x00000] in <filename unknown>:0
  at LindenLab.SecondLife.Library.llAbs (Int32 i) [0x00000] in <filename unknown>:0

So it's actually not computable. In LSO it returns -2147483648, though.
2017-01-22 19:54:01 +01:00
Sei Lisa
ac775c9999 Join Internal{Get|Delete}SubSequence, fixing a bug in Get.
llGetSubString and llList2List could produce output longer than the input for some params. Fix that, and join the functions into one unique function for uniformity. Also, get rid of the special case of empty elements, because it can be treated properly by the general case, and it's not so common as to merit special attention.
2017-01-22 18:08:44 +01:00
Sei Lisa
9b812a2d2a Add no-coverage markers to Windows-specific code.
It won't be reached. Also, simplify the expected errors line to make it shorter.
2017-01-22 01:32:50 +01:00
Sei Lisa
007a726bee Fix llUnescapeURL with % in place of the second hex character.
When the input was of the form e.g. "%4%40", the second "%" was erroneously starting another quoted character. LSL doesn't behave that way: parsing resumes without starting another quoted character. Disturbingly, the expected result in the corresponding test was wrong. Fixed both the test case and the code to match actual LSL behaviour.
2017-01-20 01:59:59 +01:00
Sei Lisa
b0f8b7036b A bit of reordering, to put some similar tests together. 2017-01-20 01:40:19 +01:00
Sei Lisa
551a6ece12 Make llGetListEntryType of a list-type element return 0 (TYPE_INVALID).
It was triggering ELSLInvalidType, which is not a good approach.
2017-01-20 01:18:13 +01:00
Sei Lisa
d1ff8a86dd Additional fixes to llBase64ToString behaviour.
llBase64ToString hid another surprise: characters in range from U+0000 to U+001F are substituted by "?" except for tabs (\x09), form feeds (\x0A), shift ins (\x0F) and unit separators (\x1F), which were kept verbatim. So, mimic this behaviour.
2017-01-19 07:00:06 +01:00
Sei Lisa
a6955c4057 Fix llGetListEntryType. 2017-01-19 04:46:57 +01:00
Sei Lisa
94550af95a Minor style change. 2017-01-19 03:31:02 +01:00
Sei Lisa
7c2b76949e Make one more llXorBase64[StringsCorrect] case computable.
When the input string is at most 1 byte (2 base64 characters), the result is computable because the first byte is always zero.
2017-01-19 02:58:42 +01:00
Sei Lisa
7f8cb4ec58 Fix llAbs corner case.
As an exception, llAbs(-2147483648) equals -2147483648.
2017-01-18 00:50:59 +01:00
Sei Lisa
a65300ed49 Typo in a comment. 2017-01-17 02:53:26 +01:00
Sei Lisa
c8bfd40c66 Ensure that floats are compared with 32-bit precision.
The equality operator was comparing the raw floats when two were given. Also, type() was called when it was not needed.
2017-01-17 02:38:52 +01:00
Sei Lisa
6591b5dfd8 Fix return type of cross product.
mod(Vector, Vector) was returning tuple, not Vector.
2017-01-17 02:22:10 +01:00
Sei Lisa
13f3c951e1 Mark returned constant node as side effect-free.
When a function was successfully applied, the resulting constant node was not marked as side effect-free. This could potentially lead to poor optimization.
2017-01-17 01:00:04 +01:00
Sei Lisa
65d3f1130a Fix llDetectedName return value.
Astonishingly, llDetectedName returns NULL_KEY for invalid indices.
2017-01-17 00:20:38 +01:00
Sei Lisa
d8cf384ccc Fix llGetColor return value for invalid face.
It returns <1,1,1>, not ZERO_VECTOR.
2017-01-16 23:51:40 +01:00
Sei Lisa
f657d3e875 Use hex notation for a denormal float. 2017-01-16 23:33:49 +01:00
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
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
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
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
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
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
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
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
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
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
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
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
Sei Lisa
91ad438bb7 Be a bit smarter when optimizing out default labels.
(Was a TODO item). Also cosmetic changes.
2016-05-08 03:55:55 +02:00
Sei Lisa
3669bbb06e Only add a label and a jump for default and break when necessary.
Well, within reasonable limits.

For break, it's explained in the code. If the block is empty of actual code (code that generates output), then the break position is eliminated.

For default, if the default label is at the top of the block, the jump and the label are both eliminated. This check doesn't include verifying that there are other non-code-generating statements in between, so there's room for improvement (added corresponding TODO item).

This way, we're on par with FS, in case someone (ab)used the FS brokeness when the 'default' label was absent. All one has to do now is add the default label at the top, and the generated code will be the same as it was in FS when abusing that bug, with no extra burden.

Example: In FS, the code at the top acted as default and there was no jump for it:

  default { timer() {
    switch(1)
    {
      0;
     case 1:
      1;
    }
  }}

This generated roughly:
  default { timer() {
    {
      if (1 == 1) jump CASE_1;
      0;
      @CASE_1;
      1;
    }
  }}

In this system, it would trigger an error by default. To obtain the FS behaviour, the scripter can do instead:
  default { timer() {
    switch(1)
    {
     default:
      0;
     case 1:
      1;
    }
  }}

Thanks to this optimization, the code will be the same as in FS. Without it, an extra default label and corresponding jump would be present.
2016-05-07 04:40:37 +02:00
Sei Lisa
b7e6e6f7b1 Fix bug with tab handling.
Commit 5804a9a introduced a bug where having the foldtabs option disabled (normal) prevented optimizations of functions. Fix it for good (hopefully). While on it, rename the nofoldtabs option to warntabs, making it default, and use it to disable a warning when there are tabs in a string.
2016-05-07 03:18:50 +02:00
Sei Lisa
697e80cb16 Rather than reproduce the broken behaviour, throw an error on missing default.
Changed my mind. This looks saner. Now, if the 'default:' label is missing, an error will be thrown by default. It has to be explicitly disabled if normal C-like behaviour is desired (namely to jump to the 'break' label if no condition is met).
2016-05-07 02:38:54 +02:00
Sei Lisa
b1b84a123e Add broken FS switch behaviour for compatibility.
In the absence of a 'default' label within a switch, FS falls through to the first CASE label (or to the code before the first CASE if there's any).

This commit adds an option, active by default for FS compatibility, that mimics this broken behaviour, as well as a warning in case the 'default' label is absent, which also triggers another warning when the option is active.
2016-05-06 20:15:46 +02:00
Sei Lisa
bb198b3745 Add a (currently disabled) viable and tested alternative to c_float for F32. 2016-05-06 20:11:41 +02:00
Sei Lisa
41149a17aa Report a type mismatch in globals in a more meaningful position.
For example, this script reported the type mismatch in default:

key k=0;
default{timer(){}}

Now it's reported at the semicolon, which is as early as it can be identified and much more meaningful.
2016-04-04 13:58:25 +02:00
Sei Lisa
dc98e477d7 Add 'nofoldtabs' option to disable warning when a function generates tabs
When a function folds to a string that contains a tab, e.g. llUnescapeURL("%09"), or to a list that contains a string that contains a tab, a warning is emitted unless the foldtabs option (which forces the optimization) is used. This option allows to quiet the warning without forcing the optimization.
2016-04-01 20:48:33 +02:00
Sei Lisa
5804a9a610 Refine the test for tabs so that it checks strings in lists too. 2016-03-30 21:01:16 +02:00
Sei Lisa
7283842b3a Make an error message more explicit.
Resolving some constant function calls may generate tabs, e.g. llUnescapeURL("%09"). That can't be pasted into a script, and a warning is emitted. The warning text was misleading, making one think that something went wrong when all that happened is that an optimization couldn't be applied. Rewrite the text of the warning to be clearer about what the problem is.
2016-03-30 18:29:11 +02:00
Sei Lisa
b0e5a50a59 Fix discrepancy with LSL in llCSV2List.
In LSL, llCSV2List eats the very first space in the string if there's one. This patch implements that behaviour.
2016-03-25 20:52:48 +01:00
Sei Lisa
14f70c93b4 Fix bug in llCSV2List when there's no space after comma but there's a space in the value.
E.g. llCSV2List(",A B") produced ["", "B"].
2016-03-25 20:44:59 +01:00
Sei Lisa
661853be53 Fix llRot2Axis to negate the axis when s is negative. 2016-01-22 20:54:43 +01:00
Sei Lisa
c555a01a48 It's possible to enter Infinity as a float constant, so do that rather than the (float)"inf" kludge. It remains for NaN though. 2016-01-06 01:21:04 +01:00
Sei Lisa
881a33a427 Remove unnecessary line 2016-01-03 01:30:22 +01:00
Sei Lisa
cfb9dee941 Parse_unary_postfix_expression shouldn't accept the token (i.e. advance to the next) if it's not processed. This caused a mismatch between the reported syntax error and the position where it should have been detected. Fixed.
Added corresponding regression test.
2016-01-03 01:29:57 +01:00
Sei Lisa
ceb442e931 Improve error reporting, by printing the errored line and a caret (^), taking care to display the beginning of the token the error is at. 2016-01-02 03:39:47 +01:00
Sei Lisa
9469855769 Document the internal behaviour of run_time_permissions under LSO 2015-12-11 02:28:51 +01:00
Sei Lisa
91201f1e30 Remove old TODO and add new one.
Identifiers can be equal if they belong to different syntactic scopes. That will allow better reuse and less creation of new identifiers, most notably as function and event parameter names.

The implementation would require a stack of counters where the current value is pushed when entering a new scope, and popped when exiting, rather than using a single counter for the whole program.
2015-12-09 05:11:53 +01:00
Sei Lisa
025f0f8440 str() doesn't return a fully-expanded float. repr() does. 2015-12-09 03:37:01 +01:00
Sei Lisa
6ec2667bf3 Refine comments 2015-09-24 22:02:46 +02:00
Sei Lisa
57cacf29bb Return a float when typecasting returns zero (fixes inconsistent type) 2015-09-22 14:14:26 +02:00
Sei Lisa
aee638e900 Return denormals as 0 in (float)"number". Found by Pedro Oval. 2015-09-21 21:15:48 +02:00
Sei Lisa
2d72b8e198 Fix llList2CSV with -nan in vector and quaternion (with test case). 2015-09-09 18:14:27 +02:00
Sei Lisa
2044f888d4 Fix bug where (typecast)[single_expr] was output as (typecast)(list)single_expr, producing a syntax error in the output for lack of extra parentheses. 2015-09-09 04:14:55 +02:00
Sei Lisa
6b7b366f63 Fix llRot2Euler exception 2015-09-08 03:47:00 +02:00
Sei Lisa
bc4f574b33 Managed to deal with the '-nan' case in llList2CSV. Add test cases. 2015-09-07 02:56:44 +02:00
Sei Lisa
0122d6ed70 On second thought, disable explicitcast for list+nonlist and nonlist+list entirely, as they are not the same as list+(list)nonlist and (list)nonlist+list anyway. 2015-09-05 03:09:46 +02:00
Sei Lisa
d8649deebd nonlist + list was returning the type of the nonlist element. Fixed and added a
regression test.

Funnily enough, it was correct if explicit cast was active. Removed from explicit cast now that it's active for all.
2015-09-04 05:56:05 +02:00
Sei Lisa
aa74e6ed64 Sadly, Python can't represent -nan, even though llList2CSV can display it. Add a note to that effect. 2015-09-04 05:46:18 +02:00
Sei Lisa
15f1a07a72 There were more translated events. After an exhaustive analysis this is the definitive list. 2015-08-21 03:35:20 +02:00
Sei Lisa
e264260477 Two events produce different internal names than the event name itself. This was causing the reused names for these events to increase memory usage instead of reducing it. Fixed. 2015-08-21 01:20:28 +02:00
Sei Lisa
f8a6d3d86c Reorganize so that warningPass is always set at least once when constfold is set. 2015-08-19 05:41:21 +02:00
Sei Lisa
cd9bfd426e Update list of pre-allocated keywords. 2015-07-26 00:13:00 +02:00
Sei Lisa
1636e56266 The llGetListLength optimization can be applied to arbitrary expressions. 2015-07-13 07:16:32 +02:00
Sei Lisa
1a67db64dc Get rid of builtins.txt.dat by adding a parameter to the parser ctor. 2015-07-09 20:35:14 +02:00
Sei Lisa
1160fea8cf Fix extendedtypecast problem with negative constants after typecasts. 2015-06-23 06:54:04 +02:00
Sei Lisa
4cc268b574 Fix parenthesizing of expressions having ~ or ! 2015-06-17 18:30:32 +02:00
Sei Lisa
f5d150f7c9 Fix typo in IsBool and add coverage test. Report and fix by Code Violet. 2015-06-17 02:51:46 +02:00
Sei Lisa
52ebe20a67 Refine a comment 2015-06-17 02:31:58 +02:00
Sei Lisa
e35431cecf Forgot to truncate llSqrt to F32. 2015-06-16 04:41:36 +02:00
Sei Lisa
bfabcd16db Fix parser bug where list = anytype was accepted. Fix also the test suite. 2015-06-16 04:16:59 +02:00
Sei Lisa
cdc3a63179 Fix problem due to not copying a node. It still needs more analysis, but this patch is an improvement in that it fixes known problematic cases and doesn't seem to introduce new ones. 2015-06-14 05:11:32 +02:00
Sei Lisa
aaa8d3b7f4 Fix crash when a global was optimized out and another global depended on it. 2015-06-14 03:36:54 +02:00
Sei Lisa
e1d0753fec When a state is removed, remove its global declaration too. 2015-06-13 02:19:15 +02:00
Sei Lisa
d8629f9200 Update behaviour of llListFindList for LSO. 2015-05-24 04:22:31 +02:00
Sei Lisa
faf296fa74 Fix bug with scripts that have UTF-8 characters.
The parser expects bytes, not unicode.
2015-05-03 05:19:14 +02:00
Sei Lisa
4302ea846d Don't fall through after optimizing a negable comparison, as it's folded already and the variables were incorrectly set and broke our invariants. 2015-04-21 06:11:25 +02:00
Sei Lisa
d58bc2d350 Implement library function parameter optimization.
So far only two kinds: angle in llSensor[Repeat] and null keys in functions that take a key parameter.

Closes two TODOs.
2015-04-21 04:56:09 +02:00
Sei Lisa
17bf0b7a1e Fix recently introduced bug: function renaming failed. 2015-04-17 03:37:24 +02:00
Sei Lisa
be86216124 Do -(b + -c) -> -b+c. Also when a-b is transformed to a+-b, fold -b. 2015-03-29 06:09:26 +02:00
Sei Lisa
a859b3e8e4 Loop over (0, 1) instead of duplicating the code. 2015-03-29 05:43:38 +02:00
Sei Lisa
a19d49d193 Implement optimization of a>=const -> a>const-1 and similar, and fix cases where | -> & or a<0 -> a&0x80000000 is counter-productive.
The logic becomes quite convoluted.
2015-03-29 03:47:54 +02:00
Sei Lisa
274b563390 No need to simplify !!! to ! as FoldCond already takes care of that. 2015-03-29 01:27:08 +01:00
Sei Lisa
9aae475125 Implement bool(x < 0) -> bool(x & 0x80000000) w/ function domain check.
Cleans up three TODOs.
2015-03-29 00:16:17 +01:00
Sei Lisa
2cb9ad6fe5 Implement a first version of IsBool and use it to optimize && -> & 2015-03-28 23:49:10 +01:00
Sei Lisa
08f48a5c32 Make program flow more consistent, add TODO, refine another TODO. 2015-03-28 23:47:45 +01:00
Sei Lisa
01d8bba3f4 Don't always output a space after the unary minus, only when necessary. 2015-03-28 23:35:08 +01:00
Sei Lisa
4fbbda60a7 Elaborate on the TODO. 2015-03-28 23:34:07 +01:00
Sei Lisa
b8a7e88f1a Add TODO item 2015-03-28 23:31:11 +01:00
Sei Lisa
c154d5eb0d Deal with a number of issues in some expressions.
- Move TODO of <0 to !=-1 to boolean, as it's counter-productive otherwise.
- All a!=b except list!=list are equivalent to !(a==b).
- Change a>b to b<a to simplify cases to analize.
- Proper fall-through in some spots, or return in some others where it didn't apply.
- Simplify handling of a<-2147483648 as a&0, falling through, instead of coping with it ourselves.
2015-03-28 20:23:47 +01:00