Commit graph

48 commits

Author SHA1 Message Date
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
a87022b73f Get rid of StSw craziness and use lsllastpass to make another pass.
This has been a TODO item for long. Now that we have lsllastpass, it's actually easy to implement.

Adds an LSLTypeDefaults dictionary to lslcommon, just in case the state-changing function returns a value and we need to insert a return statement.

We've also added subtree-local info to lsllastpass (lost when we return to the parent after visiting a subtree).

This fixes a bug where naked switch statements could appear as a result of optimization, and cause the compilation to fail.
2017-11-02 18:20:14 +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
3f6f8ed8ad Internal code reorganization.
- Separate library loading code into a new module. parser.__init__() no longer loads the library; it accepts (but does not depend on) a library as a parameter.
- Add an optional library argument to parse(). It's no longer mandatory to create a new parser for switching to a different builtins or seftable file.
- Move warning() and types from lslparse to lslcommon.
- Add .copy() to uses of base_keywords, to not rely on it being a frozen set.
- Adjust the test suite.
2017-10-20 18:19:48 +02:00
Sei Lisa
c544b51e37 Rewrite ReportError() and change EParse to report columns in chars.
ReportError() needed to account for terminal encodings that don't support the characters being printed. It was also reporting an inaccurate column number and its corresponding marker position, because the count was in bytes, not in characters, so that has been fixed.

Now EParse.__init__() calls a new function GetErrLineCol() that calculates the line and column corresponding to an error position.

The algorithm for finding the start of the line has also been changed in both ReportError() and EParse.__init__(); as a result, function fieldpos() has been removed.

The exception's lno and cno fields have been changed to be 1-based, rather than 0-based.

Thanks to @Jomik for the report. Fixes #5.
2017-10-05 18:50:45 +02:00
Sei Lisa
fe574bb462 Bump copyright year.
'bout time.
2017-08-09 19:45:46 +02:00
Sei Lisa
44dd088154 Fix expected exception in test case.
Changed in commit c71b0ee but not updated in test program.
2017-02-12 04:45:44 +01:00
Sei Lisa
8358fd5012 Fix a test case in testparser.py.
Commit 13f3c95 was clearly a step in the right direction. We had a test case that mistakenly relied on the broken behaviour that that commit fixed, for the constant values to remain in the output. That is clearly wrong, so we fix the test case to not rely on that.
2017-01-28 03:13:44 +01:00
Sei Lisa
f222289673 Fix crash on non-computable function.
When we reduced the scope of the try block in commit a823158, we introduced a bug because the tree modification was attempted even if no value was assigned (when the exception was triggered). Returning when the function is not computable ensures that this won't happen.

Scaringly, there was no check that caught this.
2016-12-25 00:56:50 +01:00
Sei Lisa
6879037735 Fix type conversion on calling LSL functions.
We had a big chaos with type conversion. That caused a bug where passing a key to a function that required a string, or vice versa, crashed the script.

Diminish the chaos by modifying the parameters just prior to invocation (in lslfoldconst). We also remove the, now unnecessary, calls to force floats, either alone or within vectors or quaternions.
2016-12-21 06:01:03 +01:00
Sei Lisa
37483a72cb Fix void expressions in FOR loops.
As an enhancement over LSL, we trigger a Type Mismatch when there are void expressions in list constructors, because in LSL, while accepted, they trigger an ugly runtime exception.

This works fine, but then expression lists, where this are checked, are not exclusive of list constructor; they are used in other places. One of these places is the initializer and the iterator of FOR loops. As a consequence, we didn't allow void functions in the FOR initializer or iterator.

Fix by adding another possible value to the parameter 'expected_types' in Parse_expression_list. False means don't allow void either (what Null did before); Null now means allow anything. All callers to Parse_expression_list are changed accordingly. Added corresponding regression test.
2016-07-10 01:29:11 +02:00
Sei Lisa
e60457f00e Fix rare bug with breakcont and label scope.
This caused "Label not defined within scope" when breakcont was active:
  default{timer(){jump x;while(0)@x;}}
The problem was that breakcont opens a new scope for the case where it has to deal with a loop which is the single statement of an outer statement, e.g.
  default{timer(){if(1)while(1)break;}}
