Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeom committed Jun 22, 2024
1 parent 8c65588 commit 95cc8ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 6 additions & 7 deletions lib/expr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ let triop' (ty : Ty.t) (op : triop) (e1 : t) (e2 : t) (e3 : t) : t =

let triop ty (op : triop) (e1 : t) (e2 : t) (e3 : t) : t =
match (op, view e1, view e2, view e3) with
| op, Val v1, Val v2, Val v3 -> value (Eval.triop ty op v1 v2 v3)
| Ite, Val True, _, _ -> e2
| Ite, Val False, _, _ -> e3
| op, Val v1, Val v2, Val v3 -> value (Eval.triop ty op v1 v2 v3)
| _ -> triop' ty op e1 e2 e3

let relop' (ty : Ty.t) (op : relop) (hte1 : t) (hte2 : t) : t =
Expand Down Expand Up @@ -520,12 +520,13 @@ module Bool = struct
let to_val b = if b then true_ else false_

let not_ (b : t) =
match of_val (view b) with
| Some b -> to_val b
let bexpr = view b in
match of_val bexpr with
| Some b -> to_val (not b)
| None -> (
match view b with
match bexpr with
| Unop (Ty_bool, Not, cond) -> cond
| _ -> unop' Ty_bool Not b )
| _ -> unop Ty_bool Not b )

let equal (b1 : t) (b2 : t) =
match (view b1, view b2) with
Expand All @@ -539,15 +540,13 @@ module Bool = struct

let and_ (b1 : t) (b2 : t) =
match (of_val (view b1), of_val (view b2)) with
| Some b1, Some b2 -> to_val (b1 && b2)
| Some true, _ -> b2
| _, Some true -> b1
| Some false, _ | _, Some false -> false_
| _ -> binop Ty_bool And b1 b2

let or_ (b1 : t) (b2 : t) =
match (of_val (view b1), of_val (view b2)) with
| Some b1, Some b2 -> to_val (b1 || b2)
| Some false, _ -> b2
| _, Some false -> b1
| Some true, _ | _, Some true -> true_
Expand Down
10 changes: 7 additions & 3 deletions test/unit/test_relop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ let () =

(* app *)
let () =
assert (relop Ty_app Eq (app (`Op "undefined") []) (app (`Op "undefined") []) = value True);
assert (relop Ty_app Ne (app (`Op "undefined") []) (app (`Op "undefined") []) = value False);
assert (
relop Ty_app Eq (app (`Op "undefined") []) (app (`Op "undefined") [])
= value True );
assert (
relop Ty_app Ne (app (`Op "undefined") []) (app (`Op "undefined") [])
= value False );
assert (relop Ty_app Eq (app (`Op "undefined") []) (int 1) = value False);
assert (relop Ty_app Eq (int 1) (app (`Op "undefined") []) = value False)
assert (relop Ty_app Eq (int 1) (app (`Op "undefined") []) = value False)

0 comments on commit 95cc8ab

Please sign in to comment.