Commit graph

404 commits

Author SHA1 Message Date
Sei Lisa
91ad438bb7 Be a bit smarter when optimizing out default labels.
(Was a TODO item). Also cosmetic changes.
2016-05-08 03:55:55 +02:00
Sei Lisa
3669bbb06e Only add a label and a jump for default and break when necessary.
Well, within reasonable limits.

For break, it's explained in the code. If the block is empty of actual code (code that generates output), then the break position is eliminated.

For default, if the default label is at the top of the block, the jump and the label are both eliminated. This check doesn't include verifying that there are other non-code-generating statements in between, so there's room for improvement (added corresponding TODO item).

This way, we're on par with FS, in case someone (ab)used the FS brokeness when the 'default' label was absent. All one has to do now is add the default label at the top, and the generated code will be the same as it was in FS when abusing that bug, with no extra burden.

Example: In FS, the code at the top acted as default and there was no jump for it:

  default { timer() {
    switch(1)
    {
      0;
     case 1:
      1;
    }
  }}

This generated roughly:
  default { timer() {
    {
      if (1 == 1) jump CASE_1;
      0;
      @CASE_1;
      1;
    }
  }}

In this system, it would trigger an error by default. To obtain the FS behaviour, the scripter can do instead:
  default { timer() {
    switch(1)
    {
     default:
      0;
     case 1:
      1;
    }
  }}

