@@ -37,12 +37,12 @@ class Specialiser(val tl: TraceLogger, val ctx: Ctx)(using val raise: Raise, val
37
37
term match
38
38
case Blk (Nil , res) => collectDefs(res)
39
39
case Blk ((d : Declaration ) :: stats, res) => collectDefs(Blk (stats, res)) ++ (d match
40
- case td@ TermDefinition (_, Fun , sym, params, _, Some (body), _) =>
40
+ case td@ TermDefinition (_, Fun , sym, params, _, Some (body), _, _, _ ) =>
41
41
val map = collectDefs(body) ++ collectDefs(Blk (stats, res))
42
42
if params.flatMap(_.params).exists(_.flags.spec) then map + (td.sym -> td) else map
43
43
case _ => d.subTerms.foldLeft(Map .empty[Symbol , TermDefinition ])((acc, sub) => acc ++ collectDefs(sub)))
44
44
case Blk ((t : Term ) :: stats, res) => collectDefs(t) ++ collectDefs(Blk (stats, res))
45
- case Blk (LetDecl (_) :: stats, res) => collectDefs(Blk (stats, res))
45
+ case Blk (LetDecl (_, _ ) :: stats, res) => collectDefs(Blk (stats, res))
46
46
case Blk (DefineVar (_, rhs) :: stats, res) => collectDefs(rhs) ++ collectDefs(Blk (stats, res))
47
47
case _ => term.subTerms.foldLeft(Map .empty)((acc, sub) => acc ++ collectDefs(sub))
48
48
@@ -59,14 +59,13 @@ class Specialiser(val tl: TraceLogger, val ctx: Ctx)(using val raise: Raise, val
59
59
case s => (acc._1 :+ s, acc._2)
60
60
collectApps(tree.res) match { case (res, ts) => (Blk (stats, res), types ::: ts) }
61
61
62
- // TODO: Make specFns immutable so this can be nice and pure
63
62
def collectApps (tree : Term )(using defs : Map [Symbol , TermDefinition ], specFns : MutMap [Str , Ident ]): Ctxl [(Term , Ls [SpApp ])] =
64
63
trace(s " Collecting term ${tree.showDbg}" ):
65
64
tree match
66
65
case app@ App (lhs, Tup (fields)) => lhs match
67
66
case s@ Sel (pre, nme) =>
68
67
if s.sym.isDefined && defs.contains(s.sym.get) then
69
- val typs = defs(s.sym.get).params.flatMap(_.params).zip(fields.map(_.value ).map {
68
+ val typs = defs(s.sym.get).params.flatMap(_.params).zip(fields.filter(e => e. isInstanceOf [ Fld ]). map(_.asInstanceOf [ Fld ].term ).map {
70
69
case Lit (lit) => lit.asTree match
71
70
case _ : IntLit => " Int"
72
71
case _ : StrLit => " Str"
@@ -75,13 +74,13 @@ class Specialiser(val tl: TraceLogger, val ctx: Ctx)(using val raise: Raise, val
75
74
}).filter(_._1.flags.spec)
76
75
log(s " Specialising ${s.sym.get} with ${typs.map((s, t) => s.sym.nme + " : " + t)}. " )
77
76
val fId = s.sym.get.nme + typs.map(_._2).mkString(" _" , " _" , " " )
78
- val name = specFns.getOrElseUpdate(fId, Ident (fId + " _" + state.nextUid)) // not sure state is the way to do this
77
+ val name = specFns.getOrElseUpdate(fId, Ident (fId + " _" + state.suid. nextUid))
79
78
val specApp : App = app.copy(lhs = s.copy(nme = name)(s.sym))(app.tree, app.resSym)
80
79
(specApp, SpApp (s.sym.get, typs.foldLeft(Map .empty)((acc, p) => acc + (p._1.sym -> p._2)), specApp) :: Nil )
81
80
else
82
81
(tree, Nil )
83
82
// FIXME: Ref applications aren't implemented, nor do I know when they are used
84
- case Ref (sym) => if defs.contains(sym) then (tree, SpApp (TempSymbol (999 , N , " " ), Map .empty, app) :: Nil ) else (tree, Nil )
83
+ case Ref (sym) => if defs.contains(sym) then (tree, SpApp (TempSymbol (N , " " ), Map .empty, app) :: Nil ) else (tree, Nil )
85
84
case _ => (tree, Nil )
86
85
case b : Blk => collectApps(b)
87
86
// FIXME: This won't work for nested applications in all cases
0 commit comments