Commit graph

712 commits

Author SHA1 Message Date
Sei Lisa
a1b5f1bb45 Avoid exposing our sint/uint class outside 2019-01-13 03:40:24 +01:00
Sei Lisa
01d45191ae Minor fixes in encoding handling
This actually needs a complete overhaul, factorization et al.
2019-01-13 00:25:28 +01:00
Sei Lisa
f958b1cdf9 Append --preargs options at the end of the command line
Allows the user to override default defines, for example.

Also add docstring to PreparePreproc().
2019-01-12 21:16:35 +01:00
Sei Lisa
7dcd7aa315 Add link to ned14/pcpp, moving the long link further down. 2019-01-12 20:35:10 +01:00
Sei Lisa
67164f4fbe Don't report pcpp as modified if it has untracked files 2019-01-12 20:33:52 +01:00
Sei Lisa
d2c25c7812 Simplify a comparison in cpreproc.c 2019-01-12 00:29:06 +01:00
Sei Lisa
c0168c8a34 Add files necessary to add an internal preprocessor (not implemented yet)
Includes PCPP as a submodule (which in turn pulls PLY as a submodule, so be sure to initialize submodules recursively). Also includes a file to interface PCPP with the optimizer, patching its behaviour according to our needs.

Special thanks to Niall Douglas and David Bezley for authoring PCPP.
2019-01-11 21:21:36 +01:00
Sei Lisa
352f410d12 Add forgotten unit tests for the identifier substitution fiasco 2019-01-11 21:20:21 +01:00
Sei Lisa
0877f8c7e6 Forgot unit_tests/__init__.py necessary to run the JSON test 2019-01-11 17:34:10 +01:00
Sei Lisa
42f47d38f0 Fix swaps and other misoptimizations
This undoes 454d44e85f
2019-01-11 02:09:15 +01:00
Sei Lisa
c3bb056f05 Revert the optimization re-added in 1946acf3a4
That change needs much more analysis and thought. And we need more testcases.
2019-01-10 23:26:58 +01:00
Sei Lisa
06f8370886 Add a reference to the author name's origin
Add TODO on vectors and rotations, too.
2019-01-10 21:56:26 +01:00
Sei Lisa
1b3c8a4d89 Check min and max to determine truth value of condition
Also added some min/max values for a few functions.

This allows optimizing things like:

  ! llGetNumberOfPrims()  ->  0
2019-01-07 00:15:38 +01:00
Sei Lisa
5bfb218505 Perform redundant jump elimination in lastpass
This is a first try at redundant jump removal (jumps that target the very next instruction). It's too basic in several ways.

- The statement is replaced by a ';' instead of removed.
- If the jump was the only statement in an if, when the if becomes empty, it's not folded.
- Jumps that are last in the 'then' branch of if+else are not visible. This would need either to track multiple last statements, or to have some means to anticipate what the next statement is at every statement. A Control Flow Graph would help a lot.
- When a label is immediately followed by a jump, all jumps to that label should target the destination of that jump if it's in scope. Added to TODO.
- It misses some optimizations when not expanding WHILE and FOR into IF/JUMP.

Moving everything to an earlier stage would help with some of these, especially with ';' and 'if' folding. Unconditionally expanding WHILE and FOR would also help.
2019-01-06 22:32:19 +01:00
Sei Lisa
574f92d08e Allow #pragma OPT inline 2019-01-06 02:20:34 +01:00
Sei Lisa
c5fd4932f1 Finish inlining for all loop conditions 2019-01-06 01:59:36 +01:00
Sei Lisa
0ffe823c18 Move symbol existence check and creation to newId
ENameAlreadyExists has also been expanded to accept an inliner object, even though it's not used yet. Plans are the same as in EParse.
2019-01-06 01:33:49 +01:00
Sei Lisa
41515f338a Disable inline by default, due to the impact it has on WHILE/FOR loops 2019-01-06 01:18:14 +01:00
Sei Lisa
852fec2f26 Inliner: Add and use newSymtab() and newId() 2019-01-06 01:10:21 +01:00
Sei Lisa
a800604632 Add a request to change the usage text if the GPL version is changed 2019-01-06 00:52:54 +01:00
Sei Lisa
55cb941234 Fix inlining of functions in conditions in DO loops 2019-01-06 00:52:54 +01:00
Sei Lisa
47a324f4a6 Coverage test lsloutput-1 is prone to exceptions. Activate -y. 2019-01-06 00:50:42 +01:00
Sei Lisa
ddec4c464e Inline functions in 'do' loop conditions have been fixed 2019-01-05 23:10:01 +01:00
Sei Lisa
cf5ee2793a Make mismatches fail with assertTrue instead of assertEqual
We already report the differences even in diff format, and the scripts can get long. The output of assertEqual was not useful, therefore it's eliminated.
2019-01-05 22:50:12 +01:00
Sei Lisa
1a83213a40 Explain the states in the argument parser 2019-01-05 00:50:08 +01:00
Sei Lisa
40cd88e9f7 Minor pickiness
Even if the last char is a backslash, if we're inside a double quoted string, report unterminated string on EOF.
2019-01-05 00:09:50 +01:00
Sei Lisa
054539adf9 Make .fail files replace the docstring in order to be visible 2019-01-04 22:29:15 +01:00
Sei Lisa
1867dc78e7 Add the new test suite.
This test suite has been in use for a long time now, in place of the obsolete and unmanageable testparser.py and testfuncs.py. It verifies the complete optimizer output to stdout and stderr, to ensure that the output matches the expectations.