Thanks to this optimization, the code will be the same as in FS. Without it, an extra default label and corresponding jump would be present.
2016-05-07 04:40:37 +02:00
Sei Lisa
b7e6e6f7b1 Fix bug with tab handling.
Commit 5804a9a introduced a bug where having the foldtabs option disabled (normal) prevented optimizations of functions. Fix it for good (hopefully). While on it, rename the nofoldtabs option to warntabs, making it default, and use it to disable a warning when there are tabs in a string.
2016-05-07 03:18:50 +02:00
Sei Lisa
697e80cb16 Rather than reproduce the broken behaviour, throw an error on missing default.
Changed my mind. This looks saner. Now, if the 'default:' label is missing, an error will be thrown by default. It has to be explicitly disabled if normal C-like behaviour is desired (namely to jump to the 'break' label if no condition is met).
2016-05-07 02:38:54 +02:00
Sei Lisa
b1b84a123e Add broken FS switch behaviour for compatibility.
In the absence of a 'default' label within a switch, FS falls through to the first CASE label (or to the code before the first CASE if there's any).

This commit adds an option, active by default for FS compatibility, that mimics this broken behaviour, as well as a warning in case the 'default' label is absent, which also triggers another warning when the option is active.
2016-05-06 20:15:46 +02:00
Sei Lisa
bb198b3745 Add a (currently disabled) viable and tested alternative to c_float for F32. 2016-05-06 20:11:41 +02:00
Sei Lisa
41149a17aa Report a type mismatch in globals in a more meaningful position.
For example, this script reported the type mismatch in default:

key k=0;
default{timer(){}}

Now it's reported at the semicolon, which is as early as it can be identified and much more meaningful.
2016-04-04 13:58:25 +02:00
Sei Lisa
dc98e477d7 Add 'nofoldtabs' option to disable warning when a function generates tabs
When a function folds to a string that contains a tab, e.g. llUnescapeURL("%09"), or to a list that contains a string that contains a tab, a warning is emitted unless the foldtabs option (which forces the optimization) is used. This option allows to quiet the warning without forcing the optimization.
2016-04-01 20:48:33 +02:00
Sei Lisa
5804a9a610 Refine the test for tabs so that it checks strings in lists too. 2016-03-30 21:01:16 +02:00
Sei Lisa
7283842b3a Make an error message more explicit.
Resolving some constant function calls may generate tabs, e.g. llUnescapeURL("%09"). That can't be pasted into a script, and a warning is emitted. The warning text was misleading, making one think that something went wrong when all that happened is that an optimization couldn't be applied. Rewrite the text of the warning to be clearer about what the problem is.
2016-03-30 18:29:11 +02:00
Sei Lisa
b0e5a50a59 Fix discrepancy with LSL in llCSV2List.
In LSL, llCSV2List eats the very first space in the string if there's one. This patch implements that behaviour.
2016-03-25 20:52:48 +01:00
Sei Lisa
14f70c93b4 Fix bug in llCSV2List when there's no space after comma but there's a space in the value.
E.g. llCSV2List(",A B") produced ["", "B"].
2016-03-25 20:44:59 +01:00
Sei Lisa
661853be53 Fix llRot2Axis to negate the axis when s is negative. 2016-01-22 20:54:43 +01:00
Sei Lisa
c555a01a48 It's possible to enter Infinity as a float constant, so do that rather than the (float)"inf" kludge. It remains for NaN though. 2016-01-06 01:21:04 +01:00
Sei Lisa
881a33a427 Remove unnecessary line 2016-01-03 01:30:22 +01: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
ceb442e931 Improve error reporting, by printing the errored line and a caret (^), taking care to display the beginning of the token the error is at. 2016-01-02 03:39:47 +01:00
Sei Lisa
9469855769 Document the internal behaviour of run_time_permissions under LSO 2015-12-11 02:28:51 +01:00
Sei Lisa
91201f1e30 Remove old TODO and add new one.
Identifiers can be equal if they belong to different syntactic scopes. That will allow better reuse and less creation of new identifiers, most notably as function and event parameter names.

The implementation would require a stack of counters where the current value is pushed when entering a new scope, and popped when exiting, rather than using a single counter for the whole program.
2015-12-09 05:11:53 +01:00
Sei Lisa
025f0f8440 str() doesn't return a fully-expanded float. repr() does. 2015-12-09 03:37:01 +01:00
Sei Lisa
6ec2667bf3 Refine comments 2015-09-24 22:02:46 +02:00
Sei Lisa
57cacf29bb Return a float when typecasting returns zero (fixes inconsistent type) 2015-09-22 14:14:26 +02:00
Sei Lisa
aee638e900 Return denormals as 0 in (float)"number". Found by Pedro Oval. 2015-09-21 21:15:48 +02:00
Sei Lisa
2d72b8e198 Fix llList2CSV with -nan in vector and quaternion (with test case). 2015-09-09 18:14:27 +02:00
Sei Lisa
2044f888d4 Fix bug where (typecast)[single_expr] was output as (typecast)(list)single_expr, producing a syntax error in the output for lack of extra parentheses. 2015-09-09 04:14:55 +02:00
Sei Lisa
6b7b366f63 Fix llRot2Euler exception 2015-09-08 03:47:00 +02:00
Sei Lisa
bc4f574b33 Managed to deal with the '-nan' case in llList2CSV. Add test cases. 2015-09-07 02:56:44 +02:00
Sei Lisa
0122d6ed70 On second thought, disable explicitcast for list+nonlist and nonlist+list entirely, as they are not the same as list+(list)nonlist and (list)nonlist+list anyway. 2015-09-05 03:09:46 +02: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
aa74e6ed64 Sadly, Python can't represent -nan, even though llList2CSV can display it. Add a note to that effect. 2015-09-04 05:46:18 +02:00
Sei Lisa
15f1a07a72 There were more translated events. After an exhaustive analysis this is the definitive list. 2015-08-21 03:35:20 +02:00
Sei Lisa
e264260477 Two events produce different internal names than the event name itself. This was causing the reused names for these events to increase memory usage instead of reducing it. Fixed. 2015-08-21 01:20:28 +02:00
Sei Lisa
f8a6d3d86c Reorganize so that warningPass is always set at least once when constfold is set. 2015-08-19 05:41:21 +02:00
Sei Lisa
cd9bfd426e Update list of pre-allocated keywords. 2015-07-26 00:13:00 +02:00
Sei Lisa
1636e56266 The llGetListLength optimization can be applied to arbitrary expressions. 2015-07-13 07:16:32 +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
1160fea8cf Fix extendedtypecast problem with negative constants after typecasts. 2015-06-23 06:54:04 +02:00
Sei Lisa
4cc268b574 Fix parenthesizing of expressions having ~ or ! 2015-06-17 18:30:32 +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
52ebe20a67 Refine a comment 2015-06-17 02:31:58 +02:00
Sei Lisa
e35431cecf Forgot to truncate llSqrt to F32. 2015-06-16 04:41:36 +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
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
aaa8d3b7f4 Fix crash when a global was optimized out and another global depended on it. 2015-06-14 03:36:54 +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
d8629f9200 Update behaviour of llListFindList for LSO. 2015-05-24 04:22:31 +02:00
Sei Lisa
faf296fa74 Fix bug with scripts that have UTF-8 characters.
The parser expects bytes, not unicode.
2015-05-03 05:19:14 +02:00
Sei Lisa
4302ea846d Don't fall through after optimizing a negable comparison, as it's folded already and the variables were incorrectly set and broke our invariants. 2015-04-21 06:11:25 +02:00
Sei Lisa
d58bc2d350 Implement library function parameter optimization.
So far only two kinds: angle in llSensor[Repeat] and null keys in functions that take a key parameter.

Closes two TODOs.
2015-04-21 04:56:09 +02:00
Sei Lisa
17bf0b7a1e Fix recently introduced bug: function renaming failed. 2015-04-17 03:37:24 +02:00