From 9c120f0f2f0657c3218d17d017756083fa0b00a0 Mon Sep 17 00:00:00 2001 From: Jonathan Protzenko Date: Thu, 24 Oct 2024 16:56:40 -0700 Subject: [PATCH] Fix a few tidbits here and there --- lib/AstToMiniRust.ml | 15 +++++++++++++-- lib/OptimizeMiniRust.ml | 4 ++-- lib/PrintMiniRust.ml | 6 +++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/AstToMiniRust.ml b/lib/AstToMiniRust.ml index 9363b6ae..a131ad3c 100644 --- a/lib/AstToMiniRust.ml +++ b/lib/AstToMiniRust.ml @@ -697,8 +697,13 @@ and translate_expr_with_type (env: env) (e: Ast.expr) (t_ret: MiniRust.typ): env env, Operator o | EQualified lid -> begin try - let name, t = lookup_decl env lid in - env, possibly_convert (Name name) t + match lid with + | [ "C" ], "_zero_for_deref" -> + (* CInt for Rust means no suffix -- rustc will convert to usize or u32 *) + env, Constant (CInt, "0") + | _ -> + let name, t = lookup_decl env lid in + env, possibly_convert (Name name) t with Not_found -> (* External -- TODO: make sure external definitions are properly added to the scope *) @@ -971,6 +976,12 @@ and translate_expr_with_type (env: env) (e: Ast.expr) (t_ret: MiniRust.typ): env let _, e = translate_expr env e in binders, pat, e ) branches in + let branches = + if not (List.exists (fun (_, p, _) -> p = MiniRust.Wildcard) branches) then + branches @ [ [], Wildcard, Panic "Incomplete pattern matching" ] + else + branches + in env, Match (e, t, branches) | ECons (cons, es) -> diff --git a/lib/OptimizeMiniRust.ml b/lib/OptimizeMiniRust.ml index e2f9da1c..50a00992 100644 --- a/lib/OptimizeMiniRust.ml +++ b/lib/OptimizeMiniRust.ml @@ -274,10 +274,10 @@ let rec infer_expr (env: env) valuation (expected: typ) (known: known) (e: expr) failwith "TODO: Call" (* atom = e3 *) - | Assign (Open { atom; _ }, e3, t) -> + | Assign (Open { atom; _ } as e1, e3, t) -> (* KPrint.bprintf "[infer_expr-mut,assign] %a\n" pexpr e; *) let known, e3 = infer_expr env valuation t known e3 in - add_mut_var atom known, e3 + add_mut_var atom known, Assign (e1, e3, t) (* atom[e2] = e2 *) | Assign (Index (Open { atom; _ } as e1, e2), e3, t) diff --git a/lib/PrintMiniRust.ml b/lib/PrintMiniRust.ml index cb60354c..987aa864 100644 --- a/lib/PrintMiniRust.ml +++ b/lib/PrintMiniRust.ml @@ -514,7 +514,11 @@ and print_pat env (p: pat) = else break1 ^^ braces_with_nesting ( separate_map (comma ^^ break1) (fun (name, pat) -> - group (group (string name ^^ colon) ^/^ group (print_pat env pat)) + match pat with + | VarP v when match lookup env v with Bound b -> b.name = name | _ -> false -> + print_pat env pat + | _ -> + group (group (string name ^^ colon) ^/^ group (print_pat env pat)) ) fields ^^ trailing ) | VarP v ->