Commit graph

712 commits

Author SHA1 Message Date
Sei Lisa
fab3ce4d24 Add note on removal of comments in help text 2018-12-22 16:02:08 +01:00
Sei Lisa
0855b8ad1d Add 'listto' to fndata.txt; remove more magic names from the code
Rather than using a hardcoded table of list-to-type extraction function, add a 'ListTo' attribute to the function data. No error is raised if more than one function exists to convert to the same type.

This change is of questionable usefulness, but it should soothe those allergic to magic names/numbers. I cringed a bit myself.

While on it, change the syntax error that was raised when the corresponding conversion function did not exist, to a tailor-made error.
2018-12-22 15:44:14 +01:00
Sei Lisa
a052bf499c Reorganize the checks, and eliminate the fn call check
After more thought, we believe that transforming llDumpList2String into a sum of strings is a gain even if there is a list constructor containing function calls as first parameter. The rationale is explained in the comment.
2018-12-22 10:27:37 +01:00
Sei Lisa
0a6155bb13 Apply an associativity rule to strings
It's not general associativity, it just folds CONST + (CONST + expr). Some day we'll implement sum flattening, to make this possible.
2018-12-22 10:27:37 +01:00
Sei Lisa
e2d01e7825 Extend the 1-element optimization of llDumpList2String to non-SEF first arg 2018-12-22 10:27:37 +01:00
Sei Lisa
d4bcafa1f7 Add proper detection of functions inside the list
A recursive function checks every subnode.
2018-12-22 10:27:37 +01:00
Sei Lisa
e5c2c4057e Always cast the separator to string when expanding
If it is a key, it would otherwise cause an error on expansion.
2018-12-22 10:27:37 +01:00
Sei Lisa
1ebd029931 llDumpList2String: Always optimize SEF lists of 1 element 2018-12-22 10:27:37 +01:00
Sei Lisa
64c9c1db8b Optimize llDumpList2String for some non-constant cases
In particular, variables and fields. When we implement an analysis of functions contained in subexpressions, we can optimize more expressions, so add that as a TODO.
2018-12-22 10:27:37 +01:00
Sei Lisa
59df033fe0 Remove spaces inside parentheses in fndata.txt 2018-12-22 10:19:21 +01:00
Sei Lisa
155a35ff8f Upstream version of builtins.txt; update fndata.txt 2018-12-08 19:30:26 +01:00
Sei Lisa
b9fe0b6c85 Add TODO item about side-effect analysis of UDFs 2018-11-19 21:15:52 +01:00
Sei Lisa
18d19b4653 Fix bug where 1 + (2 + function) was folded as 4 + function
After folding, our cached values changed under us. Re-cache them.
2018-11-19 20:43:58 +01:00
Sei Lisa
2740306b6c New upstream version of KWDB
Adds a new function. Some things are pending to check, after we become more acquainted with the new function (see TODO in fndata.txt).
2018-11-09 19:07:48 +01:00
Sei Lisa
1207275a1e Make --prenodef work more sensibly, remove caveat
--prenodef was causing the preprocessor-specific options (like -std=c99 for gcpp or -V199901L for mcpp) to be omitted. That makes no sense; '-p ext' should be used when custom options are desired (also modify the text that mentions it to make that clearer). Only the macros should be omitted.

The comment that warned about side effects with the order of --prenodef with respect to -p no longer applies, so remove it.
2018-10-15 21:18:15 +02:00
Sei Lisa
73599e0b04 More 32-bit negation-related overflow hazards patched.
Per bug report by Tonaie Resident.
2018-07-26 02:31:51 +02:00
Sei Lisa
960cbfaa09 Fix "Value of unknown type" on bit shift optimization
When converting x << constant to a product, we neglected to truncate the converted constant to S32.

Per bug report by Tonaie Resident.
2018-07-25 15:59:04 +02:00
Sei Lisa
21cecc46f8 Add new Animesh functions 2018-06-26 03:16:05 +02:00
Sei Lisa
6502a1a0b6 Remove TODO because there was nothing to do after checking. 2018-06-08 00:14:16 +02:00
Sei Lisa
e88e39127b Save a comparison (fixes a FIXME) 2018-06-08 00:07:36 +02:00
Sei Lisa
0808938894 Optimizations based on addition algebra for floats and integers
Float addition is commutative. Swap the constant to the left side if it's not there. This is a "cheap" version of a bigger change that is planned, to minimize stack usage as much as possible on savepoints.

Float addition is not associative, therefore we don't optimize e.g. 1 + (2 + float).

Integer addition is commutative and associative. If there's a constant, we swap it to the left side. If there's a chained summation of the form const + (const + expression), we apply associativity to turn it into (const + const) + expression and reoptimize.

This doesn't cover all possible cases. Expressions of the form (const + expr) + (const + expr) are not optimized. We need to flatten sums if we want to do the right thing here, but that's not yet implemented.

Get rid of some older code and TODOs that are no longer needed.
2018-06-07 23:57:21 +02:00
Sei Lisa
ac254efb77 Minor details
Assert that it can't be key where we say it can't, and that it is integer where we say it must.

