effekt-lang / effekt

A language with lexical effect handlers and lightweight effect polymorphism

Home Page:https://effekt-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Refactoring: Extract operation parameters

dvdvgt opened this issue · 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])

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.