Commit graph

60 commits

Author SHA1 Message Date
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
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
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
6813bb0458 Make the second pass of FoldScript look a bit more logic. 2015-03-28 20:14:17 +01:00
Sei Lisa
2a617b34d0 Fix bug where a<<1 was not immediately optimized, and other minor changes.
* Add a TODO.
* Don't make two fold passes if DCR is off.
* Remove comment about parentheses that no longer applies.
2015-03-28 14:45:53 +01:00
Sei Lisa
59cdd64228 Warn about float constants that can't be represented in globals. Also don't duplicate the globals warnings. 2015-03-06 23:26:58 +01:00
Sei Lisa
c68a1f4ad6 Add copyright notices to all files, to prepare the program for release. 2015-03-05 23:18:41 +01:00
Sei Lisa
8f83e2f1ab Add "addstrings" option (disabled by default) to select whether to automatically concatenate strings during constant folding. 2015-02-28 20:01:51 +01:00
Sei Lisa
6ea01c4242 Added optimizations for most operators, and 'cornermath' option.
Only remaining operators are < <= > >= &.
2015-02-28 18:30:04 +01:00
Sei Lisa
1dea1bd12c Make parentheses no longer explicit in the AST (Beta).
The output module adds parentheses where necessary, depending on the evaluation order in the tree. Or that's the idea. Prone to bugs, let's see how it bodes.
2015-02-28 00:43:26 +01:00
Sei Lisa
8e5166bb2e Move the constant folding code to lslfoldconst.py.
lsloptimizer remains as the "conductor" and option handler.

As a result, new options have been added to enable DCR and constant folding.
2014-08-13 14:19:58 +02:00
Sei Lisa
36759cacba Move PythonType2LSL to the main lsloptimizer script.
This is preparation work for splitting the optimizer.
2014-08-13 13:44:54 +02:00
Sei Lisa
e3d8533caf Use self.shrinknames instead of checking the options again. 2014-08-10 02:05:31 +02:00
Sei Lisa
9295cb104a Cast() now adds parentheses where necessary. 2014-08-10 01:14:29 +02:00
Sei Lisa
de4d6f8857 Propagate X flag in Cast(): if the expression executes, so does the cast. 2014-08-08 04:05:01 +02:00
Sei Lisa
c080f4b596 Fix detection of SEF in assignments with vector/rot fields as LHS. 2014-08-08 04:03:37 +02:00
Sei Lisa
5d7829dc9d Fix a bunch of SEF-related bugs and forgotten cases. 2014-08-08 00:41:07 +02:00
Sei Lisa
7a6e13b786 Remove line that does nothing useful. 2014-08-07 22:10:15 +02:00
Sei Lisa
954b8d81d4 Forgot a SEF case. 2014-08-07 22:09:00 +02:00
Sei Lisa
9c4d81db08 Implement side-effect-free (SEF) analysis. Also optimize x++ to ++x.
As an additional bonus, the condition folding function is now the one that converts a condition to -1, relieving that burden from the rest of the code and simplifying tests.
2014-08-06 04:30:26 +02:00
Sei Lisa
5773449edb Convert warnings to add the WARNING: title in the function. 2014-08-05 15:55:49 +02:00
Sei Lisa
58e22f77ce Prepare for the incoming Dead Code Removal module. 2014-08-05 15:47:14 +02:00
Sei Lisa
bcc7fe3524 Fix bug in FoldStmt where EXPR nodes were not optimized out. 2014-08-05 15:38:19 +02:00
Sei Lisa
24a32c30e3 Fix bug where folding a FOR loop with const false cond produced bad code.
More precisely, the initializator list was not wrapped into EXPR nodes. Now it is.

