Commit graph

873 commits

Author SHA1 Message Date
Sei Lisa
8db8872dbe Import the changes to cpreproc.py from the preprocessor branch
These changes make it ready for prime time, but main.py still does not expose the functionality.

Changes include:

- Instead of passing paths, we pass parameters, which are parsed to extract the paths (no syspaths, only regular paths) and the defines.
- Errors in the preprocessor are reported to the caller (i.e. to main).
2020-11-02 11:16:36 +01:00
Sei Lisa
13e48ff956 Improve +processpre directive parsing to include #warning 2020-11-02 11:16:36 +01:00
Sei Lisa
d5b83d50c4 Fix test case in the last commit 2020-11-02 11:14:32 +01:00
Sei Lisa
90fddf9dcd Report EParseCodePathWithoutRet at a more meaningful position 2020-10-11 16:31:49 +02:00
Sei Lisa
9e5f6e928d Improve compatibility of llToLower/llToUpper
Based on sim experiments.
2020-09-23 01:11:21 +02:00
Sei Lisa
1e22a21074 New upstream version of builtins.txt 2020-06-12 21:02:07 +02:00
Sei Lisa
f3037df055 Forgot to add the test case for the previous commit 2020-06-01 20:56:31 +02:00
Sei Lisa
d6bf0c390e Fix two issues in the dead code removal module
1. When the last statement of a function is a RETURN statement which is syntactically required, it could still be deleted.
2. The child of a RETURN statement could be removed if the statement was not executed.

This commit fixes both issues.

Bug report and test case provided by @Tonaie. Fixes #14.
2020-06-01 20:49:48 +02:00
Sei Lisa
0affbf13dd Fix "" + list_expr producing list_expr
The type checks were not strong enough. While on it, strengthen other similar checks as well.

Reported by @Tonaie. Fixes #13.
2020-04-23 13:47:57 +02:00
Sei Lisa
4d75f0f792 Future-proof of list-plus-elem.lsl and list-plus-elem.out 2020-04-23 13:47:51 +02:00
Sei Lisa
c8a0a21823 Add llLinear2sRGB / llsRGB2Linear implementations 2020-04-23 01:10:37 +02:00
Sei Lisa
5755bb1c30 Explain the origin of the PCPP License that applies to the excerpt used 2020-04-23 00:38:20 +02:00
Sei Lisa
234b9b23a3 Bump copyright year 2020-04-23 00:38:20 +02:00
Sei Lisa
2b07c13498 Update to latest kwdb from upstream 2020-04-22 21:17:45 +02:00
Sei Lisa
be06ffe1f2 New upstream version of builtins.txt 2020-02-29 17:02:58 +01:00
Sei Lisa
be850e69cc Move comment 2019-11-03 01:09:23 +01:00
Sei Lisa
a8d8c14c79 Fix NULL_KEY being optimized to "" in UDFs; do some minor changes
Bug reported by @tapple. Fixes #11.
2019-11-03 00:55:30 +01:00
Sei Lisa
2408e6e6fe Raise resource limits; raise them again in case of exception
The limits were too low to be reasonable with more modern versions of Python.

Double exceptions were possible. Make use of soft/hard limits; raise the soft limit in case of exception. That should make it less likely to get a double exception.

Per bug report by @LeonaMorro (thanks!)

Fixes GitHub issue report #9 (fix #9).
2019-10-11 20:15:52 +02:00
Sei Lisa
6d959f6f90 Handle llGetLinkName with invalid values 2019-10-11 19:38:28 +02:00
Sei Lisa
980b588986 Add FIXME and TODO 2019-10-11 19:38:05 +02:00
Sei Lisa
c02998518a Rename FoldCond -> FoldAsBool which better expresses the idea 2019-07-25 17:44:45 +02:00
Sei Lisa
1ab9dd69b4 Fix optimization of fn > -1 and fn < 0 when fn's minimum is -1 in conditions
E.g. llSubStringIndex(...) > -1 was converted into !~llSubStringIndex(...) which is incorrect. We even had a test case for it... with a wrong expected response file.

Bug report and test case by Sinha Hynes (thanks!)
2019-07-16 01:58:19 +02:00
Sei Lisa
1bdaff32ab When optimizing nonconst * const, cast the result to the type of the operator.
Per bug report by @Welcius.

Fixes #8.
2019-07-02 15:40:20 +02:00
Sei Lisa
750465f17b New upstream version of builtins.txt, new OBJECT_* constants 2019-06-23 13:33:02 +02:00
Sei Lisa
00b103c8aa Simplify v*q, make q*q more accurate, add q*q and q/q unit tests
vector * quaternion: Simplified by precalculating the repeated products and removing math.fsum.

