dbaumgarten / yodk

Development Kit for Starbase's ingame programming language YOLOL
MIT License
57 stars 16 forks source link

Optimiser Fix/Improvement for goto #47

Open Woccz opened 3 years ago

Woccz commented 3 years ago

Given the following code:

a> goto b

b> x = 5
goto a

in NOLOL, it compiles to:

goto2
b=5 goto2

There is no need for a goto pointing to the next line.

I suggest during optimisation to search and remove all gotos that point to the next line.

Thank you.

dbaumgarten commented 3 years ago

Does this happen "by accident" during compilation, or does the programmer need to deliberatly place a goto ?

Woccz commented 3 years ago

The compiled code has not been changed. What is your question exactly?

dbaumgarten commented 3 years ago

I just wondered if the compiler would generate such inefficient code when using if and while blocks, or if this only happens if the user is doing it himself.

At least for label-gotos this should be relatively simple to detect and remove. There is already code to remove useless gotos, which could just be extended to handle this.

Woccz commented 3 years ago

Well it's smart enough to replace the goto a > goto b with just a goto b, just missed the goto next line(after empty lines removed).