Skip to content

Commit 7d74ab8

Browse files
committed
PR: Cfold refactoring
1 parent b6402f4 commit 7d74ab8

9 files changed

Lines changed: 331 additions & 111 deletions

File tree

src/ecPV.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ module PVMap = struct
4747
Mnpv.find_opt (pvm m.pvm_env k) m.pvm_map
4848

4949
let raw m = m.pvm_map
50+
51+
5052
end
5153

5254
(* -------------------------------------------------------------------- *)

src/ecParser.mly

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2991,7 +2991,10 @@ interleave_info:
29912991
{ Pinterleave info }
29922992

29932993
| CFOLD s=side? c=codepos n=word?
2994-
{ Pcfold (s, c, n) }
2994+
{ Pcfold (s, c, n, false) }
2995+
2996+
| CFOLD STAR s=side? c=codepos n=word?
2997+
{ Pcfold (s, c, n, true) }
29952998

29962999
| RND s=side? info=rnd_info c=prefix(COLON, semrndpos)?
29973000
{ Prnd (s, c, info) }

src/ecParsetree.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ type phltactic =
757757
| Pcond of pcond_info
758758
| Pmatch of matchmode
759759
| Pswap of ((oside * pswap_kind) located list)
760-
| Pcfold of (oside * pcodepos * int option)
760+
| Pcfold of (oside * pcodepos * int option * bool) (* side + 1st inst + n lines + eager? *)
761761
| Pinline of inline_info
762762
| Poutline of outline_info
763763
| Pinterleave of interleave_info located

src/ecUtils.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,19 @@ module List = struct
626626
end
627627

628628
in fun state xs -> aux state [] xs
629+
630+
(* FIXME: REMOVE *)
631+
let fold_left_map_filter_while (f: 'a -> 'b -> ('a * ('c option)) interruptible) =
632+
let rec aux (state: 'a) (acc: 'c list) (xs : 'b list) =
633+
match xs with
634+
| [] -> (state, List.rev acc, [])
635+
| y :: ys -> begin
636+
match f state y with
637+
| `Continue (state, Some y) -> aux state (y :: acc) ys
638+
| `Continue (state, None) -> aux state acc ys
639+
| `Interrupt -> (state, List.rev acc, xs)
640+
end
641+
in fun state xs -> aux state [] xs
629642
end
630643

631644
(* -------------------------------------------------------------------- *)

src/ecUtils.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ module List : sig
309309
('a -> 'b -> [`Interrupt | `Continue of 'a * 'c])
310310
-> 'a -> 'b list -> 'a * 'c list * 'b list
311311

312+
val fold_left_map_filter_while :
313+
('a -> 'b -> [`Interrupt | `Continue of 'a * ('c option)])
314+
-> 'a -> 'b list -> 'a * 'c list * 'b list
315+
312316
(* ------------------------------------------------------------------ *)
313317
val ksort:
314318
?stable:bool -> ?rev:bool

0 commit comments

Comments
 (0)