Commit graph

401 commits

Author SHA1 Message Date
Sei Lisa
08f48a5c32 Make program flow more consistent, add TODO, refine another TODO. 2015-03-28 23:47:45 +01:00
Sei Lisa
01d8bba3f4 Don't always output a space after the unary minus, only when necessary. 2015-03-28 23:35:08 +01:00
Sei Lisa
4fbbda60a7 Elaborate on the TODO. 2015-03-28 23:34:07 +01:00
Sei Lisa
b8a7e88f1a Add TODO item 2015-03-28 23:31:11 +01:00
Sei Lisa
c154d5eb0d Deal with a number of issues in some expressions.
- Move TODO of <0 to !=-1 to boolean, as it's counter-productive otherwise.
- All a!=b except list!=list are equivalent to !(a==b).
- Change a>b to b<a to simplify cases to analize.
- Proper fall-through in some spots, or return in some others where it didn't apply.
- Simplify handling of a<-2147483648 as a&0, falling through, instead of coping with it ourselves.
2015-03-28 20:23:47 +01:00
Sei Lisa
de33c2df01 Simplify operands of bitwise OR expressions as booleans. Deals with a TODO in a more general way. 2015-03-28 20:16:06 +01: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
edbc240408 Remove 'Local' from symbol table; add note about an unimplemented feature; improve symbol table documentation; rename a helper variable. 2015-03-27 02:12:32 +01:00
Sei Lisa
921955f321 Implement function overriding syntax extension, fixing a bug on the way.
The funcoverride option allows defining multiple functions with the same name, each overriding the former. That's for compatibility with Firestorm, whose optimizer does that.

While on it, fix a bug where defining a function whose name matches a library function was not reporting an error, and rename self.functions to self.funclibrary for clarity. It also brings consistency with other parts of the code and with the code documentation.
2015-03-27 00:35:37 +01:00
Sei Lisa
3839863a21 EInternal is no longer reused. 2015-03-26 23:26:36 +01:00
Sei Lisa
e21173170e Simplify the builtins.txt parser REs by checking the types in the code.
Gives us more granularity reporting errors.
2015-03-26 23:08:54 +01:00
Sei Lisa
29d003b108 Add a comment about C backslash-return behaviour. 2015-03-24 21:56:35 +01:00
Sei Lisa
47eee0312b Revamp and fixes of REs for pre-preprocessing.
Easier to follow and to maintain this way. Fixes known and potential bugs, plus potential lack of greediness.
2015-03-20 17:45:38 +01:00
Sei Lisa
cd1826e9e0 Bump version. 2015-03-19 04:31:47 +01:00
Sei Lisa
df8a8b4e9e Revamp command line options to add mcpp mode with defaults.
Also remove stderr from subprocess call (let the subprocess do its own output to stderr without capturing and re-emitting it ourselves).
2015-03-19 04:11:29 +01:00
Sei Lisa
226f382c4f Switch the predefined macros to variadic, to allow commas. 2015-03-17 19:41:36 +01:00
Sei Lisa
aea101a823 Add --precmd, bump version, report 'version N' instead of 'vN' on --version 2015-03-15 20:28:53 +01:00
Sei Lisa
f93e6d65a4 Deal with encoding issues, and simplify subprocess poll loop. 2015-03-15 20:01:41 +01:00
Sei Lisa
c8bec32242 Add a comment to prevent mistakes. 2015-03-15 19:49:52 +01:00
Sei Lisa
56f40a9c76 Ensure the script is Unicode before parsing. 2015-03-15 19:19:57 +01:00
Sei Lisa
31b7048fc9 Remove debug info left by mistake. 2015-03-15 19:19:10 +01:00
Sei Lisa
3c962ef32b Add external preprocessor invocation. 2015-03-15 06:18:55 +01:00
Sei Lisa
b8f73bb5e1 Don't open the script in binary mode, open it in text mode.
Not too sure about this change, but it eliminates CRs before LFs.
2015-03-15 02:18:01 +01:00
Sei Lisa
9e0ed0521b Reorganize main to use getopt. Implement -o for output file and -O help.
Also --version and -h/--help.
2015-03-14 23:17:15 +01:00
Sei Lisa
5b105e5772 Some enhancements to README.md 2015-03-14 11:33:43 +01:00
Sei Lisa
aa0d84e01b Another link fix *sigh* 2015-03-14 04:11:11 +01:00
Sei Lisa
a462b6b41d Fix link. 2015-03-14 04:10:11 +01:00
Sei Lisa
a947b63730 README.md: Move documentation to seis.shop.tm 2015-03-14 03:53:44 +01:00
Sei Lisa
9bd66dd6fa Optimize out function calls to SEF functions with non-SEF arguments.
The function call is removed, and the arguments transformed to a block of expression statements.
2015-03-13 23:48:24 +01:00
Sei Lisa
df31a69465 In functions that end in 'return;', remove the 'return;'.
This allows better side-effect analysis, because 'return' is not side-effect free unless it's the last statement. But that's better handled in the dead code removal module, as the comment specifies.
2015-03-13 23:46:23 +01:00
Sei Lisa
9cb02839bc Remove extra code. 2015-03-13 23:45:56 +01:00
Sei Lisa
f6b472133a Optimize [elem] -> (list)elem on output. Saves us headaches. 2015-03-13 22:42:00 +01:00
Sei Lisa
2948399bf8 Revert 3b7e461d82, as it introduced bugs. 2015-03-13 22:13:00 +01:00
Sei Lisa
f7556e7a66 Remove globals from symbol table when no longer necessary. 2015-03-13 20:11:57 +01:00
Sei Lisa
5ca8e3db3f Expand README.md with optimization explanations and an intro to the features. 2015-03-13 19:01:13 +01:00
Sei Lisa
2e2975ef95 Fix unit tests. 2015-03-13 16:56:32 +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
3d965f13e0 Fix bug with the scope of function calls.
Makes this script work, as it should:

