Skip to content
Snippets Groups Projects
env.ml 1.03 KiB
Newer Older
erwan's avatar
erwan committed
(* Time-stamp: <modified the 06/06/2019 (at 11:14) by Erwan Jahier> *)
erwan's avatar
erwan committed

module Dico = Map.Make(String)

open Algo
type t = local_env Dico.t 

erwan's avatar
erwan committed
let (nget: t -> string -> Algo.local_env) =
  fun e pid  ->
    Printf.printf "get pid %s\n" pid; flush stdout;
    try ((Dico.find pid e) )
    with Not_found -> failwith (Printf.sprintf "Unknown pid: %s" pid)
erwan's avatar
erwan committed
let (get: t -> string -> string -> value) =
  fun e pid v ->
    try ((Dico.find pid e) v)
    with _ -> failwith (Printf.sprintf "Unknown value: %s.%s" pid v)
erwan's avatar
erwan committed
let (nget_copy: Algo.vars -> t -> string -> Algo.local_env) =
  fun vars e pid ->
    Algo.copy_local_env vars (get e pid)
      
erwan's avatar
erwan committed
let (get_copy: Algo.vars -> t -> string -> string -> value) =
  fun vars e pid ->
    Algo.copy_local_env vars (get e pid)
erwan's avatar
erwan committed
let (nset: t -> string -> Algo.local_env -> t) =
  fun e pid lenv ->
    Dico.add pid lenv e
erwan's avatar
erwan committed
let (set: t -> string -> string -> value -> t) =
  fun e pid v value ->
    Dico.add pid (fun x -> if x=v then value else Dico.find pid e x) e

let (init:unit -> t) = fun () -> Dico.empty