@@ -274,9 +274,13 @@ enum Stmt extends Tree {
274
274
// creates a fresh state handler to model local (backtrackable) state.
275
275
// [[capture]] is a binding occurrence.
276
276
// e.g. state(init) { [x]{x: Ref} => ... }
277
- case Var (id : Id , init : Pure , capture : Id , body : Stmt )
278
- case Get (id : Id , annotatedCapt : Captures , annotatedTpe : ValueType )
279
- case Put (id : Id , annotatedCapt : Captures , value : Pure )
277
+ case Var (ref : Id , init : Pure , capture : Id , body : Stmt )
278
+
279
+ // e.g. let x: T = !ref @ r; body
280
+ case Get (id : Id , annotatedTpe : ValueType , ref : Id , annotatedCapt : Captures , body : Stmt )
281
+
282
+ // e.g. ref @ r := value; body
283
+ case Put (ref : Id , annotatedCapt : Captures , value : Pure , body : Stmt )
280
284
281
285
// binds a fresh prompt as [[id]] in [[body]] and delimits the scope of captured continuations
282
286
// Reset({ [cap]{p: Prompt[answer] at cap} => stmt: answer}): answer
@@ -614,11 +618,11 @@ object Variables {
614
618
case Stmt .Region (body) => free(body)
615
619
// are mutable variables now block variables or not?
616
620
case Stmt .Alloc (id, init, region, body) => free(init) ++ Variables .block(region, TRegion , Set (region)) ++ (free(body) -- Variables .block(id, TState (init.tpe), Set (region)))
617
- case Stmt .Var (id , init, capture, body) => free(init) ++ (free(body) -- Variables .block(id , TState (init.tpe), Set (capture)))
618
- case Stmt .Get (id, annotatedCapt, annotatedTpe ) =>
619
- Variables .block(id , core.Type .TState (annotatedTpe), annotatedCapt)
620
- case Stmt .Put (id , annotatedCapt, value) =>
621
- Variables .block(id , core.Type .TState (value.tpe), annotatedCapt) ++ free(value)
621
+ case Stmt .Var (ref , init, capture, body) => free(init) ++ (free(body) -- Variables .block(ref , TState (init.tpe), Set (capture)))
622
+ case Stmt .Get (id, annotatedTpe, ref, annotatedCapt, body ) =>
623
+ Variables .block(ref , core.Type .TState (annotatedTpe), annotatedCapt) ++ (free(body) -- Variables .value(id, annotatedTpe) )
624
+ case Stmt .Put (ref , annotatedCapt, value, body ) =>
625
+ Variables .block(ref , core.Type .TState (value.tpe), annotatedCapt) ++ free(value) ++ free(body )
622
626
623
627
case Stmt .Reset (body) => free(body)
624
628
case Stmt .Shift (prompt, body) => free(prompt) ++ free(body)
@@ -710,14 +714,14 @@ object substitutions {
710
714
Alloc (id, substitute(init), substituteAsVar(region),
711
715
substitute(body)(using subst shadowBlocks List (id)))
712
716
713
- case Var (id , init, capture, body) =>
714
- Var (id , substitute(init), capture, substitute(body)(using subst shadowBlocks List (id )))
717
+ case Var (ref , init, capture, body) =>
718
+ Var (ref , substitute(init), capture, substitute(body)(using subst shadowBlocks List (ref )))
715
719
716
- case Get (id, capt, tpe ) =>
717
- Get (substituteAsVar(id ), substitute(capt), substitute(tpe ))
720
+ case Get (id, tpe, ref, capt, body ) =>
721
+ Get (id, substitute(tpe), substituteAsVar(ref ), substitute(capt), substitute(body)( using subst shadowBlocks List (id) ))
718
722
719
- case Put (id , capt, value) =>
720
- Put (substituteAsVar(id ), substitute(capt), substitute(value))
723
+ case Put (ref , capt, value, body ) =>
724
+ Put (substituteAsVar(ref ), substitute(capt), substitute(value), substitute(body ))
721
725
722
726
// We annotate the answer type here since it needs to be the union of body.tpe and all shifts
723
727
case Reset (body) =>
0 commit comments