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

simplify detection of functions when translating types

parent 239eff71
No related branches found
No related tags found
No related merge requests found
...@@ -7,8 +7,6 @@ theory BuiltIn ...@@ -7,8 +7,6 @@ theory BuiltIn
end end
module HighOrd module HighOrd
(* used by the printer to safely detect function types *)
syntax type (->) "FUNCTION_ARROW"
(* TODO this does not work when there are multiple @ *) (* TODO this does not work when there are multiple @ *)
syntax val ( @ ) "%1(%2)" syntax val ( @ ) "%1(%2)"
end end
......
...@@ -135,19 +135,20 @@ module MLToRust = struct ...@@ -135,19 +135,20 @@ module MLToRust = struct
(* TODO make sure we don't extract any ghosts *) (* TODO make sure we don't extract any ghosts *)
let id_is_func = id_equal ts_func.ts_name
let rec translate_ty info (t:ty) : Rust.ty = let rec translate_ty info (t:ty) : Rust.ty =
match t with match t with
| Tvar tvs -> Rust.Tvar tvs | Tvar tvs -> Rust.Tvar tvs
| Ttuple tl -> Rust.Ttuple (List.map (translate_ty info) tl) | Ttuple tl -> Rust.Ttuple (List.map (translate_ty info) tl)
(* specialization of a generic type *) (* function *)
| Tapp (ts, tl) -> | Tapp (ts, tl) when id_is_func ts ->
let syn = query_syntax info.syntax ts in
match syn with
| Some "FUNCTION_ARROW" ->
(* recursively look for multi-argument functions *)
let args_and_res = function_sig info t in let args_and_res = function_sig info t in
let args, res = Lists.chop_last args_and_res in let args, res = Lists.chop_last args_and_res in
Rust.Tfn(args, res) Rust.Tfn(args, res)
(* specialization of a generic type *)
| Tapp (ts, tl) ->
match query_syntax info.syntax ts with
| Some s -> Rust.Tsyn (s, List.map (translate_ty info) tl) | Some s -> Rust.Tsyn (s, List.map (translate_ty info) tl)
| None -> | None ->
let tl = List.map (translate_ty info) tl in let tl = List.map (translate_ty info) tl in
...@@ -155,13 +156,10 @@ module MLToRust = struct ...@@ -155,13 +156,10 @@ module MLToRust = struct
and function_sig info (t:ty) : Rust.ty list = and function_sig info (t:ty) : Rust.ty list =
match t with match t with
| Tapp (ts, tl) -> | Tapp (ts, tl) when id_is_func ts ->
(match query_syntax info.syntax ts with
| Some "FUNCTION_ARROW" ->
(match tl with (match tl with
| [ta; tb] -> translate_ty info ta :: function_sig info tb | [ta; tb] -> translate_ty info ta :: function_sig info tb
| _ -> assert false) | _ -> assert false)
| _ -> [translate_ty info t])
| _ -> [translate_ty info t] | _ -> [translate_ty info t]
let translate_var (info:info) ((id, ty, _ghost):var) : Rust.var = let translate_var (info:info) ((id, ty, _ghost):var) : Rust.var =
...@@ -207,15 +205,6 @@ module MLToRust = struct ...@@ -207,15 +205,6 @@ module MLToRust = struct
exception MissingSyntaxLiteral exception MissingSyntaxLiteral
let get_record info rs =
match Mid.find_opt rs.rs_name info.mo_known_map with
| Some {pd_node = PDtype itdl} ->
let eq_rs {itd_constructors} =
List.exists (rs_equal rs) itd_constructors in
let itd = List.find eq_rs itdl in
List.filter (fun e -> not (rs_ghost e)) itd.itd_fields
| _ -> []
let box_expr (e:Rust.expr) = Rust.Esyntax ("Box::new(%1)", [e]) let box_expr (e:Rust.expr) = Rust.Esyntax ("Box::new(%1)", [e])
let rec translate_expr (info:info) (e:expr) : Rust.expr = let rec translate_expr (info:info) (e:expr) : Rust.expr =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment