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

Make the compiler smarter with variables #39

Open
NeeEoo opened this issue Mar 9, 2021 · 0 comments
Open

Make the compiler smarter with variables #39

NeeEoo opened this issue Mar 9, 2021 · 0 comments

Comments

@NeeEoo
Copy link
Contributor

NeeEoo commented Mar 9, 2021

The code below takes 276 bytes.

int main() {
    int a = 54;
    int b = 4;

    while(b != 0) {
        a++;
        b--;
    }
}

bf code for a and b init:

>>>[-]>[-]++++++[-<+++++++++>]<><>[-]<<<[-]>>[>+<<<+>>-]>[<+>-]<><[-]++++><>[-]<<[-]>[>+<<+>-]>[<+>-]

The code below takes 548 bytes.

int main() {
    int a = 54;
    int b = 4;

    while(b != 0) {
        a++;
        b--;
    }

    int c;
    int d;
    int e;
    int f;
    int g;
    int h;
    int i;
    int j;
}

bf code for a and b init:

>>>>>>>>>>>[-]>[-]++++++[-<+++++++++>]<><>[-]<<<<<<<<<<<[-]>>>>>>>>>>[>+<<<<<<<<<<<+>>>>>>>>>>-]>[<+>-]<><[-]++++><>[-]<<<<<<<<<<[-]>>>>>>>>>[>+<<<<<<<<<<+>>>>>>>>>-]>[<+>-]

Currently, the compiler allocates every variable present in the scope.
Which means if you only use a small quantity of variables in the beginning and more later it will take up a lot more code size.

What I was thinking is that what if the compiler allocated enough and then when more variables appears it shifts the temp variables to the right 
So then when a is declared only that is allocated. Every other variable technically exists in temp until it's declared.

This might also fix #35 since we could check if it is already declared.

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

No branches or pull requests

1 participant