quaternion * quaternion: Add more F32's to get a result closer to SL's (still not there, but we're definitively closer now).

We left out quaternion/quaternion in the tests, and the q*q test was not general enough (had many zeros). Remedied that.
2019-05-23 01:57:27 +02:00
Sei Lisa
ec509b3840 Fix parenthesization of unary minus
The algorithm for adding parentheses around unary operators was not working properly. It converted a * (-b) * c into a * -b * c, which LSL handles as a * -(b * c).

Fix and add test cases for that. One of the test cases shows an example where the difference matters: 0 * (-1e20) * 1e20 should result in 0.0, but if wrongly parenthesized, it gives NaN, because 1e20*1e20 gives infinity due to float overflow, and minus infinity times 0 is indeterminate.

The addition of parentheses has been improved, but it still does not eliminate every redundant parenthesis.

Also fix the horrendous typo of using "operands" where it should be "operators".
2019-05-04 23:20:20 +02:00
Sei Lisa
9d540798b4 Allow returning void expressions where state changes are allowed
In the same places as state changes are allowed, i.e. in places where a parent of the AST node is a WHILE/DO/FOR or an IF without ELSE, it's allowed to use return statements with expressions that return void, e.g. llDie(), provided the function itself is declared as returning void.

The construction, when found, is rewritten to '{<void expression>; return;}' because the optimizer is not designed to deal with these monsters.

We've renamed the variable SuspiciousStSw to PruneBug, because it's used for both purposes now, though a better name might have been PruneBugPendingChecks, because these are only errors if the IF has an ELSE. We've also added the exception to raise as part of the data stored in the list.

Per report by Tonaie Resident.
2019-05-01 04:28:58 +02:00
Sei Lisa
3cfbbb923c The encoding of sys.stderr can exist and be None. 2019-05-01 01:22:54 +02:00
Sei Lisa
2c94905f1e Add regression test for the keyerror bug 2019-02-26 02:28:21 +01:00
Sei Lisa
73bc2c29a8 Fix a couple of slips that can cause crashes
'Type' is a string with a LSL type. 'Kind' is a single leter denoting the kind of identifier. We meant Kind. Twice.
2019-02-25 19:59:59 +01:00
Sei Lisa
985b9c4ef1 New upstream version of builtins.txt 2019-02-23 02:06:03 +01:00
Sei Lisa
7589d72572 Add missing functions to fndata.txt 2019-02-08 18:30:33 +01:00
Sei Lisa
4b83ae6c4e More upstream changes to builtins.txt 2019-02-07 14:46:53 +01:00
Sei Lisa
f2aa2ed231 New upstream version of builtins.txt adding INVENTORY_SETTING 2019-02-06 18:54:40 +01:00
Sei Lisa
7282e539d0 Add a directory that is important for tests
It had no files, so git didn't include it. Sigh.
2019-02-04 19:05:08 +01:00
Sei Lisa
2ade2804df Bug fix: include 'emap' attribute in UniConvScript
Fixes an AttributeError: 'UniConvScript' object has no attribute 'emap'
2019-02-04 19:03:46 +01:00
Sei Lisa
8cfcdd090a Fix --emap output when the error is not in the main file 2019-02-04 17:51:15 +01:00
Sei Lisa
68c8726a64 Option to output error messages suitable for automated processing
Enables use of the optimizer as an editor plug-in.
2019-02-04 17:20:12 +01:00
Sei Lisa
f0068dd3bc Style fixes
Calm pyflakes by using identifiers, and change hexversion to version.major.
2019-02-04 00:07:12 +01:00
Sei Lisa
09556d5fbc 'backslashreplace' makes no sense for str.decode() 2019-02-04 00:07:10 +01:00
Sei Lisa
128005e889 Fix bug in inlining of empty for() initializer
It was causing an exception. Fixed now.

Thanks to Cindy Reynaud for reporting the problem and sending a backtrace.
2019-02-02 00:50:05 +01:00
Sei Lisa
65f217afa8 Fix codec problem on MSW 2019-01-31 11:51:55 +01:00
Sei Lisa
326091624c Fix non-compliance problem with octal/hex literals without U suffix
To follow the standard, hexadecimal and octal values that don't fit an intmax_t must be of type uintmax_t, regardless of the presence of the U suffix.
2019-01-21 16:28:15 +01:00
Sei Lisa
dc41b36ace Update to latest pcpp (fixes __LINE__)
See https://github.com/ned14/pcpp/issues/25 for details.
2019-01-18 16:46:12 +01:00
Sei Lisa
36ed90c9ba Revert _Pragma operator
Revert "Add support for C11-style _Pragma operator on processpre".
Revert "Add unit test for the _Pragma operator".

This reverts commits 31fcb331c7 and e261ac2121.

This should rather be the job of the preprocessor, which should generate #pragma lines. gcc does that.
2019-01-17 20:30:04 +01:00
Sei Lisa
fba40123e1 Only include BOM if it isn't already present. 2019-01-17 12:55:49 +01:00
Sei Lisa
b5092c0be2 More Unicode vs str fixes 2019-01-16 20:24:31 +01:00
Sei Lisa
173a12be15 New feature: add preprocessor params before or after system's
Reverts f958b1cdf9, and adds the possibility of adding parameters after the system-inserted ones through a new command line parameter -A/--postarg.

Enables using e.g. both a command interpreter which requires the file to execute before any other parameters, and overriding the default definitions.
2019-01-16 19:19:27 +01:00
Sei Lisa
44ba2e2a8a Add digraph support to the default mcpp command line 2019-01-16 19:05:24 +01:00
Sei Lisa
fe2dd9a721 First baby steps towards dual Python2+3 compatibility 2019-01-16 00:15:06 +01:00