effekt icon indicating copy to clipboard operation
effekt copied to clipboard

Refactoring: Extract operation parameters

Open dvdvgt opened this issue 1 year ago • 2 comments

With the addition of block parameters to operations with #361, it might be worthwhile to extract the operation parameters into its own class for better readability:

case BlockLiteral(tparams: List[Id], vparams: List[ValueParam], bparams: List[BlockParam], body: Stmt)
...
case class Operation(id: IdDef, tparams: List[Id], vparams: List[ValueParam], bparams: List[BlockParam], ret: Effectful) extends Definition
...
case class OpClause(id: IdRef,  tparams: List[Id], vparams: List[ValueParam], bparams: List[BlockParam], ret: Option[Effectful], body: Stmt, resume: IdDef) extends Reference
...
case FunDef(id: IdDef, tparams: List[Id], vparams: List[ValueParam], bparams: List[BlockParam], ret: Option[Effectful], body: Stmt)
...
case ExternDef(capture: CaptureSet, id: IdDef, tparams: List[Id], vparams: List[ValueParam], bparams: List[BlockParam], ret: Effectful, body: Template[Term]) extends Def

to

case BlockLiteral(params: Params, body: Stmt)
...
case class Operation(id: IdDef, params: Params, ret: Effectful) extends Definition
...
case class OpClause(id: IdRef,  params: Params, ret: Option[Effectful], body: Stmt, resume: IdDef) extends Reference
...
case FunDef(id: IdDef, params: Params, ret: Option[Effectful], body: Stmt)
...
case ExternDef(capture: CaptureSet, id: IdDef, params: Params, ret: Effectful, body: Template[Term]) extends Def
...
case class Params(tparams: List[Id], vparams: List[ValueParam], bparams: List[BlockParam])

dvdvgt avatar Jan 19 '24 10:01 dvdvgt

Note that this probably could be done in the various stages source, symbols, core, lifted, etc.

Just another advice on the style in the compiler

When processing programs, typically, for each nonterminal in the grammar (that is type in the ADT that describes the tree) we write a corresponding function.

For example in Namer, we would add a function

def resolve(p: Params): ...

and then call it whenever we process an Operation, BlockLiteral, etc.

b-studios avatar Jan 19 '24 11:01 b-studios