While on it, fix a minor bug (the substitutive of a FOR statement should produce no output type), and change order of execution to the actual one (iterators come last).
2014-08-04 02:19:36 +02:00
Sei Lisa
17e94a0d0f Add FoldCond as a stub. Change cond constant to -1. Add support for EXPR.
(EXPR as a statement, not as a general 'expression')
2014-08-03 20:06:50 +02:00
Sei Lisa
14e5b78d94 Remove empty statements. Optimize out 'else ;' and 'else {}'.
Without empty statement removal, {;} would trick the optimizer into believing the statement was not empty. E.g. if(x) ; else {;} would not remove the else.
2014-08-02 10:40:59 +02:00
Sei Lisa
dce6419b4f Deal with the state change in globals error. 2014-08-01 23:51:24 +02:00
Sei Lisa
400809671e Fix GetNextShortest. Add test and regression cases. Rename AssignNewNames. 2014-08-01 18:02:55 +02:00
Sei Lisa
6c248c46e3 Implement the shrinknames option.
Fixes some bugs with the treatment of the shrink attribute, some others with the output of renamed stuff.
2014-08-01 05:07:50 +02:00
Sei Lisa
fb65144e1b One less to-do. 2014-08-01 02:02:01 +02:00
Sei Lisa
cf880b8dbf Fix priorities for x << const optimization. 2014-07-31 19:45:30 +02:00
Sei Lisa
a303ef2066 Unfold all assignment+operation operators to optimize them better.
With test case.
2014-07-31 18:44:50 +02:00
Sei Lisa
5bedc17b73 Fix bug where optimization disabled didn't return a value. 2014-07-31 05:39:20 +02:00
Sei Lisa
e5714eba25 Fix the obnoxious issue with globals propagation in full expressions.
Fixed by backtracking in the parser, and keeping a copy of the original expression if it's a simple_expr, which is used for output in place of the folded one.

There's still the potential issue that if a global is optimized away, then it will "come back" during output and cause an error because the definition is missing.
2014-07-31 04:47:19 +02:00
Sei Lisa
5b401ff9a5 Copy the node, don't just ref it. Also add comments on the simple_expr issue. 2014-07-31 04:07:03 +02:00
Sei Lisa
2cbed52bf7 Add optimization of declarations.
integer a = 0; -> integer a;
float f; -> float f = 0;
vector v; -> vector v = <0,0,0>;
rotation r -> rotation r = <0,0,0,1>;
2014-07-31 03:29:21 +02:00
Sei Lisa
6ec39aa745 Add a bunch of optimizations. Fix || and && results.
Notably, addition/subtraction, and llGetListLength -> !=[]

But also parenthesis removal etc.

With test coverage.
2014-07-31 02:53:51 +02:00
Sei Lisa
895e4f4668 Overall renaming of stuff to make it more understandable. 2014-07-30 16:00:00 +02:00
Sei Lisa
fb68273eed Turned everything upside down, and fixed a couple bugs.
Bugs fixed:
- %= and the new assignment operators were not emitting error on invalid types.
- List globals referenced in another global were duplicated entirely.
- Properly recognize -option in the command line.

Rest:
- Complete overhaul of the internal data structure.
  - Got rid of the symbol table plus mini-trees, and made everything one big tree plus an auxiliary symbol table.
  - No more special case hacks like using tuples instead of lists...
  - Got rid of the EXPR hack.
  - Dict-based, rather than list-based. Allows adding arbitrary data to any node or symbol entry.
- Added a few coverage tests for the new code.
- Return values can now be chained; the functions parameter requirement is gone. Still not fully convinced, though. My guess is that a parser object should be passed between functions instead. Will do for now.
2014-07-30 04:54:16 +02:00
Sei Lisa
5d4abf967d Comment changes - just make the idea more explicit. 2014-07-28 21:39:36 +02:00
Sei Lisa
b441c1774f Fix incorrect warning when a global vector/quat/list contains an ident 2014-07-28 18:46:37 +02:00
Sei Lisa
a6b3a0946f Enable foldtabs warning 2014-07-28 17:39:35 +02:00
Sei Lisa
eab0bec84b Add preprocessor skip option, command line options and help, options for all functions, and enhance parentheses removal. 2014-07-28 02:13:08 +02:00
Sei Lisa
8907a59d5f Fix remaining bug in optimizer, and minor fixes.
- Get rid of Fold().

- Handle globalmode properly. It was sometimes active during function calls.

- Change all warning() calls to not use Unicode, just in case the output is redirected to file.

- Cosmetic fixes and TODO items.
2014-07-27 23:33:20 +02:00
Sei Lisa
64e5d0dc92 Check that it's a variable definition before collapsing or giving warning. 2014-07-27 22:04:15 +02:00
Sei Lisa
3dd73f218f Fix a few more statements missing. 2014-07-27 21:05:57 +02:00
Sei Lisa
6af4f40752 Add TODO items 2014-07-27 20:48:37 +02:00
Sei Lisa
1747028211 Finish coverage tests. 2014-07-27 20:26:24 +02:00
Sei Lisa
7623c444a8 Forgot empty statement. Also make warning more prominent. 2014-07-27 20:14:25 +02:00
Sei Lisa
e57c21a73a Fix FIELD and IDENT in globals. 2014-07-27 20:03:57 +02:00