@ -96,8 +96,8 @@ and Trm : sig
val _ Q : Q . t -> t
val _ Q : Q . t -> t
val _ Arith : Arith . t -> t
val _ Arith : Arith . t -> t
val _ Splat : t -> t
val _ Splat : t -> t
val _ Sized : t -> t -> t
val _ Sized : seq: t -> siz : t -> t
val _ Extract : t -> t -> t -> t
val _ Extract : seq: t -> off: t -> len : t -> t
val _ Concat : t array -> t
val _ Concat : 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
@ -229,7 +229,7 @@ end = struct
let seq_size e =
let seq_size e =
try Some ( seq_size_exn e ) with Invalid_argument _ -> None
try Some ( seq_size_exn e ) with Invalid_argument _ -> None
let _ Sized seq siz =
let _ Sized ~ seq ~ siz =
( match seq_size seq with
( match seq_size seq with
(* ⟨n,α⟩ ==> α when n ≡ |α | *)
(* ⟨n,α⟩ ==> α when n ≡ |α | *)
| Some n when equal siz n -> seq
| Some n when equal siz n -> seq
@ -247,7 +247,7 @@ end = struct
let empty_seq = Concat [| |]
let empty_seq = Concat [| |]
let rec _ Extract seq off len =
let rec _ Extract ~ seq ~ off ~ len =
[ % trace ]
[ % trace ]
~ call : ( fun { pf } -> pf " %a " pp ( Extract { seq ; off ; len } ) )
~ call : ( fun { pf } -> pf " %a " pp ( Extract { seq ; off ; len } ) )
~ retn : ( fun { pf } -> pf " %a " pp )
~ retn : ( fun { pf } -> pf " %a " pp )
@ -259,12 +259,12 @@ end = struct
match seq with
match seq with
(* α [m,k ) [o,l ) ==> α [m+o,l ) when k ≥ o+l *)
(* α [m,k ) [o,l ) ==> α [m+o,l ) when k ≥ o+l *)
| Extract { seq = a ; off = m ; len = k } when partial_ge k o_l ->
| Extract { seq = a ; off = m ; len = k } when partial_ge k o_l ->
_ Extract a (add m off ) len
_ Extract ~ seq : a ~off : (add m off ) ~ len
(* ⟨_,0⟩[_,_ ) ==> 0 *)
(* ⟨_,0⟩[_,_ ) ==> 0 *)
| Sized { seq } when seq = = zero -> seq
| Sized { seq } when seq = = zero -> seq
(* ⟨n,E^⟩[o,l ) ==> ⟨l,E^⟩ when n ≥ o+l *)
(* ⟨n,E^⟩[o,l ) ==> ⟨l,E^⟩ when n ≥ o+l *)
| Sized { siz = n ; seq = Splat _ as e } when partial_ge n o_l ->
| Sized { siz = n ; seq = Splat _ as e } when partial_ge n o_l ->
_ Sized e len
_ Sized ~ seq : e ~ siz : len
(* ⟨n,a⟩[0,n ) ==> ⟨n,a⟩ *)
(* ⟨n,a⟩[0,n ) ==> ⟨n,a⟩ *)
| Sized { siz = n } when equal off zero && equal n len -> seq
| Sized { siz = n } when equal off zero && equal n len -> seq
(* For ( α₀^α₁ ) [o,l ) there are 3 cases:
(* For ( α₀^α₁ ) [o,l ) there are 3 cases:
@ -293,7 +293,7 @@ end = struct
Array . fold_map_until na1N ( l , off )
Array . fold_map_until na1N ( l , off )
~ f : ( fun naI ( l , oI ) ->
~ f : ( fun naI ( l , oI ) ->
if Z . equal Z . zero l then
if Z . equal Z . zero l then
` Continue ( _ Extract naI oI zero , ( l , oI ) )
` Continue ( _ Extract ~ seq : naI ~ off : oI ~ len : zero , ( l , oI ) )
else
else
let nI = seq_size_exn naI in
let nI = seq_size_exn naI in
let oI_nI = sub oI nI in
let oI_nI = sub oI nI in
@ -302,7 +302,8 @@ end = struct
let oJ = if Z . sign z < = 0 then zero else oI_nI in
let oJ = if Z . sign z < = 0 then zero else oI_nI in
let lI = Z . ( max zero ( min l ( neg z ) ) ) in
let lI = Z . ( max zero ( min l ( neg z ) ) ) in
let l = Z . ( l - lI ) in
let l = Z . ( l - lI ) in
` Continue ( _ Extract naI oI ( _ Z lI ) , ( l , oJ ) )
` Continue
( _ Extract ~ seq : naI ~ off : oI ~ len : ( _ Z lI ) , ( l , oJ ) )
| _ -> ` Stop ( Extract { seq ; off ; len } ) )
| _ -> ` Stop ( Extract { seq ; off ; len } ) )
~ finish : ( fun ( e1N , _ ) -> _ Concat e1N )
~ finish : ( fun ( e1N , _ ) -> _ Concat e1N )
| _ -> Extract { seq ; off ; len } )
| _ -> Extract { seq ; off ; len } )
@ -328,15 +329,15 @@ end = struct
, Extract { seq = na' ; off = o_k ; len = l } )
, Extract { seq = na' ; off = o_k ; len = l } )
when equal na na' && equal o_k ( add o k ) && partial_ge n ( add o_k l )
when equal na na' && equal o_k ( add o k ) && partial_ge n ( add o_k l )
->
->
Some ( _ Extract na o ( add k l ) )
Some ( _ Extract ~ seq : na ~ off : o ~ len : ( add k l ) )
(* ⟨m,0⟩^⟨n,0⟩ ==> ⟨m+n,0⟩ *)
(* ⟨m,0⟩^⟨n,0⟩ ==> ⟨m+n,0⟩ *)
| Sized { siz = m ; seq = a } , Sized { siz = n ; seq = a' }
| Sized { siz = m ; seq = a } , Sized { siz = n ; seq = a' }
when a = = zero && a' = = zero ->
when a = = zero && a' = = zero ->
Some ( _ Sized a ( add m n ) )
Some ( _ Sized ~ seq : a ~ siz : ( add m n ) )
(* ⟨m,E^⟩^⟨n,E^⟩ ==> ⟨m+n,E^⟩ *)
(* ⟨m,E^⟩^⟨n,E^⟩ ==> ⟨m+n,E^⟩ *)
| Sized { siz = m ; seq = Splat _ as a } , Sized { siz = n ; seq = a' }
| Sized { siz = m ; seq = Splat _ as a } , Sized { siz = n ; seq = a' }
when equal a a' ->
when equal a a' ->
Some ( _ Sized a ( add m n ) )
Some ( _ Sized ~ seq : a ~ siz : ( add m n ) )
| _ -> None
| _ -> None
in
in
let xs = flatten xs in
let xs = flatten xs in
@ -408,8 +409,8 @@ let arith = _Arith
(* sequences *)
(* sequences *)
let splat = _ Splat
let splat = _ Splat
let sized ~seq ~ siz = _ Sized seq siz
let sized = _ Sized
let extract ~seq ~ off ~ len = _ Extract seq off len
let extract = _ Extract
let concat elts = _ Concat elts
let concat elts = _ Concat elts
(* uninterpreted *)
(* uninterpreted *)
@ -424,8 +425,12 @@ let rec map_vars e ~f =
| Z _ | Q _ -> e
| Z _ | Q _ -> e
| Arith a -> map1 ( Arith . map ~ f : ( map_vars ~ f ) ) e _ Arith a
| Arith a -> map1 ( Arith . map ~ f : ( map_vars ~ f ) ) e _ Arith a
| Splat x -> map1 ( map_vars ~ f ) e _ Splat x
| Splat x -> map1 ( map_vars ~ f ) e _ Splat x
| Sized { seq ; siz } -> map2 ( map_vars ~ f ) e _ Sized seq siz
| Sized { seq ; siz } ->
| Extract { seq ; off ; len } -> map3 ( map_vars ~ f ) e _ Extract seq off len
map2 ( map_vars ~ f ) e ( fun seq siz -> _ Sized ~ seq ~ siz ) seq siz
| Extract { seq ; off ; len } ->
map3 ( map_vars ~ f ) e
( fun seq off len -> _ Extract ~ seq ~ off ~ len )
seq off len
| Concat xs -> mapN ( map_vars ~ f ) e _ Concat xs
| Concat xs -> mapN ( map_vars ~ f ) e _ Concat xs
| Apply ( g , xs ) -> mapN ( map_vars ~ f ) e ( _ Apply g ) xs
| Apply ( g , xs ) -> mapN ( map_vars ~ f ) e ( _ Apply g ) xs
@ -434,8 +439,9 @@ let map e ~f =
| Var _ | Z _ | Q _ -> e
| Var _ | Z _ | Q _ -> e
| Arith a -> map1 ( Arith . map ~ f ) e _ Arith a
| Arith a -> map1 ( Arith . map ~ f ) e _ Arith a
| Splat x -> map1 f e _ Splat x
| Splat x -> map1 f e _ Splat x
| Sized { seq ; siz } -> map2 f e _ Sized seq siz
| Sized { seq ; siz } -> map2 f e ( fun seq siz -> _ Sized ~ seq ~ siz ) seq siz
| Extract { seq ; off ; len } -> map3 f e _ Extract seq off len
| Extract { seq ; off ; len } ->
map3 f e ( fun seq off len -> _ Extract ~ seq ~ off ~ len ) seq off len
| Concat xs -> mapN f e _ Concat xs
| Concat xs -> mapN f e _ Concat xs
| Apply ( g , xs ) -> mapN f e ( _ Apply g ) xs
| Apply ( g , xs ) -> mapN f e ( _ Apply g ) xs