Skip to content

Commit

Permalink
motoko-san: refactor assign_stmt
Browse files Browse the repository at this point in the history
Make it possible to return multiple instructions (for arrays)
  • Loading branch information
GoPavel committed Apr 25, 2024
1 parent c5e40ac commit 3b228e0
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/viper/trans.ml
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,12 @@ and dec ctxt d =
{ ctxt with ids = Env.add x.it Local ctxt.ids },
fun ctxt' ->
([ !!(id x, tr_typ e.note.M.note_typ) ],
[ !!(assign_stmt ctxt' (id x) e) ])
assign_stmt ctxt' (id x) e d.at)
| M.(LetD ({it=VarP x;_}, e, None)) ->
{ ctxt with ids = Env.add x.it Local ctxt.ids },
fun ctxt' ->
([ !!(id x, tr_typ e.note.M.note_typ) ],
[ !!(assign_stmt ctxt' (id x) e) ])
assign_stmt ctxt' (id x) e d.at)
| M.(ExpD e) -> (* TODO: restrict to e of unit type? *)
(ctxt,
fun ctxt' ->
Expand Down Expand Up @@ -502,7 +502,7 @@ and stmt ctxt (s : M.exp) : seqn =
begin match Env.find x.it ctxt.ids with
| Local ->
let loc = !!! (x.at) (x.it) in
!!([], [!!(assign_stmt ctxt loc e2)])
!!([], assign_stmt ctxt loc e2 s.at)
| Field ->
let fld = (self ctxt x.at, id x) in
!!([],
Expand Down Expand Up @@ -532,19 +532,19 @@ and stmt ctxt (s : M.exp) : seqn =
self_var :: call_args ctxt args))])
| M.RetE e ->
!!([],
[ !!(assign_stmt ctxt (!!! (Source.no_region) "$Res") e);
!!(GotoS(!!! (Source.no_region) "$Ret"))
])
assign_stmt ctxt (!!! (Source.no_region) "$Res") e s.at
@ [ !!(GotoS(!!! (Source.no_region) "$Ret")) ])
| _ ->
unsupported s.at (Arrange.exp s)

and assign_stmt ctxt x e =
and assign_stmt ctxt x e at =
let (!!) p = !!! at p in
match e with
| M.({it = CallE({it = VarE m; _}, inst, args); _}) ->
MethodCallS ([x], id m,
let self_var = self ctxt m.at in
self_var :: call_args ctxt args)
| _ -> VarAssignS(x, exp ctxt e)
[ !!(MethodCallS ([x], id m,
let self_var = self ctxt m.at in
self_var :: call_args ctxt args))]
| _ -> [!! (VarAssignS(x, exp ctxt e))]

and call_args ctxt e =
match e with
Expand Down

0 comments on commit 3b228e0

Please sign in to comment.