[go: up one dir, main page]

File: state.ml

package info (click to toggle)
cduce 0.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,180 kB
  • ctags: 3,176
  • sloc: ml: 20,028; xml: 5,546; makefile: 427; sh: 133
file content (29 lines) | stat: -rw-r--r-- 692 bytes parent folder | download | duplicates (8)
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
(*
let state = ref []
let complete = ref false

let close () =
  complete := true

let register name r =
  if !complete then failwith "State.register: state already closed";
  state := (name,Obj.magic r) :: !state 

let ref name v =
  let r = ref v in
  register name r;
  r

let get () =
  if not !complete then failwith "State.get: need to close the state";
  Obj.magic (List.map (fun (name,r) -> (name, !r)) !state)

let set s =
  if not !complete then failwith "State.set: need to close the state";
  let rec aux = function
    | [],[] -> ()
    | (n1,v)::l1, (n2,r)::l2 when n1 = n2 -> r := v; aux (l1,l2)
    | _ -> failwith "State.set_state: failed"
  in
  aux (Obj.magic s,!state)
*)