lustrec / src / env.ml @ 22fe1c93
History | View | Annotate | Download (1.81 KB)
1 |
(* ---------------------------------------------------------------------------- |
---|---|
2 |
* SchedMCore - A MultiCore Scheduling Framework |
3 |
* Copyright (C) 2009-2011, ONERA, Toulouse, FRANCE - LIFL, Lille, FRANCE |
4 |
* |
5 |
* This file is part of Prelude |
6 |
* |
7 |
* Prelude is free software; you can redistribute it and/or |
8 |
* modify it under the terms of the GNU Lesser General Public License |
9 |
* as published by the Free Software Foundation ; either version 2 of |
10 |
* the License, or (at your option) any later version. |
11 |
* |
12 |
* Prelude is distributed in the hope that it will be useful, but |
13 |
* WITHOUT ANY WARRANTY ; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
* Lesser General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU Lesser General Public |
18 |
* License along with this program ; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
*---------------------------------------------------------------------------- *) |
22 |
|
23 |
(** Generic inference environments. Used both for typing and |
24 |
clock-calculus. *) |
25 |
open Utils |
26 |
|
27 |
(* Same namespace for nodes, variables and constants *) |
28 |
let initial = IMap.empty |
29 |
|
30 |
let add_value env ident ty = |
31 |
IMap.add ident ty env |
32 |
|
33 |
let lookup_value env ident = |
34 |
IMap.find ident env |
35 |
|
36 |
let exists_value env ident = |
37 |
IMap.mem ident env |
38 |
|
39 |
let overwrite x y = |
40 |
IMap.merge ( |
41 |
fun k _old _new -> match _new with |
42 |
| Some _ -> _new |
43 |
| _ -> _old |
44 |
) x y |
45 |
|
46 |
open Format |
47 |
|
48 |
let pp_env pp_fun fmt env = |
49 |
let (lid,lty) = list_of_imap env in |
50 |
let l' = List.combine lid lty in |
51 |
let pp_fun fmt (id,value) = |
52 |
Format.fprintf fmt "%s |-> %a" id pp_fun value |
53 |
in |
54 |
Format.fprintf fmt "{ @[<v 2>%a@] }" (fprintf_list ~sep:"@," pp_fun) l' |
55 |
|
56 |
(* Local Variables: *) |
57 |
(* compile-command:"make -C .." *) |
58 |
(* End: *) |