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

Add Labels and Goto #58

Open
NeeEoo opened this issue Apr 6, 2021 · 2 comments
Open

Add Labels and Goto #58

NeeEoo opened this issue Apr 6, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@NeeEoo
Copy link
Contributor

NeeEoo commented Apr 6, 2021

This is a thing that would probably not be implemented for a long time, due to it's completely.

Here is an example:

void main() {
    int x = 5;
    int y = 7;

    if(x>y) {
        goto invalid;
    }

    for(int a = 0; a < 10; a++) {
        if(a*y+x > 128) goto invalid;
        if(a*y+x < 3) goto invalid;
    }

invalid:
    print("Invalid Value");
    while(1){};
}
@elikaski
Copy link
Owner

elikaski commented Apr 7, 2021

This seems very difficult to implement. Do you have any idea how to do it? Because it's hard for me to think of one
Note: while implementing this, should also implement "return" statement, to actually affect the flow.

@NeeEoo
Copy link
Contributor Author

NeeEoo commented Apr 7, 2021

I made this issue as a long term thing. I can only think of one thing, and that is to convert a lot of code into if(!__COMPILER__should_goto_invalid) {}

I actually forgot to add goto valid; and valid: in the code, without them it will always print Invalid Value
Here is a way the converted code could be:

void main() {
    int x = 5;
    int y = 7;

    bool __COMPILER__should_goto_invalid = false;
    bool __COMPILER__should_goto_valid = false;

    if(x>y) {
        __COMPILER__should_goto_invalid = true
    }

    if(!__COMPILER__should_goto_invalid) {
        for(int a = 0; a < 10; a++) {
            if(a*y+x > 128) __COMPILER__should_goto_invalid = true;
            if(!__COMPILER__should_goto_invalid) {
                if(a*y+x < 3) __COMPILER__should_goto_invalid = true;
            }

            // internal condition code

            if(__COMPILER__should_goto_invalid) {
                condition = false;
            }
        }
    }
    
    if(!__COMPILER__should_goto_invalid) {
        __COMPILER__should_goto_valid = true;
    }
    
    if(!__COMPILER__should_goto_valid) {
        if(__COMPILER__should_goto_invalid) {
            print("Invalid Value");
            while(1){};
        }
    }
}

But i don't think that this will work for more labels and other statements.


I believe that in the future we might come up with a way to accomplish this.

@elikaski elikaski added the enhancement New feature or request label Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants