ammarbinfaisal / sahl

a programming language with channels and coroutines/threads
MIT License
10 stars 1 forks source link

patch calls and jumps after codegen #1

Closed ammarbinfaisal closed 1 year ago

ammarbinfaisal commented 1 year ago

like I am doing in bytecode generation for c vm, the calls and jumps should be patched after the entire codegen when we know the place of each function in the instruction vector.

ammarbinfaisal commented 1 year ago

example of a program which wouldn't work because the current way is faulty

fun f(n: int) -> int {
    return fib(10)
}

fun fib(n: int) -> int {
    if n < 2 {
        return n
    }
    return fib(n - 1) + fib(n - 2)
}

fun main() {
    print(f(10))
}