Commit graph

514 commits

Author SHA1 Message Date
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
3f59f5f16f New upstream release of builtins.txt. 2017-08-17 16:57:08 +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
20d2f68918 New upstream version of builtins.txt. 2017-08-17 00:42:13 +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
dd6a65bb03 When including source at the top, make it more intelligible.
Avoid breaking URLs in particular.
2017-08-09 17:48:23 +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
b4d9d5bc8c Note that ListLength depends on constant folding. 2017-05-07 16:08:05 +02:00
Sei Lisa
7110802dab Fix incorrect explanation of the effect of multiple labels in LSO. 2017-05-06 16:19:42 +02:00
Sei Lisa
6fe4cc3ae8 Add (undocumented) option 'rsrclimit' to limit resource usage. 2017-05-06 16:17:46 +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
98da3f32c6 New upstream version of builtins.txt. 2017-03-17 04:51:39 +01: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
44dd088154 Fix expected exception in test case.
Changed in commit c71b0ee but not updated in test program.
2017-02-12 04:45:44 +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
8358fd5012 Fix a test case in testparser.py.
Commit 13f3c95 was clearly a step in the right direction. We had a test case that mistakenly relied on the broken behaviour that that commit fixed, for the constant values to remain in the output. That is clearly wrong, so we fix the test case to not rely on that.
2017-01-28 03:13:44 +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
9b09c29eea llUnescapeURL is side effect-free. 2017-01-27 20:14:47 +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