Commit graph

30 commits

Author SHA1 Message Date
Sei Lisa
fe2dd9a721 First baby steps towards dual Python2+3 compatibility 2019-01-16 00:15:06 +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
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
f243f3a3c1 New copyright year 2019-01-01 22:54:34 +01:00
Sei Lisa
285c7172fd Get rid of DoesSomething() in favour of SEF
The missing bit was to mark labels are SEF when they are not referenced. Label references are now counted at parse time, enabling us to do this.

Also, make FoldStmt clearer when the node is an expression.
2018-05-17 09:08:48 +02:00
Sei Lisa
4a554d60e8 Remove a TODO item that was already done 2018-04-02 13:42:28 +02:00
Sei Lisa
075d3aba0c Change the AST node type from dict to object
That was long overdue. Obviously, this is a large commit.

The new nr (node record) class has built-in dump capabilities, rather than using print_node().

SEF always exists now, and is a boolean, rather than using the existence of SEF as the flag. This was changed for sanity. However, other flags like 'X' are still possibly absent, and in some cases the absence itself has meaning (in the case of 'X', its absence means that the node has not yet been analyzed).

Similarly, an event is distinguished from a UDF by checking for the existence of the 'scope' attribute. This trick works because events are not in the symbol table therefore they have no scope. But this should probably be changed in future to something more rational and faster.

A few minor bugfixes were applied while going through the code.

- Some tabs used as Unicode were written as byte strings. Add the u'\t' prefix.
- After simplifying a%1 -> a&0, fold again the node and return. It's not clear why it didn't return, and whether it depended on subsequent passes (e.g. after DCR) for possibly optimizing out the result. Now we're sure.
- A few places lacked a SEF declaration.
- Formatting changes to split lines that spilled the margin.
- Some comment changes.
- Expanded lazy_list_set definition while adapting it to object format. The plan was to re-compress it after done, but decided to leave it in expanded form.
- Added a few TODOs & FIXMEs, resisting the temptation to fix them in the same commit:
  - TODO: ~-~-~-expr  ->  expr + -3.
  - FIXME: Now that we have CompareTrees, we can easily check if expr + -expr cancels out and remove a TODO. Low-hanging fruit.
  - TODO: Check what we can do when comparing non-SEF and non-CONST values in '>' (current code relies on converting '>' to '<' for applying more optimizations, but that may miss some opportunities).
  - FIXME: Could remove one comparison in nt == '&&' or nt == '||'. Low-hanging fruit.
2018-04-01 02:14:00 +02:00
Sei Lisa
f3c87299c2 Move comment to its correct place 2018-03-23 22:05:05 +01:00
Sei Lisa
2b14acc8a0 Follow-up fix to 82081b2 (#3)
Globals appearing in vectors or rotations inside a list still caused a crash.

Fixes #3 again.
2018-03-23 21:57:33 +01:00
Sei Lisa
d0d6d6744b Bump copyright year
The help text in main.py was still at 2015. Oops.
2018-03-23 16:36:45 +01:00
Sei Lisa
70f39d7f5e Remove "magic names" where possible, using new data from fndata.txt 2017-10-27 23:39:26 +02:00
Sei Lisa
82081b2206 Fix crash when variables appear inside global lists.
Fixes #3.
2017-10-16 02:22:52 +02:00
Sei Lisa
cc96850f66 Fix bug where list elements of global declarations were removed.
CleanNode was too greedy, because children of global declarations (particularly lists) are not marked executable. Make a special case for them and don't recurse, since what matters is whether the declaration itself is executed. Its contents can't be cleaned up.
2017-10-16 02:22:40 +02:00
Sei Lisa
fe574bb462 Bump copyright year.
'bout time.
2017-08-09 19:45:46 +02: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
cdc3a63179 Fix problem due to not copying a node. It still needs more analysis, but this patch is an improvement in that it fixes known problematic cases and doesn't seem to introduce new ones. 2015-06-14 05:11:32 +02:00
Sei Lisa
e1d0753fec When a state is removed, remove its global declaration too. 2015-06-13 02:19:15 +02:00
Sei Lisa
f7556e7a66 Remove globals from symbol table when no longer necessary. 2015-03-13 20:11:57 +01:00
Sei Lisa
fc7abc7d99 Fix bug broken by 562154e7aa.
Referencing a global that was optimized out, caused a crash.

```
integer DEBUG = 1;

default
{
    state_entry()
    {
        if (DEBUG) llOwnerSay("DEBUG");
    }
}
```
2015-03-13 16:49:31 +01:00
Sei Lisa
562154e7aa Remove the symbol table entry too when removing a global state/function/var. 2015-03-07 14:33:11 +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
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
4461f36dce Emergency fix for a bug discovered via a nPose plugin. 2015-02-12 07:46:02 +01: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
72b4b08cbe Add dead code elimination module. 2014-08-10 02:07:00 +02:00