LSL-PyOptimizer/lslopt
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
..
__init__.py Initial commit. Status so far: 2014-07-26 02:43:44 +02:00
lslbasefuncs.py Add a (currently disabled) viable and tested alternative to c_float for F32. 2016-05-06 20:11:41 +02:00
lslcommon.py Reorganize main to use getopt. Implement -o for output file and -O help. 2015-03-14 23:17:15 +01:00
lsldeadcode.py 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
lslextrafuncs.py Add copyright notices to all files, to prepare the program for release. 2015-03-05 23:18:41 +01:00
lslfoldconst.py Fix bug with tab handling. 2016-05-07 03:18:50 +02:00
lslfuncparams.py Implement library function parameter optimization. 2015-04-21 04:56:09 +02:00
lslfuncs.py Add copyright notices to all files, to prepare the program for release. 2015-03-05 23:18:41 +01:00
lsljson.py Add copyright notices to all files, to prepare the program for release. 2015-03-05 23:18:41 +01:00
lsloptimizer.py Fix bug with tab handling. 2016-05-07 03:18:50 +02:00
lsloutput.py Fix bug with tab handling. 2016-05-07 03:18:50 +02:00
lslparse.py Only add a label and a jump for default and break when necessary. 2016-05-07 04:40:37 +02:00
lslrenamer.py Document the internal behaviour of run_time_permissions under LSO 2015-12-11 02:28:51 +01:00