@@ -89,7 +89,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
89
89
private def getFields (etts : List [Statement ]): Set [Var ] = {
90
90
etts.flatMap{
91
91
case NuFunDef (_, nm, _, _) => Some (nm)
92
- case NuTypeDef (_, TypeName (nm), _, _, _, _) => Some (Var (nm ))
92
+ case nuty : NuTypeDef => Some (Var (nuty.name ))
93
93
case Let (_, name, _, _) => Some (name)
94
94
case _ => None
95
95
}.toSet
@@ -180,13 +180,13 @@ class ClassLifter(logDebugMsg: Boolean = false) {
180
180
}.fold(emptyCtx)(_ ++ _)
181
181
case TyApp (trm, tpLst) =>
182
182
getFreeVars(trm).addT(tpLst.flatMap(_.collectTypeNames.map(TypeName (_))))
183
- case NuTypeDef (_, nm, tps, param, pars, body) =>
183
+ case NuTypeDef (_, nm, tps, param, _, pars, _, _ , body) =>
184
184
val prmVs = getFreeVars(param)(using emptyCtx, Map (), None )
185
185
val newVs = prmVs.vSet ++ getFields(body.entities) + Var (nm.name)
186
- val nCtx = ctx.addV(newVs).addT(nm).addT(tps)
186
+ val nCtx = ctx.addV(newVs).addT(nm).addT(tps.map(_._2) )
187
187
val parVs = pars.map(getFreeVars(_)(using nCtx)).fold(emptyCtx)(_ ++ _)
188
188
val bodyVs = body.entities.map(getFreeVars(_)(using nCtx)).fold(emptyCtx)(_ ++ _)
189
- (bodyVs ++ parVs -+ prmVs).extT(tps)
189
+ (bodyVs ++ parVs -+ prmVs).extT(tps.map(_._2) )
190
190
case Blk (stmts) =>
191
191
val newVs = getFields(stmts)
192
192
stmts.map(getFreeVars(_)(using ctx.addV(newVs))).fold(emptyCtx)(_ ++ _)
@@ -197,7 +197,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
197
197
}
198
198
199
199
private def collectClassInfo (cls : NuTypeDef , preClss : Set [TypeName ])(using ctx : LocalContext , cache : ClassCache , outer : Option [ClassInfoCache ]): ClassInfoCache = {
200
- val NuTypeDef (_, nm, tps, param, pars, body) = cls
200
+ val NuTypeDef (_, nm, tps, param, _, pars, _, _ , body) = cls
201
201
log(s " grep context of ${cls.nme.name} under { \n $ctx\n $cache\n $outer\n } \n " )
202
202
val (clses, funcs, trms) = splitEntities(cls.body.entities)
203
203
val (supNms, rcdFlds) = pars.map(getSupClsInfoByTerm).unzip
@@ -209,7 +209,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
209
209
}.unzip
210
210
log(s " par record: ${flds._2.flatten}" )
211
211
val fields = (param.fields.flatMap(tupleEntityToVar) ++ funcs.map(_.nme) ++ clses.map(x => Var (x.nme.name)) ++ trms.flatMap(grepFieldsInTrm) ++ flds._1).toSet
212
- val nCtx = ctx.addV(fields).addV(flds._1).extT(tps)
212
+ val nCtx = ctx.addV(fields).addV(flds._1).extT(tps.map(_._2) )
213
213
val tmpCtx = ((body.entities.map(getFreeVars(_)(using nCtx)) ++ pars.map(getFreeVars(_)(using nCtx))).fold(emptyCtx)(_ ++ _).moveT2V(preClss)
214
214
).addT(flds._2.flatten.toSet).extV(supNms.flatten.map(x => Var (x.name)))
215
215
@@ -379,13 +379,14 @@ class ClassLifter(logDebugMsg: Boolean = false) {
379
379
val nTpNm = TypeName (genAnoName(t.name))
380
380
val cls = cache.get(t).get
381
381
val supArgs = Tup (cls.body.params.fields.flatMap(tupleEntityToVar).map(toFldsEle))
382
- val anoCls = NuTypeDef (Cls , nTpNm, Nil , cls.body.params, List (App (Var (t.name), supArgs)), tu)
382
+ val anoCls = NuTypeDef (Cls , nTpNm, Nil , cls.body.params, None ,
383
+ List (App (Var (t.name), supArgs)), None , None , tu)(None )
383
384
val nSta = New (Some ((nTpNm, prm)), TypingUnit (Nil ))
384
385
val ret = liftEntities(List (anoCls, nSta))
385
386
(Blk (ret._1), ret._2)
386
387
case New (None , tu) =>
387
388
val nTpNm = TypeName (genAnoName())
388
- val anoCls = NuTypeDef (Cls , nTpNm, Nil , Tup (Nil ), Nil , tu )
389
+ val anoCls = NuTypeDef (Cls , nTpNm, Nil , Tup (Nil ), None , Nil , None , None , tu)( None )
389
390
val nSta = New (Some ((nTpNm, Tup (Nil ))), TypingUnit (Nil ))
390
391
val ret = liftEntities(List (anoCls, nSta))
391
392
(Blk (ret._1), ret._2)
@@ -464,7 +465,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
464
465
val nlhs = liftType(lb)
465
466
val nrhs = liftType(ub)
466
467
Bounds (nlhs._1, nrhs._1) -> (nlhs._2 ++ nrhs._2)
467
- case Constrained (base, bounds, where) =>
468
+ case Constrained (base : Type , bounds, where) =>
468
469
val (nTargs, nCtx) = bounds.map { case (tv, Bounds (lb, ub)) =>
469
470
val nlhs = liftType(lb)
470
471
val nrhs = liftType(ub)
@@ -478,6 +479,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
478
479
val (nBase, bCtx) = liftType(base)
479
480
Constrained (nBase, nTargs, bounds2) ->
480
481
((nCtx ++ nCtx2).fold(emptyCtx)(_ ++ _) ++ bCtx)
482
+ case Constrained (_, _, _) => die
481
483
case Function (lhs, rhs) =>
482
484
val nlhs = liftType(lhs)
483
485
val nrhs = liftType(rhs)
@@ -531,7 +533,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
531
533
case PolyType (targs, body) =>
532
534
val (body2, ctx) = liftType(body)
533
535
PolyType (targs, body2) -> ctx
534
- case Top | Bot | _ : Literal | _ : TypeTag | _ : TypeVar => target -> emptyCtx
536
+ case Top | Bot | _ : Literal | _ : TypeTag | _ : TypeVar => target. asInstanceOf [ Type ] -> emptyCtx
535
537
}
536
538
537
539
@@ -541,14 +543,14 @@ class ClassLifter(logDebugMsg: Boolean = false) {
541
543
body match {
542
544
case Left (value) =>
543
545
val ret = liftTerm(value)(using ctx.addV(nm).addT(tpVs))
544
- (func.copy(rhs = Left (ret._1)), ret._2)
546
+ (func.copy(rhs = Left (ret._1))( None ) , ret._2)
545
547
case Right (PolyType (targs, body)) =>
546
548
val nBody = liftType(body)(using ctx.addT(tpVs))
547
549
val nTargs = targs.map {
548
550
case L (tp) => liftTypeName(tp)(using ctx.addT(tpVs)).mapFirst(Left .apply)
549
551
case R (tv) => R (tv) -> emptyCtx
550
552
}.unzip
551
- (func.copy(rhs = Right (PolyType (nTargs._1, nBody._1))), nTargs._2.fold(nBody._2)(_ ++ _))
553
+ (func.copy(rhs = Right (PolyType (nTargs._1, nBody._1)))( None ) , nTargs._2.fold(nBody._2)(_ ++ _))
552
554
}
553
555
}
554
556
@@ -624,14 +626,14 @@ class ClassLifter(logDebugMsg: Boolean = false) {
624
626
).flatten.toMap
625
627
}
626
628
log(" lift type " + target.toString() + " with cache " + cache.toString())
627
- val NuTypeDef (kind, nme, tps, params, pars, body) = target
629
+ val NuTypeDef (kind, nme, tps, params, sig, pars, supAnn, thisAnn , body) = target
628
630
val nOuter = cache.get(nme)
629
631
val ClassInfoCache (_, nName, freeVs, flds, inners, sups, _, _, _) = nOuter.get
630
632
val (clsList, funcList, termList) = splitEntities(body.entities)
631
633
val innerNmsSet = clsList.map(_.nme).toSet
632
634
633
635
val nCache = cache ++ inners ++ getAllInners(sups)
634
- val nTps = (tps ++ (freeVs.tSet -- nCache.keySet).toList).distinct
636
+ val nTps = (tps.map(_._2) ++ (freeVs.tSet -- nCache.keySet).toList).distinct
635
637
val nCtx = freeVs.addT(nTps)
636
638
val nParams =
637
639
outer.map(x => List (toFldsEle(Var (genParName(x.liftedNm.name))))).getOrElse(Nil )
@@ -641,7 +643,9 @@ class ClassLifter(logDebugMsg: Boolean = false) {
641
643
val nFuncs = funcList.map(liftFunc(_)(using emptyCtx, nCache, nOuter)).unzip
642
644
val nTerms = termList.map(liftTerm(_)(using emptyCtx, nCache, nOuter)).unzip
643
645
clsList.foreach(x => liftTypeDefNew(x)(using nCache, nOuter))
644
- retSeq = retSeq.appended(NuTypeDef (kind, nName, nTps, Tup (nParams), nPars._1, TypingUnit (nFuncs._1 ++ nTerms._1)))
646
+ retSeq = retSeq.appended(NuTypeDef (
647
+ kind, nName, nTps.map((None , _)), Tup (nParams), None , nPars._1,
648
+ None , None , TypingUnit (nFuncs._1 ++ nTerms._1))(None ))
645
649
}
646
650
647
651
def liftTypingUnit (rawUnit : TypingUnit ): TypingUnit = {
0 commit comments