Skip to content

Commit

Permalink
Generalize TermDef for multiple parameter lists
Browse files Browse the repository at this point in the history
The member `params` is renamed to `paramLists` to reflect its new behavior. The type of `paramLists` is changed from `Opt[Ls[Tree]]` to `Ls[Tup]` to reflect its new behavior. It now returns a list of parameter tuples instead of a list of parameters.
  • Loading branch information
FlandiaYingman committed Oct 30, 2024
1 parent 18499fc commit 883abd9
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions hkmc2/shared/src/main/scala/hkmc2/syntax/Tree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,31 +204,33 @@ private def getName(t: Tree, symNme: Opt[Tree]): (Opt[Tree], Diagnostic \/ Ident

trait TermDefImpl:
this: TermDef =>
lazy val (symName, name, params, typeParams, signature): (Opt[Tree], Diagnostic \/ Ident, Opt[Ls[Tree]], Opt[Tree], Opt[Tree]) =
def rec(t: Tree, symName: Opt[Tree]):
(Opt[Tree], Diagnostic \/ Ident, Opt[Ls[Tree]], Opt[Tree], Opt[Tree]) =
t match
case InfixApp(id: Ident, Keyword.`:`, sign) =>
(symName, R(id), N, N, S(sign))
// show(t: Tree): Str
case InfixApp(App(id: Ident, args), Keyword.`:`, ret) =>
(symName, R(id), S(args :: Nil), N, N)
// show[A](t: Tree[A]): Str
case InfixApp(App(App(id: Ident, typeParams: TyTup), args), Keyword.`:`, ret) =>
// val sign = S(InfixApp(typeParams, Keyword.`->`, InfixApp(args, Keyword.`->`, ret)))
(symName, R(id), S(args :: Nil), S(typeParams), N)
lazy val (symName, name, paramLists, typeParams, signature): (Opt[Tree], Diagnostic \/ Ident, Ls[Tup], Opt[Tree], Opt[Tree]) =
def rec(t: Tree, symName: Opt[Tree]): (Opt[Tree], Diagnostic \/ Ident, Ls[Tup], Opt[Tree], Opt[Tree]) = t match
// fun f: Int
// fun f(n1: Int): Int
// fun f(n1: Int)(nn: Int): Int
case InfixApp(Apps(id: Ident, paramLists), Keyword.`:`, sign) =>
(symName, R(id), paramLists, N, S(sign))
// fun f[T]: Int
// fun f[T](n1: Int): Int
// fun f[T](n1: Int)(nn: Int): Int
case InfixApp(Apps(App(id: Ident, typeParams: TyTup), paramLists), Keyword.`:`, ret) =>
(symName, R(id), paramLists, S(typeParams), N)

case InfixApp(Jux(lhs, rhs), Keyword.`:`, ret) =>
rec(InfixApp(rhs, Keyword.`:`, ret), S(lhs))
case id: Ident =>
(symName, R(id), N, N, N)
case App(id: Ident, typeParams: TyTup) =>
(symName, R(id), N, S(typeParams), N)
case App(id: Ident, args) =>
(symName, R(id), S(args :: Nil), N, N)
case App(primary: App, second) =>
// TODO: handle the second parameter list
val (sn, id, first, tps, sig) = rec(primary, symName)
(sn, id, S(first.fold(Ls(second))(_ :+ second)), tps, sig)

// fun f
// fun f(n1: Int)
// fun f(n1: Int)(nn: Int)
case Apps(id: Ident, paramLists) =>
(symName, R(id), paramLists, N, N)
// fun f[T]
// fun f[T](n1: Int)
// fun f[T](n1: Int)(nn: Int)
case Apps(App(id: Ident, typeParams: TyTup), paramLists) =>
(symName, R(id), paramLists, S(typeParams), N)

case Jux(lhs, rhs) => // happens in `fun (op) nme` form
require(symName.isEmpty) // TOOD
rec(rhs, S(lhs))
Expand Down

0 comments on commit 883abd9

Please sign in to comment.