summaryrefslogtreecommitdiff
path: root/testsuite/tests/frame-pointers/reperform.ml
blob: ec5393907c0a1f944dfd7c35ae877a3ec2636d65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(* TEST
 frame_pointers;
 readonly_files = "fp_backtrace.c";
 all_modules = "${readonly_files} reperform.ml";
 native;
*)

open Effect
open Effect.Deep

external fp_backtrace : unit -> unit = "fp_backtrace" [@@noalloc]

type _ Effect.t += E : unit t
                 | F : unit t

let rec foo n =
  if n = 10 then 0
  else begin
    if n = 5 then begin
      perform E;
      print_endline "# resumed...";
      fp_backtrace ()
    end;
    foo (n + 1) + n
  end

let rec bar n =
  if n = 10 then 0
  else begin
    if n = 5 then begin
      match_with foo 0
      { retc = ignore;
        exnc = raise;
        effc = fun (type a) (eff : a t) ->
          match eff with
          | F -> Some (fun (k : (a, _) continuation) -> continue k ())
          | _ -> None }
    end;
    bar (n + 1) + n
  end

let _ =
  try_with bar 0
  { effc = fun (type a) (eff : a t) ->
      match eff with
      | E -> Some (fun (k : (a, _) continuation) -> continue k ())
      | _ -> None }