See unit_tests/README.txt for more info.
2019-01-04 20:27:36 +01:00
Sei Lisa
7fbde0269c Fix indentation typo (cosmetic) 2019-01-04 19:35:36 +01:00
Sei Lisa
1946acf3a4 Proper fix for unwanted substitutions in function calls
SymbolReplacedOrDeleted had an "emergency fix" that disabled several kinds of substitutions, because they generated code that didn't compile. The cause was actually elsewhere.

The actual problem was the marking of function parameters as being written to by function calls. This is true in a sense, but there's a big scope change that totally destroys the possibility of substituting identifiers, for example.

We were not removing the function parameters, anyway, therefore that code has just been disabled.

Note that removal of function parameters may be impossible if one parameter has side effects. Consider this:

f(string x, integer y, string z)
{
    llOwnerSay(x + z);
}
integer n = 2;
default{state_entry(){
  f("a" + (string)n, n=llSetRegionPos(<100,100,100>), "c" + (string)n);
}}

Even worse if the expression for the x argument has side effects too and x and y need to be performed in the right order.

Fortunately, such case is highly unlikely. But if we ever implement removal of function parameters, that's an additional difficulty to take care of.
2019-01-03 02:33:23 +01:00
Sei Lisa
454d44e85f Optimize chains of assignments
This allows optimizing, for example:

  integer a = 1;
  integer b = a;
  llOwnerSay((string)b);

which wasn't done before. This case is prone to happen with inlined functions, e.g. using the result of an inlined function as a parameter to another.
2019-01-03 02:32:14 +01:00
Sei Lisa
5a5635358f Add an assertion where we expect sym['W'] to have a symbol 2019-01-02 20:43:47 +01:00
Sei Lisa
aca4cc2721 OKtoRemoveSymbol: Return the symbol as specified, instead of True 2019-01-02 20:43:47 +01:00
Sei Lisa
8322284faa Rename SymbolReplacedOrDeleted to OKtoRemoveSymbol
It was an awful name but we couldn't think of anything better. That's what we have come up with as a substitute, which is not entirely accurate but it is MUCH more descriptive of what it actually does.
2019-01-02 20:43:47 +01:00
Sei Lisa
ffe55b38c3 Add the capability to show scope info to the output module
It's set in a variable local to that module. There's currently no way to enable it except by editing the code, but since it's mostly for internal purposes, it's OK like that.
2019-01-02 15:05:21 +01:00
Sei Lisa
ad71303eb0 Fix lack of 'ref' in symbol table entries for labels
These were expected by the constant folder, causing a crash.
2019-01-02 13:33:58 +01:00
Sei Lisa
2d583bb7e3 Fix scope of variables in inlined functions
The identifiers didn't point to the right scopes, causing optimization to produce wrong results.
2019-01-02 12:34:00 +01:00
Sei Lisa
42750c56d7 Fix some comments 2019-01-02 00:38:44 +01:00
Sei Lisa
f243f3a3c1 New copyright year 2019-01-01 22:54:34 +01:00
Sei Lisa
a4986f21df Add 'inline' directive to forcibly inline function calls 2019-01-01 22:30:18 +01:00
Sei Lisa
7bb07ecf38 Refine the places where void expressions are allowed
To prevent passing down a value in every call, the flag is a member. Yes, ugly.
2019-01-01 22:23:54 +01:00
Sei Lisa
660dcff65b Remove the symbol table's parent pointer
Instead of a tree of symbol tables, we keep a running stack of active symbol tables while parsing. The only case in which this causes problems is forward reference resolution for jump labels, which is solved by storing a copy of the stack at the point the jump was found.
2018-12-29 21:19:29 +01:00
Sei Lisa
76f483fc11 Add scope field to {} nodes
Since we need to add variables, we need to know which scope to add them to. Add this information to the {} node, which is what creates a new scope.

An alternative would be to scan for any variable or label declaration within the braces and use that or create a new one if none, which is more expensive and may waste symbol tables.
2018-12-29 21:10:14 +01:00
Sei Lisa
3542824d51 Add spaces after commas in vector/rotation constructors 2018-12-27 23:35:23 +01:00
Sei Lisa
6f32b4710a Remove handling of corner cases that we decided to not support
There was some remaining code trying to deal with labels in the single statement part of IFs and FORs.
2018-12-26 19:25:11 +01:00
Sei Lisa
b329b2b28e Avoid a possibly unnecessary expansion
When transforming if(!non-bool | !bool) to if(!(non-bool & -bool)), don't negate the bool if non-bool is actually an AND-bool.
2018-12-24 17:22:54 +01:00
Sei Lisa
c9f73bd429 Extend an optimization to cover some (admittedly rare) cases.
The value of bool|const is const when bit 0 of const is 1. This is a generalization of the case bool|1 = 1.
2018-12-24 17:22:54 +01:00
Sei Lisa
141301d7ff Reformatting 2018-12-24 17:22:54 +01:00
Sei Lisa
e123866e6e Apply DeMorgan in some cases that were not caught.
Example: the optimization of if(i < 2 || i) was suboptimal, because FoldTree was done before FoldCond. In a first stage, the || was removed: if(!!(i < 2 | i)); when folded, the inner ! was optimized first and the result was if(!(1 < i & (!i))), which FoldCond wasn't smart enough to handle.

The new optimization takes over from there, and converts if(!(!a & b)) with b boolean, in any order, to if(a | !b). When applied to the above expression, it gets folded to if(i < 2 | i) as expected, which is optimal.

Also, new function: IsAndBool (see docstring), used on b in the above example.
2018-12-24 17:18:48 +01:00
Sei Lisa
fa547cd9e8 Add blank lines to make the output somewhat prettier
Add blank lines between functions, between functions and states, between variables and functions or states, between states, and between events.

Or more concisely: add blank lines between events and between all elements at the global level except between variables (that actually describes the algorithm).

Some test cases expected no newlines; fix them.
2018-12-23 18:12:10 +01:00