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

Switch case impl (Generalized goto style flow control support) #93

Open
mattbierner opened this issue Sep 5, 2013 · 0 comments
Open

Comments

@mattbierner
Copy link
Owner

The current switch impl works but does a lot of ugly array stuff and duplicates computations in order to support fallthroughs.

A better solution would be to add support for generic goto style flow control and then use these to support switch case. Each case maps to a specific chunk of code only accessible in the switch block. These are then chained together. Writing this explicitly:

switch (x) {
case 0: // Section 0;
    ++x;
    goto section 1;

default:
case 1: // Section 1:
    return 3;
    goto section 2;

case 2: // Section 2;
    x = 444;
    break;
    goto section 3;

case 3: // Section 3
    x += 10;
    goto section 4;

// Section 4
   ;// Empty statement

}

Implicit goto commands are inserted as the last element of the switch case body. In cases with non normal flow control, these are not reached. Otherwise, they handle the chaining of blocks of code together to support fallthrough.

An empty last noop block is also included to support fallthrough in the last case using the same logic.

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

No branches or pull requests

1 participant