would add braces to jump to the correct break point:
  default{timer(){if(1){while(1)jump brk;@brk;}}
To avoid excessive complication, a new scope was always opened for the whole statement in each of the loops, regardless of whether we needed braces later on or not. That should be transparent most of the time, but then if the statement was a label declaration, the label would be in a new scope that would be invisible outside the loop.

Fix that by checking explicitly for a label to temporarily get rid of the new scope in that case, and add a test case for it.
2016-07-09 23:41:27 +02:00
Sei Lisa
30a07db4fb Mark a couple bugs found to not lose track, and add a regression test. 2016-06-28 03:47:48 +02:00
Sei Lisa
0c3ad9b938 Change skippreproc -> processpre, add #pragma option processing.
Usage:

Options are case insensitive.
2016-06-28 03:20:21 +02:00
Sei Lisa
79dff25769 Update copyright years of some files; add legalese to seftable.txt 2016-06-27 20:06:41 +02:00
Sei Lisa
cfb9dee941 Parse_unary_postfix_expression shouldn't accept the token (i.e. advance to the next) if it's not processed. This caused a mismatch between the reported syntax error and the position where it should have been detected. Fixed.
Added corresponding regression test.
2016-01-03 01:29:57 +01:00
Sei Lisa
d8649deebd nonlist + list was returning the type of the nonlist element. Fixed and added a
regression test.

Funnily enough, it was correct if explicit cast was active. Removed from explicit cast now that it's active for all.
2015-09-04 05:56:05 +02:00
Sei Lisa
1a67db64dc Get rid of builtins.txt.dat by adding a parameter to the parser ctor. 2015-07-09 20:35:14 +02:00
Sei Lisa
f5d150f7c9 Fix typo in IsBool and add coverage test. Report and fix by Code Violet. 2015-06-17 02:51:46 +02:00
Sei Lisa
bfabcd16db Fix parser bug where list = anytype was accepted. Fix also the test suite. 2015-06-16 04:16:59 +02:00
Sei Lisa
2e2975ef95 Fix unit tests. 2015-03-13 16:56:32 +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
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
f3301b07c6 Fix test case. 2014-08-13 13:35:19 +02:00
Sei Lisa
72b4b08cbe Add dead code elimination module. 2014-08-10 02:07:00 +02:00
Sei Lisa
7a4a6d221e Fix field assignment. Add regression test. 2014-08-08 00:52:23 +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
58e22f77ce Prepare for the incoming Dead Code Removal module. 2014-08-05 15:47:14 +02:00
Sei Lisa
67f3061e19 Fix state switch error reporting bug. Add 'Not all code paths...' error.
Add corresponding tests too. Simplify the identifier renaming coverage test. Also remove extra newlines from library reading code.

We've had to give up on the 'else if' loop-instead-of-recurse optimization, to properly propagate the LastWasReturn flag.
2014-08-03 04:50:18 +02:00
Sei Lisa
400809671e Fix GetNextShortest. Add test and regression cases. Rename AssignNewNames. 2014-08-01 18:02:55 +02:00
Sei Lisa
e29f16d3eb Add duplabels option (not yet implemented).
When disabled, it now disallows duplicate labels. The plan is that when enabled, it will auto-rename labels so that there are no repetitions within a function.

Add coverage tests too, and also a coverage test that was missed after the latest changes.
2014-08-01 00:33:20 +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
66417276ae Test cases for the previous commit 2014-07-31 03:31:42 +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
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
3b4bf13a10 Add coverage for new stuff. 2014-07-28 21:19:23 +02:00
Sei Lisa
56d51b835c Hack to make identifiers in globals in non-global-expression mode work. 2014-07-28 19:20:36 +02:00
Sei Lisa
6c00400d7d Add coverage for new preprocessor option. 2014-07-28 02:45:30 +02:00
Sei Lisa
ae94e80c34 Add a regression test for a case that failed before the globals fix. 2014-07-28 01:01:10 +02:00
Sei Lisa
1747028211 Finish coverage tests. 2014-07-27 20:26:24 +02:00
Sei Lisa
19ca34d7e0 Expand the test case to include more coverage. Triggers errors. 2014-07-27 20:13:12 +02:00
Sei Lisa
716374eb83 Add test cases that failed without the previous commit. 2014-07-27 18:08:18 +02:00
Sei Lisa
f5444bb83d Update coverage tests. Add optimizer test. Rename classes (cosmetic). 2014-07-27 13:52:55 +02:00
Sei Lisa
0959be94bc Add extra coverage case, as we were missing a few lines.
The option extendedglobalexpr shaded string juxtaposition in globals.
2014-07-26 04:51:35 +02:00
Sei Lisa
e03b342f78 Allow concatenation of key+string and string+key producing string.
Also add corresponding test cases, making some mostly cosmetic changes to the test program while on it.
2014-07-26 04:41:09 +02:00
Sei Lisa
0b6ff4646e Add coverage tests for allowmultistrings, and reorder for coverage of the test program itself. 2014-07-26 03:57:02 +02:00
Sei Lisa
4ee320ace1 Add the unit testing files.
testfuncs.py uses custom testing functions.
testparser.py uses the unittest standard module.
2014-07-26 03:18:02 +02:00