Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Useless jumps with nested if #227

Open
hsaturn opened this issue Mar 13, 2024 · 1 comment · May be fixed by #222
Open

Useless jumps with nested if #227

hsaturn opened this issue Mar 13, 2024 · 1 comment · May be fixed by #222

Comments

@hsaturn
Copy link

hsaturn commented Mar 13, 2024

Hello

Some useless jumps are generated with nested if.
Here is the smallest code I've found, but with large code, I saw a bunch of 7 useless jumps !!

var c;
if (c < 10) {
    if (c < 5)
        c = 5;
    else
        c = 10;
}
else
    c = 23;

The generated code is

0 jump 6 greaterThanEq c:1:4 10
1 jump 4 greaterThanEq c:1:4 5
2 set c:1:4 5
3 jump 5 always  --> JUMP TO 5
4 set c:1:4 10
5 jump 7 always --> THEN JUMP TO 7 !
6 set c:1:4 23
7 end

As we can see, the jump at line 3 goes to line 5 wich jumps then to line 7.
I think this is easy to add a pass to optimize this, without having to remove a line (which could cause some issue with indirect jumps such as those made with @counter (arrays etc..))

Best regards, MLogJs is so great !

@JeanJPNM JeanJPNM linked a pull request Mar 14, 2024 that will close this issue
@JeanJPNM
Copy link
Collaborator

Hi, thanks for filing an issue. This problem will be fixed by #222.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants