Skip to content

Commit

Permalink
Fix a few tidbits here and there
Browse files Browse the repository at this point in the history
  • Loading branch information
msprotz committed Oct 24, 2024
1 parent 25131d7 commit 9c120f0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
15 changes: 13 additions & 2 deletions lib/AstToMiniRust.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down Expand Up @@ -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) ->
Expand Down
4 changes: 2 additions & 2 deletions lib/OptimizeMiniRust.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion lib/PrintMiniRust.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down

0 comments on commit 9c120f0

Please sign in to comment.