Skip to content

Commit

Permalink
Remaining cases for pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeom committed Jul 27, 2024
1 parent 00d871b commit b47258e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/expr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ module Expr = struct
| Extract (e1, h1, l1), Extract (e2, h2, l2) ->
phys_equal e1 e2 && h1 = h2 && l1 = l2
| Concat (e1, e3), Concat (e2, e4) -> phys_equal e1 e2 && phys_equal e3 e4
| _ -> false
| ( ( Val _ | Ptr _ | Symbol _ | List _ | App _ | Unop _ | Binop _ | Triop _
| Relop _ | Cvtop _ | Naryop _ | Extract _ | Concat _ )
, _ ) ->
false

let hash (e : expr) : int =
let h x = Hashtbl.hash x in
Expand Down
6 changes: 4 additions & 2 deletions src/value.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ let rec equal (v1 : t) (v2 : t) : bool =
| List l1, List l2 -> List.equal equal l1 l2
| App (`Op op1, vs1), App (`Op op2, vs2) ->
String.equal op1 op2 && List.equal equal vs1 vs2
| _ -> false
| (True | False | Unit | Int _ | Real _ | Str _ | Num _ | List _ | App _), _
->
false

let rec pp (fmt : Fmt.formatter) (v : t) : unit =
match v with
Expand All @@ -73,7 +75,7 @@ let rec pp (fmt : Fmt.formatter) (v : t) : unit =
Fmt.pf fmt "%s(%a)" op
(Fmt.list ~sep:(fun fmt () -> Fmt.string fmt ", ") pp)
vs
| _ -> assert false
| App _ -> assert false

let to_string (v : t) : string = Fmt.str "%a" pp v

Expand Down

0 comments on commit b47258e

Please sign in to comment.