Commit graph

873 commits

Author SHA1 Message Date
Sei Lisa
789eb85bfe Add the outfile.tmp file generated by a test to .gitignore 2019-01-15 23:22:02 +01:00
Sei Lisa
8c1dc90cc8 Add a routine used to generate some of the test cases
When run in SL, this program generates a list in pretty much the format expected by the test suite, therefore it's quite convenient to have.
2019-01-15 23:19:02 +01:00
Sei Lisa
d394adf45a Add a test case to the infinity vector conversion 2019-01-15 23:18:10 +01:00
Sei Lisa
e261ac2121 Add unit test for the _Pragma operator 2019-01-15 20:38:19 +01:00
Sei Lisa
7fd7eae56c Add *- to gitignore 2019-01-15 20:37:07 +01:00
Sei Lisa
8043cb7c9f Add two forgotten files from the inline tests 2019-01-15 20:35:17 +01:00
Sei Lisa
bb841eb65a Remove obsolete test programs 2019-01-15 18:47:10 +01:00
Sei Lisa
138d042b2e Fix bug in type conciliation function
Casting wasn't enough, it needed to call to_uint().
2019-01-15 01:22:44 +01:00
Sei Lisa
6dfbd804d0 Update PCPP with latest fixes 2019-01-13 19:33:13 +01:00
Sei Lisa
31fcb331c7 Add support for C11-style _Pragma operator on processpre
A minor difference is that strings and whitespace are parsed according to LSL rules, not to C rules, since this processing is performed in the lexer.

This could be fixed, but is it worth the trouble?
2019-01-13 19:03:10 +01:00
Sei Lisa
4a9cc9e20f Add support for comment passthrough to expression evaluator 2019-01-13 13:51:13 +01:00
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