assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

[Refactor] Refactor Flow to use save & restore pattern for handling flow switching

Open MaxGraey opened this issue 3 years ago • 5 comments

See original proposal in this comment But instead lock / unlock perhaps better to use save / restore names

// save prev flow
const currFlow = this.currentFlow;

currFlow.save();
// Fork and implicitly set this.currentFlow to this fork
var trueBranchFlow = currFlow.toBranch(prevFlow, condExpr, ConditionKind.True);

// do some work with `someFlow`

currFlow.restore(); // release trueBranchFlow's locals and restore previous flow

MaxGraey avatar Sep 05 '22 16:09 MaxGraey

But for some complex cases such as doCompileWhileStatement, there are lots of flow. How can we know which flow should be restore and restore what?

HerrCai0907 avatar Sep 06 '22 01:09 HerrCai0907

Good point. Need to think more. Perhaps save can accept optional argument. Or we can use stack-based approach for save / restore

MaxGraey avatar Sep 06 '22 04:09 MaxGraey

Or we can use stack-based approach

Indeed, some sort of push/pop for flows seems fitting. Other than that, I am a little skeptical because it restricts what we can do, so we should be reasonably sure that more complicated flow ordering won't be necessary.

dcodeIO avatar Sep 06 '22 06:09 dcodeIO

I am a little skeptical because it restricts what we can do, so we should be reasonably sure that more complicated flow ordering won't be necessary.

I think a tree may be suitable for it. Fork some children from parent flow and then go back to the parent

HerrCai0907 avatar Sep 06 '22 07:09 HerrCai0907

Flow is pretty linear stuff. It can go into deep inner scope, but I don't think we need tree or DAG for handling this

MaxGraey avatar Sep 06 '22 10:09 MaxGraey