Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 47 lines (37 sloc) 1.321 kb
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 type 'a label = 'a ref * exn
19
20 let return (r,e) value =
21 r := value;
22 raise e
23
24 let set_checkpoint_either f =
25 let r = ref (Obj.magic 0) in
26 let module M = struct exception Return end in
27 (* defining a local exception, it is different from any other one *)
28 try
29 Base.Left (f (r,M.Return))
30 with
31 | M.Return -> Base.Right !r
32
33 let set_checkpoint_opt f =
34 match set_checkpoint_either f with
35 | Base.Left () -> None
36 | Base.Right a -> Some a
37
38 let set_checkpoint f =
39 match set_checkpoint_either f with
40 | Base.Left a -> a
41 | Base.Right a -> a
42
43 let set_checkpoint_none f =
44 match set_checkpoint_either f with
45 | Base.Left a -> Some a
46 | Base.Right () -> None
Something went wrong with that request. Please try again.