Skip to content
Snippets Groups Projects
process.ml 1.62 KiB
Newer Older
(* Time-stamp: <modified the 10/03/2019 (at 20:35) by Erwan Jahier> *)
erwan's avatar
erwan committed

type t = {
  pid : string;
  variables : Algo.vars;
  init : Algo.neighbor list -> Algo.local_env;
erwan's avatar
erwan committed
  enable : Algo.enable_fun;
  step : Algo.step_fun ;
  (* le demon choisi quelle action activer *)
}

(** called by sasa ; not part of the process programmer API *)
let (make: Topology.node -> t) =
  fun n ->
    let pid = n.Topology.id in
    let cmxs = n.Topology.file in
    let id = Filename.chop_suffix cmxs ".cmxs" in
    if !Algo.verbose_level > 0 then Printf.printf "Loading %s...\n" cmxs;
    (* TODO: should I prevent the same cmxs to be loaded twice? Not clear. *)
    Dynlink.loadfile cmxs;
    let vars = Algo.get_vars id in
    let user_init_env = Algo.get_init_vars id vars in
    (* let (string_to_value: string -> Algo.value) = *)
    let init_env nl v =
erwan's avatar
erwan committed
      match List.assoc_opt v n.Topology.init with
        None ->
        if !Algo.verbose_level > 1 then
          Printf.eprintf "No init value for '%s' found in the graph.\n" v;
        user_init_env nl v
erwan's avatar
erwan committed
      | Some x -> (
            match List.assoc_opt v vars with
            | Some(Algo.It)
            | Some(Algo.Nt) -> I (int_of_string x)
            | Some(Algo.Bt) -> B (bool_of_string x)
            | Some(Algo.Ft) -> F (float_of_string x)
            | Some(Algo.Et _i) -> I (int_of_string x)
            | None ->
              failwith (Printf.sprintf "%s is not a variable of program %s" v cmxs)
          )
erwan's avatar
erwan committed
    in 
    let process = {
      pid = pid; 
      variables = vars ;
      init = init_env ;
      enable = Algo.get_enable id; 
      step = Algo.get_step id;
    }
    in
    process