nielsAD / lape

Scripting engine with Pascal-like syntax for FPC and Delphi
118 stars 28 forks source link

Improve TLapeTree_Case #163

Closed ollydev closed 3 years ago

ollydev commented 3 years ago

Some ridiculous issue was happening when a case branch had a lot of values.

  case 123 of
    3, 7, 10, 18, 21, 24, 27, 31, 32, 34, 35, 41, 43, 45, 46, 48, 49, 51, 54, 56, 58, 59, 61, 62: ;
  end;
Succesfully compiled in 547 milliseconds.  // Above
Succesfully compiled in 1078 milliseconds. // Above with one value added
Succesfully compiled in 2157 milliseconds. // Above with two values added

No idea what causes this exponential growth. A large operator tree does get generated, but still makes no sense. https://pastebin.com/D2zDnP2T

I "fixed" this by changing how case statements are generated. Rather than if else statements it's more of a goto style.

if (cond = value_0) then
  goto statement;
if (cond = value_1) then
  goto statement;

It's now slightly more efficient and less code is generated.


Also ContinueCase compiler option has been removed. Fallthrough keyword has been added. See tests/System_Fallthrough.lap for usage.

slackydev commented 3 years ago

Nice find