Open tomoyanonymous opened 1 month ago
In the current implementation, popstate
is inserted at the end of the function with the sum of the statesize within the function, but is should be inserted right after the non-closure function call. Or, maybe new instruction like callstatefulfn address [arguments] statesize
should be introduced at the MIR level and push/popstate instruction should be removed.
Hmm, I'm thinking a bit more subtle cases like this.
fn dsp(){
if (random()){
gen_a()
}else{
gen_b()
}
}
gen_a
and gen_b
are stateful functions which have a different state size, 4 and 5 respectively for instance.
The state size of the dsp function should be 9 and shiftstate(4) should be inserted at the beginning of else block.
Also, it maybe problematic because only one side of branches are evaluated and then samplerate becomes inconsistent...
Continued from #63 .
I found the reason for the bug of the segfault. Function that calls stateful function only on the one side of the if-else branch generate bytecodes that may shift different amount of state position depending on the branch path.
The function
bar
is compiled tolike this.
If the condition was true,
pushstate(1)
andpopstate(1)
will be called but onlypopstate(1)
is called when the condition was false.