Adjust some comments.
2018-06-07 02:14:15 +02:00
Sei Lisa
a33dc8540f Implement ~-~-~-expr -> expr + -3
Gets rid of a TODO
2018-06-07 02:14:15 +02:00
Sei Lisa
464797020a Remove commented-out print_node function (superseded by nr.__str__) 2018-06-07 02:14:15 +02:00
Sei Lisa
fa73348dc6 Fix test case that was broken since 2b14acc 2018-06-07 02:14:15 +02:00
Sei Lisa
33fc38e42d Fix bug with key variable in list within globals
Mark the expression as simple also when ExtendedGlobalExpr is not set.
2018-05-17 19:05:00 +02:00
Sei Lisa
89c627b0c0 Remove jumps that just go to the next statement
This might help a bit with switch().
2018-05-17 09:46:06 +02: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
a93ea0ca19 Delete statements in a {} block when they are SEF
This is probably equivalent to what we did, as FoldStmt changes SEF statements to ';' statements, but it's simpler.
2018-05-17 09:08:35 +02:00
Sei Lisa
caf50c4e14 Change while (cond) /*empty*/; into do /*empty*/; while (cond); 2018-05-17 06:38:33 +02:00
Sei Lisa
8f93386108 Get rid of label checks in some situations no longer supported 2018-05-17 06:38:12 +02:00
Sei Lisa
1d7142a698 Add --bom command-line option to prefix the script with a BOM 2018-05-11 22:37:09 +02:00
Sei Lisa
c3be2bd216 New functions llName2Key() and llRequestUserKey() 2018-05-09 19:06:25 +02:00
Sei Lisa
c62773ad3f Refine the denormal check for Mono
The threshold for returning 0 for denormals is slightly different.
2018-05-09 19:04:09 +02:00
Sei Lisa
091f06cccc Fix threshold value for denormal to be taken as 0
(float)"1.1754944e-38" is != 0
(float)"1.1754943e-38" is == 0

Yet, 1.1754944e-38 == 1.1754943e-38.

The fix is to perform the operations as doubles, and convert to F32 *after* comparing the denormal range.
2018-04-27 23:44:27 +02:00
Sei Lisa
1afe1643c0 Allow lists to contain void elements if not optimizing and not lazy
LSO allows this. The compiler does too, but it chokes in RAIL.

This affected a test, which has been adjusted too.

Untyped lazy list elements can no longer be used in isolation in expression lists (including FOR initializator and iterator).

Also rename the terribly named 'self.forbidlabels' to 'self.optenabled' which is more descriptive.
2018-04-09 18:49:47 +02:00
Sei Lisa
4a554d60e8 Remove a TODO item that was already done 2018-04-02 13:42:28 +02:00
Sei Lisa
6ef4c03994 Remove support for labels as immediate children of IF/ELSE/WHILE/FOR/DO.
This extremely uncommon coding pattern was becoming a hell to support. It has caused many bugs in past that need them being treated as special cases.

Getting rid of the possibility entirely seems like the best approach.

It's still supported if the code is not to be optimized (e.g. with --pretty).
2018-04-01 20:05:35 +02:00
Sei Lisa
27698a92ef Remove TODO from fndata.txt 2018-04-01 19:07:53 +02:00
Sei Lisa
4ebd84f0ed Raise EParseSyntax on wrong minus sign (not followed by int or float)
While not strictly a bug because it would be caught later in the function (it passes the tests either way), it made me nervous to leave a dangling NextToken().
2018-04-01 02:14:53 +02:00
Sei Lisa
dc30d461e2 Format some docstrings better; make one more precise about the grammar 2018-04-01 02:14:53 +02:00
Sei Lisa
8d0b995f07 Accept library function names as vars in simple_expr in globals
This may cause more trouble than it's worth, but it's how LSL behaves and one of our objectives is to document the darker corners of LSL. Mono chokes at the RAIL postprocessing stage, not in compilation proper. LSO chokes at runtime for string, key and list, and works fine for the other types.
2018-04-01 02:14:53 +02:00
Sei Lisa
8289c14c81 Fix bug where types of expressions in vectors/rotations were not checked
E.g. this was a valid vector literal: <"",0,0>

Parse_simple_expr didn't have that problem, though.
2018-04-01 02:14:53 +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
d890f0b5fa Comment-at-eol cleanup
Ensure every comment has a double space after the code.
2018-03-27 13:29:04 +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
877d5fc10c Optimize -a == -b, !(a - b), !(a + b)
-a == -b  ->  a == b

If both a and b either are constants or have a minus sign, negate both.

!(a - b) can be optimized to a == b.

!(a + b) can be optimized to -a == b, relying on the first optimization to remove redundant minus signs.
2018-03-23 19:02:42 +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
a1f1f13739 Better optimization of (non-)equality comparisons.
int != int was not properly optimized, because the != was transformed into the equivalent !(int == int) at an earlier stage. Fixed.

!(a ^ b) can be optimized to a == b, so do it.
2018-03-23 16:04:18 +01:00