From 08b38472e22c428316f648bc7a3014b119a546f1 Mon Sep 17 00:00:00 2001 From: Alain Date: Mon, 22 Nov 2021 15:49:02 +0100 Subject: [PATCH] found a bug inside the match translation. --- compiler/lcalc/ast.ml | 3 +++ compiler/lcalc/compile_without_exceptions.ml | 11 ++++++++++- compiler/lcalc/to_ocaml.ml | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/compiler/lcalc/ast.ml b/compiler/lcalc/ast.ml index c4ae6123..c5eb2467 100644 --- a/compiler/lcalc/ast.ml +++ b/compiler/lcalc/ast.ml @@ -26,6 +26,7 @@ type lit = type except = ConflictError | EmptyError | NoValueProvided | Crash + type expr = | EVar of expr Bindlib.var Pos.marked | ETuple of expr Pos.marked list * D.StructName.t option @@ -118,6 +119,8 @@ let make_letopt_in (e2: expr Pos.marked Bindlib.box) : expr Pos.marked Bindlib.box = +(* let%opt x: tau = e1 in e2 == matchopt e1 with | None -> None | Some x -> e2 *) + let pos = Pos.get_position (Bindlib.unbox e2) in let+ e2 = make_abs diff --git a/compiler/lcalc/compile_without_exceptions.ml b/compiler/lcalc/compile_without_exceptions.ml index a7388fe6..555df713 100644 --- a/compiler/lcalc/compile_without_exceptions.ml +++ b/compiler/lcalc/compile_without_exceptions.ml @@ -106,7 +106,16 @@ and translate_expr (ctx : ctx) (e : D.expr Pos.marked) : A.expr Pos.marked Bindl let e2 = let+ e1 = Bindlib.box (A.EVar (x, pos)) - and+ cases = Bindlib.box_list (List.map (translate_expr ctx) cases) in + (* there is an issue here. *) + and+ cases = cases + |> List.map (fun e' -> translate_expr ctx e') + |> List.map (function + | A.ESome e'' -> e'' + | _ -> assert false + ) + |> assert false + |> Bindlib.box_list + in same_pos @@ A.EMatch ((e1, pos), cases, en) in diff --git a/compiler/lcalc/to_ocaml.ml b/compiler/lcalc/to_ocaml.ml index 1696246b..65081f01 100644 --- a/compiler/lcalc/to_ocaml.ml +++ b/compiler/lcalc/to_ocaml.ml @@ -108,6 +108,7 @@ let avoid_keywords (s : string) : string = | "object" | "of" | "open" | "or" | "private" | "rec" | "sig" | "struct" | "then" | "to" | "true" | "try" | "type" | "val" | "virtual" | "when" | "while" | "with" -> true + | "x" -> true (* i need a variable to make the translation *) | _ -> false then s ^ "_" else s @@ -331,7 +332,7 @@ let rec format_expr (ctx : Dcalc.Ast.decl_ctx) (fmt : Format.formatter) (e : exp Format.fprintf fmt "@[ Some@ %a@ @]" format_with_parens e1 | ENone -> Format.fprintf fmt "None@" | EMatchopt (e1, e2, e3) -> - let x = assert false in + let x = Ast.Var.make ("x", Pos.no_pos) in Format.fprintf fmt "@[match@ %a@]@ with@\n| None ->@[@ %a@]@\n| Some %a ->@[@ %a@ %a@]" format_expr e1 format_with_parens e2 format_var x format_with_parens e3 format_var x let format_struct_embedding (fmt : Format.formatter)