package lutin

  1. Overview
  2. Docs

Source file rif.ml

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(*-----------------------------------------------------------------------
** Copyright (C) - Verimag.
** This file may only be copied under the terms of the CeCill
** Public License
**-----------------------------------------------------------------------
**
** File: rif.ml
** Author: erwan.jahier@univ-grenoble-alpes.fr
*)

    
(*------------------------------------------------------------------------*)
let (to_subst_list : Value.OfIdent.t -> Data.subst list) =
  fun x -> 
    Value.OfIdent.fold
      (fun name value acc -> 
         (name, Value.to_data_val value)::acc
      )
      x
      []

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

(* exported *)
let (read : bool -> in_channel -> out_channel option -> Exp.var list ->  Var.env_in) =
  fun _debug ic oc vars -> 
    let sl = RifIO.read ic oc
      (List.map (fun v -> Var.name v, Type.to_data_t (Var.typ v)) vars) 
    in
    let sl = List.map (fun (n,value) -> (n, Value.from_data_val value)) sl in
      Value.OfIdent.from_list sl

(*------------------------------------------------------------------------*)
(* exported *)
let (write : out_channel -> string -> unit) = RifIO.write

(* exported *)
let (flush : out_channel -> unit) = RifIO.flush

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

let (write_interface : out_channel -> Exp.var list -> Exp.var list -> Exp.var list option -> 
      Exp.var list list option -> unit) =
  fun oc in_vars out_vars loc_vars_opt oracle_vars_opt -> 
    RifIO.write_interface oc
      (List.map (fun v -> Var.name v, Type.to_data_t (Var.typ v)) in_vars)
      (List.map (fun v -> Var.name v, Type.to_data_t (Var.typ v)) out_vars)
      (match loc_vars_opt with
         | None -> None
         | Some vars -> 
           Some (List.map (fun v -> Var.name v, Type.to_data_t (Var.typ v)) vars)
      )
      (match oracle_vars_opt with
         | None -> None
         | Some vars_l -> 
           Some (List.map 
                   (List.map (fun v -> Var.name v, Type.to_data_t (Var.typ v)))
                   vars_l)
      )


(*------------------------------------------------------------------------*)
(* exported *)


let (write_outputs : out_channel -> Exp.var list -> Value.OfIdent.t -> unit) =
  fun oc vars x ->
    RifIO.write_outputs oc Util.my_string_of_float
      (List.map (fun v -> Var.name v, Type.to_data_t (Var.typ v)) vars) 
      (to_subst_list x)