@ -82,10 +82,6 @@ and Trm : sig
| Sized of { seq : t ; siz : t }
| Sized of { seq : t ; siz : t }
| Extract of { seq : t ; off : t ; len : t }
| Extract of { seq : t ; off : t ; len : t }
| Concat of t array
| Concat of t array
(* records ( with fixed indices ) *)
| Select of { idx : int ; rcd : t }
| Update of { idx : int ; rcd : t ; elt : t }
| Record of t array
(* uninterpreted *)
(* uninterpreted *)
| Apply of Funsym . t * t array
| Apply of Funsym . t * t array
[ @@ deriving compare , equal , sexp ]
[ @@ deriving compare , equal , sexp ]
@ -100,9 +96,6 @@ and Trm : sig
val _ Sized : t -> t -> t
val _ Sized : t -> t -> t
val _ Extract : t -> t -> t -> t
val _ Extract : t -> t -> t -> t
val _ Concat : t array -> t
val _ Concat : t array -> t
val _ Select : int -> t -> t
val _ Update : int -> t -> t -> t
val _ Record : t array -> t
val _ Apply : Funsym . t -> t array -> t
val _ Apply : Funsym . t -> t array -> t
val add : t -> t -> t
val add : t -> t -> t
val sub : t -> t -> t
val sub : t -> t -> t
@ -121,9 +114,6 @@ end = struct
| Sized of { seq : t ; siz : t }
| Sized of { seq : t ; siz : t }
| Extract of { seq : t ; off : t ; len : t }
| Extract of { seq : t ; off : t ; len : t }
| Concat of t array
| Concat of t array
| Select of { idx : int ; rcd : t }
| Update of { idx : int ; rcd : t ; elt : t }
| Record of t array
| Apply of Funsym . t * t array
| Apply of Funsym . t * t array
[ @@ deriving compare , equal , sexp ]
[ @@ deriving compare , equal , sexp ]
@ -155,11 +145,15 @@ end = struct
| Sized { seq ; siz } -> pf " @<1>⟨%a,%a@<1>⟩ " pp siz pp seq
| Sized { seq ; siz } -> pf " @<1>⟨%a,%a@<1>⟩ " pp siz pp seq
| Extract { seq ; off ; len } -> pf " %a[%a,%a) " pp seq pp off pp len
| Extract { seq ; off ; len } -> pf " %a[%a,%a) " pp seq pp off pp len
| Concat [| |] -> pf " @<2>⟨⟩ "
| Concat [| |] -> pf " @<2>⟨⟩ "
| Concat xs -> pf " (%a) " ( Array . pp " @,^ " pp ) xs
| Concat xs -> (
| Select { idx ; rcd } -> pf " %a[%i] " pp rcd idx
let exception Not_a_string in
| Update { idx ; rcd ; elt } ->
try
pf " [%a@ @[| %i → %a@]] " pp rcd idx pp elt
pf " %S "
| Record xs -> pf " {%a} " ( ppx_record strength ) xs
( String . init ( Array . length xs ) ~ f : ( fun i ->
match xs . ( i ) with
| Sized { seq = Z c } -> Char . of_int_exn ( Z . to_int c )
| _ -> raise_notrace Not_a_string ) )
with _ -> pf " (%a) " ( Array . pp " @,^ " pp ) xs )
| Apply ( f , [| |] ) -> pf " %a " Funsym . pp f
| Apply ( f , [| |] ) -> pf " %a " Funsym . pp f
| Apply
| Apply
( ( ( Rem | BitAnd | BitOr | BitXor | BitShl | BitLshr | BitAshr )
( ( ( Rem | BitAnd | BitOr | BitXor | BitShl | BitLshr | BitAshr )
@ -171,24 +165,6 @@ end = struct
in
in
pp fs trm
pp fs trm
and ppx_record strength fs elts =
[ % Trace . fprintf
fs " %a "
( fun fs elts ->
let exception Not_a_string in
match
String . init ( Array . length elts ) ~ f : ( fun i ->
match elts . ( i ) with
| Z c -> Char . of_int_exn ( Z . to_int c )
| _ -> raise_notrace Not_a_string )
with
| s -> Format . fprintf fs " %S " s
| exception ( Not_a_string | Z . Overflow | Failure _ ) ->
Format . fprintf fs " @[<h>%a@] "
( Array . pp " ,@ " ( ppx strength ) )
elts )
elts ]
let pp = ppx ( fun _ -> None )
let pp = ppx ( fun _ -> None )
let invariant e =
let invariant e =
@ -354,10 +330,6 @@ end = struct
let xs = Array . reduce_adjacent ~ f : simp_adjacent xs in
let xs = Array . reduce_adjacent ~ f : simp_adjacent xs in
( if Array . length xs = 1 then xs . ( 0 ) else Concat xs ) | > check invariant
( if Array . length xs = 1 then xs . ( 0 ) else Concat xs ) | > check invariant
let _ Select idx rcd = Select { idx ; rcd } | > check invariant
let _ Update idx rcd elt = Update { idx ; rcd ; elt } | > check invariant
let _ Record es = Record es | > check invariant
let _ Apply f es =
let _ Apply f es =
( match Funsym . eval ~ equal ~ get_z ~ ret_z : _ Z ~ get_q ~ ret_q : _ Q f es with
( match Funsym . eval ~ equal ~ get_z ~ ret_z : _ Z ~ get_q ~ ret_q : _ Q f es with
| Some c -> c
| Some c -> c
@ -370,16 +342,15 @@ end = struct
match e with
match e with
| Var _ as v -> f ( Var . of_ v )
| Var _ as v -> f ( Var . of_ v )
| Z _ | Q _ -> ()
| Z _ | Q _ -> ()
| Splat x | Select { rcd = x } -> iter_vars ~ f x
| Splat x -> iter_vars ~ f x
| Sized { seq = x ; siz = y } | Update { rcd = x ; elt = y } ->
| Sized { seq = x ; siz = y } ->
iter_vars ~ f x ;
iter_vars ~ f x ;
iter_vars ~ f y
iter_vars ~ f y
| Extract { seq = x ; off = y ; len = z } ->
| Extract { seq = x ; off = y ; len = z } ->
iter_vars ~ f x ;
iter_vars ~ f x ;
iter_vars ~ f y ;
iter_vars ~ f y ;
iter_vars ~ f z
iter_vars ~ f z
| Concat xs | Record xs | Apply ( _ , xs ) ->
| Concat xs | Apply ( _ , xs ) -> Array . iter ~ f : ( iter_vars ~ f ) xs
Array . iter ~ f : ( iter_vars ~ f ) xs
| Arith a -> Iter . iter ~ f : ( iter_vars ~ f ) ( Arith . trms a )
| Arith a -> Iter . iter ~ f : ( iter_vars ~ f ) ( Arith . trms a )
let vars e = Iter . from_labelled_iter ( iter_vars e )
let vars e = Iter . from_labelled_iter ( iter_vars e )
@ -428,12 +399,6 @@ let sized ~seq ~siz = _Sized seq siz
let extract ~ seq ~ off ~ len = _ Extract seq off len
let extract ~ seq ~ off ~ len = _ Extract seq off len
let concat elts = _ Concat elts
let concat elts = _ Concat elts
(* records *)
let select ~ rcd ~ idx = _ Select idx rcd
let update ~ rcd ~ idx ~ elt = _ Update idx rcd elt
let record elts = _ Record elts
(* uninterpreted *)
(* uninterpreted *)
let apply sym args = _ Apply sym args
let apply sym args = _ Apply sym args
@ -449,9 +414,6 @@ let rec map_vars e ~f =
| Sized { seq ; siz } -> map2 ( map_vars ~ f ) e _ Sized seq siz
| Sized { seq ; siz } -> map2 ( map_vars ~ f ) e _ Sized seq siz
| Extract { seq ; off ; len } -> map3 ( map_vars ~ f ) e _ Extract seq off len
| Extract { seq ; off ; len } -> map3 ( map_vars ~ f ) e _ Extract seq off len
| Concat xs -> mapN ( map_vars ~ f ) e _ Concat xs
| Concat xs -> mapN ( map_vars ~ f ) e _ Concat xs
| Select { idx ; rcd } -> map1 ( map_vars ~ f ) e ( _ Select idx ) rcd
| Update { idx ; rcd ; elt } -> map2 ( map_vars ~ f ) e ( _ Update idx ) rcd elt
| Record xs -> mapN ( map_vars ~ f ) e _ Record xs
| Apply ( g , xs ) -> mapN ( map_vars ~ f ) e ( _ Apply g ) xs
| Apply ( g , xs ) -> mapN ( map_vars ~ f ) e ( _ Apply g ) xs
let map e ~ f =
let map e ~ f =
@ -462,9 +424,6 @@ let map e ~f =
| Sized { seq ; siz } -> map2 f e _ Sized seq siz
| Sized { seq ; siz } -> map2 f e _ Sized seq siz
| Extract { seq ; off ; len } -> map3 f e _ Extract seq off len
| Extract { seq ; off ; len } -> map3 f e _ Extract seq off len
| Concat xs -> mapN f e _ Concat xs
| Concat xs -> mapN f e _ Concat xs
| Select { idx ; rcd } -> map1 f e ( _ Select idx ) rcd
| Update { idx ; rcd ; elt } -> map2 f e ( _ Update idx ) rcd elt
| Record xs -> mapN f e _ Record xs
| Apply ( g , xs ) -> mapN f e ( _ Apply g ) xs
| Apply ( g , xs ) -> mapN f e ( _ Apply g ) xs
(* * Traverse *)
(* * Traverse *)
@ -473,15 +432,15 @@ let iter_subtrms e ~f =
match e with
match e with
| Var _ | Z _ | Q _ -> ()
| Var _ | Z _ | Q _ -> ()
| Arith a -> Iter . iter ~ f ( Arith . trms a )
| Arith a -> Iter . iter ~ f ( Arith . trms a )
| Splat x | Select { rcd = x } -> f x
| Splat x -> f x
| Sized { seq = x ; siz = y } | Update { rcd = x ; elt = y } ->
| Sized { seq = x ; siz = y } ->
f x ;
f x ;
f y
f y
| Extract { seq = x ; off = y ; len = z } ->
| Extract { seq = x ; off = y ; len = z } ->
f x ;
f x ;
f y ;
f y ;
f z
f z
| Concat xs | Record xs | Apply ( _ , xs ) -> Array . iter ~ f xs
| Concat xs | Apply ( _ , xs ) -> Array . iter ~ f xs
let subtrms e = Iter . from_labelled_iter ( iter_subtrms e )
let subtrms e = Iter . from_labelled_iter ( iter_subtrms e )