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

Pop switch expression correctly #613

Merged
merged 1 commit into from
May 30, 2023

Conversation

RevengerWizard
Copy link
Contributor

@RevengerWizard RevengerWizard commented May 19, 2023

This PR fixes a small behaviour bug with the switch statement. Prior to this, the switch expression was never popped out of stack at the end of the case statements, polluting the stack and leading to problems.

Type of change:

  • Bug fix

@Jason2605
Copy link
Member

Thanks for this! Could you possibly provide a snippet that caused this bug? We can then try to form a test around it

@RevengerWizard
Copy link
Contributor Author

RevengerWizard commented May 25, 2023

I think this could be more noticeable when there is a switch statement inside a loop and taking a look at the traced instructions.
Here a basic example:

for(var i = 1; i <= 3; i += 1)
{
    switch(i) 
    {
        case 1:
        {
            print("One");
        }
        case 2:
        {
            print("Two");
        }
        case 3:
        {
            print("Three");
        }
    }
    print("Other");
}

With a longer and intense loop it could be noticed better, but after all the compare jumps you should see the switch expression left up on the stack.

@Jason2605
Copy link
Member

Perfect, thanks for this!

@Jason2605 Jason2605 merged commit 863d831 into dictu-lang:develop May 30, 2023
@Jason2605 Jason2605 mentioned this pull request Aug 16, 2023
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 this pull request may close these issues.

2 participants