You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the key features of the Nanopass framework is automating the "boring-parts" of transformation between passes. I think our equivalent could be a generated visitor base class for each pass. By default, it would do a catamorphic transformation on unchanged nodes - that you can still override, if you need -, and would require the user to write the ones that were affected.
abstractclassPass1ToPass2Base{// Generate dispatch functionalitypublic Pass2.Expr Apply(Pass1.Expr expr)=>exprswitch{
Pass1.Expr.Unit e => Apply(e),
Pass1.Expr.IfElse e => Apply(e),
Pass1.Expr.If e => Apply(e),
Pass1.Expr.Name e => Apply(e),
_ =>thrownew InvalidOperationException(),};// Unchanged nodes are just translated trivially// The user can still override them, if neededpublicvirtual Pass2.Expr Apply(Pass1.Expr.Unit e)=>new Pass2.Expr.Unit();publicvirtual Pass2.Expr Apply(Pass1.Expr.IfElse e)=>new Pass2.Expr.IfElse(
Apply(e..Cond),
Apply(e.Then),
Apply(e.Else));// Changed or removed nodes are required to be handled by the userpublicabstract Pass2.Expr Apply(Pass1.Expr.If e);publicabstract Pass2.Expr Apply(Pass1.Expr.Name e);}
One of the key features of the Nanopass framework is automating the "boring-parts" of transformation between passes. I think our equivalent could be a generated visitor base class for each pass. By default, it would do a catamorphic transformation on unchanged nodes - that you can still override, if you need -, and would require the user to write the ones that were affected.
For example, let's say we have this AST:
And then we do the following modifications:
Then the next generated AST would look like:
And the generated visitor base could be:
Then all the user needs to implement is:
The text was updated successfully, but these errors were encountered: