@@ -48,7 +48,7 @@ sealed abstract class Block extends Product:
4848 // Note that the handler's LHS and body are not part of the current block, so we do not consider them here.
4949 case HandleBlock (lhs, res, par, args, cls, hdr, bod, rst) => rst.definedVars + res
5050 case TryBlock (sub, fin, rst) => sub.definedVars ++ fin.definedVars ++ rst.definedVars
51- case Label (lbl, bod, rst) => bod.definedVars ++ rst.definedVars
51+ case Label (lbl, _, bod, rst) => bod.definedVars ++ rst.definedVars
5252
5353 lazy val size : Int = this match
5454 case _ : Return | _ : Throw | _ : End | _ : Break | _ : Continue => 1
@@ -60,7 +60,7 @@ sealed abstract class Block extends Product:
6060 1 + arms.map(_._2.size).sum + dflt.map(_.size).getOrElse(0 ) + rst.size
6161 case Define (_, rst) => 1 + rst.size
6262 case TryBlock (sub, fin, rst) => 1 + sub.size + fin.size + rst.size
63- case Label (_, bod, rst) => 1 + bod.size + rst.size
63+ case Label (_, _, bod, rst) => 1 + bod.size + rst.size
6464 case HandleBlock (lhs, res, par, args, cls, handlers, bdy, rst) => 1 + handlers.map(_.body.size).sum + bdy.size + rst.size
6565
6666 // TODO conserve if no changes
@@ -75,7 +75,7 @@ sealed abstract class Block extends Product:
7575 Match (scrut, arms.map(_ -> _.mapTail(f)), dflt.map(_.mapTail(f)), rst)
7676 case Match (scrut, arms, dflt, rst) =>
7777 Match (scrut, arms, dflt, rst.mapTail(f))
78- case Label (label, body, rest) => Label (label, body, rest.mapTail(f))
78+ case Label (label, loop, body, rest) => Label (label, loop, body.mapTail(f) , rest.mapTail(f))
7979 case af @ AssignField (lhs, nme, rhs, rest) =>
8080 AssignField (lhs, nme, rhs, rest.mapTail(f))(af.symbol)
8181 case adf @ AssignDynField (lhs, fld, arrayIdx, rhs, rest) =>
@@ -90,7 +90,7 @@ sealed abstract class Block extends Product:
9090 (pat, arm) => arm.freeVars -- pat.freeVars
9191 case Return (res, implct) => res.freeVars
9292 case Throw (exc) => exc.freeVars
93- case Label (label, body, rest) => (body.freeVars - label) ++ rest.freeVars
93+ case Label (label, _, body, rest) => (body.freeVars - label) ++ rest.freeVars
9494 case Break (label) => Set (label)
9595 case Continue (label) => Set (label)
9696 case Begin (sub, rest) => sub.freeVars ++ rest.freeVars
@@ -110,7 +110,7 @@ sealed abstract class Block extends Product:
110110 (pat, arm) => arm.freeVarsLLIR -- pat.freeVarsLLIR
111111 case Return (res, implct) => res.freeVarsLLIR
112112 case Throw (exc) => exc.freeVarsLLIR
113- case Label (label, body, rest) => (body.freeVarsLLIR - label) ++ rest.freeVarsLLIR
113+ case Label (label, _, body, rest) => (body.freeVarsLLIR - label) ++ rest.freeVarsLLIR
114114 case Break (label) => Set .empty
115115 case Continue (label) => Set .empty
116116 case Begin (sub, rest) => sub.freeVarsLLIR ++ rest.freeVarsLLIR
@@ -132,7 +132,7 @@ sealed abstract class Block extends Product:
132132 case AssignDynField (_, _, _, rhs, rest) => rhs.subBlocks ::: rest :: Nil
133133 case Define (d, rest) => d.subBlocks ::: rest :: Nil
134134 case HandleBlock (_, _, par, args, _, handlers, body, rest) => par.subBlocks ++ args.flatMap(_.subBlocks) ++ handlers.map(_.body) :+ body :+ rest
135- case Label (_, body, rest) => body :: rest :: Nil
135+ case Label (_, _, body, rest) => body :: rest :: Nil
136136
137137 // TODO rm Lam from values and thus the need for these cases
138138 case Return (r, _) => r.subBlocks
@@ -177,12 +177,12 @@ sealed abstract class Block extends Product:
177177 then this
178178 else Match (scrut, newArms, newDflt, newRest)
179179
180- case Label (label, body, rest) =>
180+ case Label (label, loop, body, rest) =>
181181 val newBody = body.flattened
182182 val newRest = rest.flatten(k)
183183 if (newBody is body) && (newRest is rest)
184184 then this
185- else Label (label, newBody, newRest)
185+ else Label (label, loop, newBody, newRest)
186186
187187 case Begin (sub, rest) =>
188188 sub.flatten(_ => rest.flatten(k))
@@ -267,7 +267,7 @@ case class Return(res: Result, implct: Bool) extends BlockTail
267267
268268case class Throw (exc : Result ) extends BlockTail
269269
270- case class Label (label : Local , body : Block , rest : Block ) extends Block
270+ case class Label (label : Local , loop : Bool , body : Block , rest : Block ) extends Block
271271
272272case class Break (label : Local ) extends BlockTail
273273case class Continue (label : Local ) extends BlockTail
@@ -595,7 +595,7 @@ extension (k: Block => Block)
595595 def end = k.rest(End ())
596596 def ifthen (scrut : Path , cse : Case , trm : Block , els : Opt [Block ] = N ): Block => Block =
597597 k.chain(Match (scrut, cse -> trm :: Nil , els, _))
598- def label (label : Local , body : Block ) = k.chain(Label (label, body, _))
598+ def label (label : Local , loop : Bool , body : Block ) = k.chain(Label (label, loop , body, _))
599599 def ret (r : Result ) = k.rest(Return (r, false ))
600600 def staticif (b : Boolean , f : (Block => Block ) => (Block => Block )) = if b then k.transform(f) else k
601601 def foldLeft [A ](xs : Iterable [A ])(f : (Block => Block , A ) => Block => Block ) = xs.foldLeft(k)(f)
0 commit comments