`default { timer() { string llSay; llSay(0, llSay); } }`
2015-03-13 16:43:35 +01:00
Sei Lisa
890e960b57 Implement Lazy List reading. Update docs according to last changes (in FS too).
Adds a new tree node type, SUBIDX, which hopefully should never appear in actual output. If it does, it's prefixed with the string (MISSING TYPE) as a cue to the programmer.
2015-03-13 06:38:35 +01:00
Sei Lisa
535dc8434c Allow a code block instead of a ':' as terminator for 'case' and 'default'.
For Firestorm compatibility.
2015-03-13 05:16:22 +01:00
Sei Lisa
39b6036671 Remove 'Scope' from functions in symbol table. Function scope is always 0. 2015-03-13 05:12:09 +01:00
Sei Lisa
4f8d2979aa Fix typo in EParseFunctionMismatch. 2015-03-13 03:28:51 +01:00
Sei Lisa
4065fa95bb FS's optimizer now sucks a bit less thanks to the author's contributions. 2015-03-11 06:10:41 +01:00
Sei Lisa
63e3021a6d Comment tweaking. 2015-03-09 13:20:37 +01:00
Sei Lisa
9c926b6fec Fix obsolete comment.
There was a time where I decided that the tree would be stored inside the symbol table, as values for the global symbols. I changed my mind later and separated them, but that comment remained.
2015-03-09 01:07:55 +01:00
Sei Lisa
6a0eebf157 Implement a couple subtleties of the lexer in the handling of strings.
First, a string does not have its own context, it's a regular expression, therefore if there isn't a matching closing quote until EOF, it's not an unterminated string. It plainly *isn't* a string.

Second, the string lexer searches for either the regexp '[^"\\]' (any character except a double quote or a backslash) or the regexp '\\.', that is, a backslash followed by an "any character" meta. But the "any character" meta does NOT match a newline. The consequence is that a '\' followed by a newline cancels the matching, and the whole thing is not considered a string.

Isolated double quotes are then plain ignored as many other characters.

An example illustrating both cases:
```
default
{
    state_entry()
    {
        string msg = "Hello, Avatar!";
        llOwnerSay"(msg); // the opening quote will be ignored
        // the following backslash at EOL cancels the previous double quote: \
        llOwnerSay(llGetKey(")); // Unterminated string; unmatched so ignored.
    }
}
```
2015-03-08 16:53:58 +01:00
Sei Lisa
defa9fde97 Typo in help 2015-03-07 22:55:25 +01:00
Sei Lisa
1e8b77bf50 Rather than generating random identifiers for locals, prefix them with 'loc_'.
Should help improving readability of the optimized script.
2015-03-07 14:51:51 +01:00
Sei Lisa
a292846d28 Fix missing scope table index when generating the call to lazy_list_set. 2015-03-07 14:50:25 +01:00