Skip to content
Snippets Groups Projects
env.ml 763 B
Newer Older
(* Time-stamp: <modified the 09/05/2019 (at 21:52) by Erwan Jahier> *)
erwan's avatar
erwan committed

module Dico = Map.Make(String)

open Algo
type t = local_env Dico.t 

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)



let rec (copy_value : value -> value) =
  fun v ->
    match v with 
    | I _ | F _ | B _ | E _ | S _ | N _ -> v
    | A a -> A (Array.copy (Array.map copy_value a))

let (get_copy: t -> string -> string -> value) =
  fun e pid v ->
    copy_value (get e pid v)
    

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