You are browsing as a guest. Sign up (or log in) to start making projects!

1h 16m 56s logged

Made “PromoteToGlobals” which is a more powerful version of OptimizeToGlobals which allows for recursive functions to have their locals turned into globals aswell

This is something called liveness analysis, the compiler looks at the code paths and decides at which points a variable is “live”, which means it can’t get overwritten by a recursive call
Example:

warp int fib(int n) {
    return 0 if n <= 0;
    return 1 if n == 1;
    if (n == 2) {
        int b = n * 2;
        return otherFunc(b);
    }
    return fib(n - 1) + fib(n - 2);
}

In this function the “b” variable can be turned into a global because it cannot get overwritten by a recursive call, its used too early for that to happen

0
3

Comments 0

No comments yet. Be the first!