Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring: Extract operation parameters #364

Open
dvdvgt opened this issue Jan 19, 2024 · 1 comment
Open

Refactoring: Extract operation parameters #364

dvdvgt opened this issue Jan 19, 2024 · 1 comment

Comments

@dvdvgt
Copy link
Collaborator

dvdvgt commented Jan 19, 2024

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])
@b-studios
Copy link
Collaborator

b-studios commented Jan 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants