From a2ac6c6b0c6c457ceca9bea6e1c6d94386add4dd Mon Sep 17 00:00:00 2001 From: nilfit <nils.fitinghoff@gmail.com> Date: Thu, 28 Feb 2019 17:36:59 +0100 Subject: [PATCH] clean up --- src/mlw/rust_printer.ml | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/mlw/rust_printer.ml b/src/mlw/rust_printer.ml index 2b7953d21..f410d50c3 100644 --- a/src/mlw/rust_printer.ml +++ b/src/mlw/rust_printer.ml @@ -27,7 +27,6 @@ module Rust = struct type pat = | Pwild (* _ *) | Pvar of ident * bool (* mut? id *) - (* TODO may need to be able to mark as ref too *) | Pde_str of ident * rsymbol list * pat list (* destructure struct *) (* S { l1: p1, l2: p2; .. } rust *) | Pde_enum of lsymbol * pat list (* destructure enum *) @@ -79,7 +78,6 @@ module Rust = struct } * It is not needed to translate Mltree. *) - (* TODO introduce tuple structs and make enum a list of typedefs *) | Dstruct of (ident * ty) list type t_defn = { @@ -157,8 +155,6 @@ module Translate = struct let rs_nargs = Hrs.create 42 - (* TODO make sure we don't extract any ghosts *) - let is_id_func = id_equal ts_func.ts_name let rec translate_ty info (t:ty) : Rust.ty = @@ -306,7 +302,7 @@ module Translate = struct | Eblock [] -> [0] | Eblock el -> find_arg_counts (List.hd (List.rev el)) | Eexn (_, _, e) -> find_arg_counts e - | Evar _ (* TODO can this ever be of function type? *) + | Evar _ (* TODO the var could hold a function *) | Econst _ | Eassign _ | Ewhile (_, _) | Efor (_, _, _, _, _) | Eraise (_, _) | Eignore _ | Eabsurd | Ehole -> [] | Eany _ -> assert false @@ -338,7 +334,7 @@ module Translate = struct let e'' = {e' with e_node = Eapp (rs, el @ el2)} in translate_expr info e'' | e1 :: el' -> Rust.Ecall (translate_expr info e1, List.map (translate_expr info) el') - | _ -> raise (TODO ("infix @ with " ^ (* TODO this can only happen for el=[] now *) + | _ -> raise (TODO ("infix @ with " ^ (* this can only happen for el=[] now *) string_of_int (List.length el) ^ " args"))) else ( let el = List.map (translate_expr info) el in @@ -377,11 +373,9 @@ module Translate = struct | None, _ -> (* use rs_nargs to know when and where to split into multiple calls *) let nargs = (try Hrs.find rs_nargs rs -(* with Not_found -> [2]) in *) with Not_found -> let loc = rs.rs_name.id_loc in Loc.errorm ?loc "rs_nargs not found %s. Should it be in a driver?" rs.rs_name.id_string) in -(* raise (TODO ("rs_nargs not found " ^ rs.rs_name.id_string ^ ". Should it be in a driver?"))) in *) (* the second result signals that the last application is partial * and how many args are not applied *) let rec split_args el nargs : Rust.expr list list * int option = @@ -440,7 +434,6 @@ module Translate = struct | Eif (ei, et, ee) -> Rust.Eif (translate_expr info ei, translate_expr info et, translate_expr info ee) - (* TODO special cases like if true *) | Eassign [(rho, rs, e)] -> Rust.Eassign (rho, rs, translate_expr info e) | Eassign al -> @@ -480,19 +473,18 @@ module Translate = struct | Mltree.Eexn (xs, _, _) -> let loc = xs.xs_name.id_loc in Loc.errorm ?loc "Unsupported exception: %s" xs.xs_name.id_string -(* raise (TODO "Eexn") *) | Mltree.Eignore _ -> raise (TODO "Eignore") (* let _ = e, or do we need a _name to avoid dropping early? *) | Mltree.Eany _ -> raise (TODO "Eany") | Eabsurd -> Rust.Eunreachable | Mltree.Ehole -> raise (TODO "Ehole") -(* | _ -> raise (TODO "expr") *) ) and translate_branch info ((p, e):reg_branch) : Rust.branch = (translate_pat info p, translate_expr info e) + (* lifetimes and type variables *) let union_stv_list sl = List.fold_left Stv.union Stv.empty sl let union_slt_list sl = List.fold_left Slt.union Slt.empty sl let union_slt_stv_list sl = @@ -515,7 +507,6 @@ module Translate = struct let rec discover_lts_tvs_expr (e:Rust.expr) : Slt.t * Stv.t = let map_and_union el = union_slt_stv_list (List.map discover_lts_tvs_expr el) in -(* let map_and_union el = union_stv_list (List.map discover_lts_tvs_expr el) in *) (match e with | Rust.Econst _ | Rust.Evar _ | Rust.Eunreachable | Rust.Ers _ -> Slt.empty, Stv.empty @@ -538,8 +529,6 @@ module Translate = struct discover_lts_tvs_expr e | Rust.Efn ((_, args, _, e1, stv, slt), e2) -> (* TODO promote tvs from the fn args/body? *) -(* let sl = List.map (fun (_, t) -> discover_lts_tvs_ty t) args in *) -(* let s1 = discover_lts_tvs_expr e1 in *) let s2 = discover_lts_tvs_expr e2 in s2 ) @@ -552,8 +541,7 @@ module Translate = struct let ts = discover_lts_tvs_ty t in let vs = union_slt_stv_list (List.map tvs_snd_ty vl) in union_slt_stv_list [es; ts; vs; (lts, tvs)] - | Rust.Dstatic _ -> Slt.empty, Stv.empty - (* TODO make sure this is correct *) + | Rust.Dstatic (_, e) -> discover_lts_tvs_expr e | Rust.Dtype td -> (match td.Rust.def with | None -> Slt.empty, Stv.empty @@ -726,20 +714,18 @@ module Translate = struct let vr = translate_vars info vars in let arg_counts = List.length vars :: find_arg_counts e in Hrs.add rs_nargs rs arg_counts; - (* TODO can the tvs be found from rs_cty instead? *) + (* TODO can the type variables be found from rs_cty instead? *) let slt, stv = discover_lts_tvs_def (Rust.Dfn (rs, vr, tr, er, Stv.empty, Slt.empty)) in [Rust.Dfn (rs, vr, tr, er, stv, slt)] | Dlet (Lrec rdefs) -> List.map (translate_rdef info) rdefs | Dlet (Lvar (pv, e)) -> [Rust.Dstatic (pv, translate_expr info e)] (* top level (static) variables *) - (* TODO find mlw that leads to this case *) | Dlet (Lany (rs, res, args)) -> Hrs.add rs_nargs rs [List.length args]; let args = List.map (fun (id, _, _) -> id.id_string) args in let args = String.concat ", " args in let s = rs.rs_name.id_string ^ ", _, [" ^ args ^ "]" in -(* raise (TODO ("Dlet(Lany " ^ s ^ ")")) *) [Rust.Derror ("Dlet(Lany " ^ s ^ ")")] | Dtype itsl -> let bf, be = box_typedefs itsl boxes.box_fields boxes.box_enum in @@ -899,9 +885,7 @@ module Print = struct match ty with | Tvar tv -> print_tv fmt tv | Tapp (ts, tl, lts) -> -(* print_slt_stv fmt (lts, (Stv.of_list tl)) *) (* tl is ty not tvsymbol *) (match tl with - (* TODO make a function print_slt_ty that handles <> *) | [] -> (print_uident info) fmt ts | tl -> fprintf fmt "%a<%a>" (print_uident info) ts @@ -939,8 +923,10 @@ module Print = struct let pv_name (pv:pvsymbol) : ident = pv.pv_vs.vs_name let print_pv info fmt pv = print_lident info fmt (pv_name pv) - let print_constant fmt (n:BigInt.t) = fprintf fmt "%s" (BigInt.to_string n) - (* TODO parenthesize if negative *) + let print_constant fmt (n:BigInt.t) = + let s = BigInt.to_string n in + fprintf fmt (if BigInt.sign n = 0 then "%s" else "(%s)") s +(* fprintf fmt "%s" (BigInt.to_string n) *) let print_arg info fmt (id, ty) = fprintf fmt "%a:@ %a" (print_lident info) id (print_ty info) ty @@ -1024,10 +1010,7 @@ module Print = struct let print_type_def info fmt (td:t_defn) = let pub = if not td.priv then "pub " else "" in match td.def with -(* - | None -> raise (TODO "None type def") -*) - |None->fprintf fmt "%stype %a = ***none_typedef here****" pub (print_uident info) td.id + |None -> fprintf fmt "%stype %a = ***none_typedef here****" pub (print_uident info) td.id (* TODO error out in translation instead of passing it along this far *) | Some (Denum csl) -> let print_constr fmt (id, tl) = -- GitLab