Handling the function stack
I'm currently implementing function calls (iterating inside of functions called from main or from other functions).
And I just realized that I might need a variable-sized function stack, even with no recursive calls.
Example:
package main
import "fmt"
func fibonacci(n int) int {
j0 := 0
j1 := 1
for ; n > 0; n-- {
j1, j0 = j1+j0, j1
}
return j0
}
func main() {
i := fibonacci(10)
j := fibonacci(20)
fmt.Println(i, j)
}
Here, once fibonacci at main:0
completes, it will store its result into the state (G2PState
). However, it also needs to indicate that on the next call to get_successors
, it should return to main:1
. The same goes for fibonacci at main:1
-> main:2
.
I see two alternatives to implementing a stack for now:
- Inlining functions.
- For each function, adding two items to the state:
PrevFunctionId
andPrevNodeId
(in the example, that could bemain
and0
). This is much simpler than inlining.
I'm going to go with the second option for now.
@renault WDYT?