Skip to content
Snippets Groups Projects
Commit 81de7472 authored by nilfit's avatar nilfit
Browse files

add Eassign translation

parent 8e0823a8
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ module Rust = struct ...@@ -47,6 +47,7 @@ module Rust = struct
| Econst of string option * BigInt.t | Econst of string option * BigInt.t
| Evar of pvsymbol | Evar of pvsymbol
| Efield of expr * ident | Efield of expr * ident
| Eassign of pvsymbol * rsymbol * pvsymbol
| Etup of expr list | Etup of expr list
| Eenum of rsymbol * expr list | Eenum of rsymbol * expr list
| Estruct of rsymbol * rsymbol list * expr list (* Rs { r1: e1, r2: e2 } *) | Estruct of rsymbol * rsymbol list * expr list (* Rs { r1: e1, r2: e2 } *)
...@@ -105,6 +106,7 @@ module Rust = struct ...@@ -105,6 +106,7 @@ module Rust = struct
| Esyntax (s, el) -> Esyntax (s, (clean_list el)) | Esyntax (s, el) -> Esyntax (s, (clean_list el))
| Elet (p, e1, e2) -> Elet (p, clean_expr e1, clean_expr e2) | Elet (p, e1, e2) -> Elet (p, clean_expr e1, clean_expr e2)
| Efield (e, id) -> Efield (clean_expr e, id) | Efield (e, id) -> Efield (clean_expr e, id)
| Eassign _ -> e
| Etup el -> Etup (clean_list el) | Etup el -> Etup (clean_list el)
| Eenum (rs, el) -> Eenum (rs, clean_list el) | Eenum (rs, el) -> Eenum (rs, clean_list el)
| Estruct (rs, fl, el) -> Estruct (rs, fl, clean_list el) | Estruct (rs, fl, el) -> Estruct (rs, fl, clean_list el)
...@@ -302,9 +304,11 @@ module MLToRust = struct ...@@ -302,9 +304,11 @@ module MLToRust = struct
Rust.Eif (translate_expr info ei, translate_expr info et, Rust.Eif (translate_expr info ei, translate_expr info et,
translate_expr info ee) translate_expr info ee)
(* TODO special cases *) (* TODO special cases *)
| Mltree.Eassign _ -> | Eassign [(rho, rs, pv)] ->
Rust.Eassign (rho, rs, pv)
| Eassign al ->
(* struct field assignment *) (* struct field assignment *)
raise (TODO "Eassign") Rust.Eblock (List.map (fun (rho, rs, pv) -> Rust.Eassign (rho, rs, pv)) al)
| Ematch (e1, [(p, e2)], []) -> | Ematch (e1, [(p, e2)], []) ->
(* TODO is this always irrefutable? *) (* TODO is this always irrefutable? *)
Rust.Elet (translate_pat info p, translate_expr info e1, Rust.Elet (translate_pat info p, translate_expr info e1,
...@@ -370,6 +374,7 @@ module MLToRust = struct ...@@ -370,6 +374,7 @@ module MLToRust = struct
map_and_union el map_and_union el
| Rust.Elet (_, e1, e2) -> map_and_union [e1;e2] | Rust.Elet (_, e1, e2) -> map_and_union [e1;e2]
| Rust.Efield (e, _) -> discover_lts_tvs_expr e | Rust.Efield (e, _) -> discover_lts_tvs_expr e
| Rust.Eassign _ -> Slt.empty, Stv.empty (* FIXME *)
| Rust.Etup el -> map_and_union el | Rust.Etup el -> map_and_union el
| Rust.Eenum (_, el) -> map_and_union el | Rust.Eenum (_, el) -> map_and_union el
| Rust.Estruct (_, _, el) -> map_and_union el (* TODO check rsymbols*) | Rust.Estruct (_, _, el) -> map_and_union el (* TODO check rsymbols*)
...@@ -763,6 +768,9 @@ module Print = struct ...@@ -763,6 +768,9 @@ module Print = struct
| Evar pv -> print_pv info fmt pv | Evar pv -> print_pv info fmt pv
| Efield (e, id) -> | Efield (e, id) ->
fprintf fmt "%a.%a" (print_expr info) e (print_lident info) id fprintf fmt "%a.%a" (print_expr info) e (print_lident info) id
| Eassign (rho, rs, pv) ->
fprintf fmt "%a.%a = %a" (print_lident info) (pv_name rho)
(print_lident info) rs.rs_name (print_lident info) (pv_name pv)
| Etup el -> fprintf fmt "(%a)" (print_list comma (print_expr info)) el | Etup el -> fprintf fmt "(%a)" (print_list comma (print_expr info)) el
| Eenum (rs, []) -> print_uident info fmt (struct_id rs) | Eenum (rs, []) -> print_uident info fmt (struct_id rs)
| Eenum (rs, el) -> | Eenum (rs, el) ->
...@@ -770,7 +778,7 @@ module Print = struct ...@@ -770,7 +778,7 @@ module Print = struct
(print_list comma (print_expr info)) el (print_list comma (print_expr info)) el
| Estruct (rs, fl, el) -> | Estruct (rs, fl, el) ->
fprintf fmt "@[<hov 2>%a { %a }@]" (print_uident info) (struct_id rs) fprintf fmt "@[<hov 2>%a { %a }@]" (print_uident info) (struct_id rs)
(print_list2 semi colon (print_rs info) (print_expr info)) (fl, el) (print_list2 comma colon (print_rs info) (print_expr info)) (fl, el)
| Eblock el -> | Eblock el ->
fprintf fmt "@[<hov 2>{@\n%a@]@\n}" (print_list semi (print_expr info)) el fprintf fmt "@[<hov 2>{@\n%a@]@\n}" (print_list semi (print_expr info)) el
| Ecall (rs, el) -> | Ecall (rs, el) ->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment