From 341c4a6e33499c52bc38754bad7ee07d2af74e09 Mon Sep 17 00:00:00 2001 From: Erwan Jahier <erwan.jahier@univ-grenoble-alpes.fr> Date: Mon, 11 Mar 2019 10:50:28 +0100 Subject: [PATCH] Clean up the algo.mli w.r.t. to possible varT and values --- bin/process.ml | 4 +++- bin/stringOf.ml | 1 + lib/algo/algo.ml | 10 +++++++--- lib/algo/algo.mli | 27 ++++++++++++++------------- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/bin/process.ml b/bin/process.ml index 5db5a022..1994865b 100644 --- a/bin/process.ml +++ b/bin/process.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 10/03/2019 (at 22:47) by Erwan Jahier> *) +(* Time-stamp: <modified the 11/03/2019 (at 10:41) by Erwan Jahier> *) type t = { pid : string; @@ -33,6 +33,8 @@ let (make: bool -> Topology.node -> t) = | 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) + | Some(Algo.St) -> S "dummy" + | None -> failwith (Printf.sprintf "%s is not a variable of program %s" v cmxs) ) diff --git a/bin/stringOf.ml b/bin/stringOf.ml index 228fa5a5..e584b19f 100644 --- a/bin/stringOf.ml +++ b/bin/stringOf.ml @@ -6,6 +6,7 @@ let (algo_varT: Algo.varT -> string) = function | Bt -> "bool" | Et i -> Printf.sprintf "enum(%d)" i | Nt -> "Neighbor" + | St -> "string" let (algo_vars : Algo.vars -> string) = fun vars -> String.concat "," (List.map (fun (n,t) -> Printf.sprintf "%s:%s" n (algo_varT t)) vars) diff --git a/lib/algo/algo.ml b/lib/algo/algo.ml index 840a3c3e..a6ca9b09 100644 --- a/lib/algo/algo.ml +++ b/lib/algo/algo.ml @@ -1,9 +1,9 @@ -(* Time-stamp: <modified the 10/03/2019 (at 20:46) by Erwan Jahier> *) +(* Time-stamp: <modified the 11/03/2019 (at 10:40) by Erwan Jahier> *) (** Process programmer API *) -type varT = It | Nt | Ft | Bt | Et of int +type varT = It | Ft | Bt | Et of int | St | Nt type action = string (* just a label *) -type value = I of int | F of float | B of bool | S of string | N of int +type value = I of int | F of float | B of bool | E of int | S of string | N of int type local_env = string -> value type vars = (string * varT) list @@ -40,11 +40,13 @@ let vart_to_rif_string = function | It -> "int" | Ft -> "real" | Bt -> "bool" + | St -> "string" | Et _i -> "int" | Nt -> "int" let value_to_string = function | I i + | E i | N i -> string_of_int i | F f -> string_of_float f | B true -> "t" @@ -88,6 +90,8 @@ let (get_init_vars : algo_id -> (string * varT) list -> (neighbor list -> local_ | Some(_,Bt) -> B (Random.bool ()) | Some(_,Ft) -> F (Random.float max_float) | Some(_,Et i) -> I (Random.int i) + | Some(_,St) -> S "dummy" + ) in try diff --git a/lib/algo/algo.mli b/lib/algo/algo.mli index e9328546..66409efb 100644 --- a/lib/algo/algo.mli +++ b/lib/algo/algo.mli @@ -1,13 +1,13 @@ -(* Time-stamp: <modified the 10/03/2019 (at 20:47) by Erwan Jahier> *) +(* Time-stamp: <modified the 11/03/2019 (at 10:38) by Erwan Jahier> *) (** Process programmer API *) -type value = I of int | F of float | B of bool | S of string +type varT = It | Ft | Bt | Et of int | St | Nt +type vars = (string * varT) list + +type value = I of int | F of float | B of bool | E of int | S of string | N of int (* neighbor canal number *) type local_env = string -> value type action = string (* label *) - -type varT = It | Nt | Ft | Bt | Et of int -type vars = (string * varT) list type neighbor = { lenv: local_env; @@ -15,37 +15,38 @@ type neighbor = { } type enable_fun = neighbor list -> local_env -> action list -type step_fun = neighbor list -> local_env -> action -> local_env - +type step_fun = neighbor list -> local_env -> action -> local_env (** Those 3 registering functions must be called! *) -type algo_id = string (* XXX comment s'en passer ??? *) +type algo_id = string val reg_vars : algo_id -> vars -> unit val reg_enable : algo_id -> enable_fun -> unit val reg_step : algo_id -> step_fun -> unit -(** nb: The initialisation done in the dot file have priority over this one *) +(** raised by sasa if one of the function above is not called *) +exception Unregistred of string * string + +(** This one is not mandatory. The initialisation done in the dot + file have priority over this one. *) val reg_init_vars : algo_id -> (neighbor list -> local_env) -> unit +(** Mandatory in custom mode only. *) val reg_actions : algo_id -> action list -> unit (** util(s) *) val value_to_string : value -> string - (**/**) +(** functions below are not part of the API *) val vart_to_rif_string: varT -> string val verbose_level: int ref -(** raised by get_* functions *) -exception Unregistred of string * string (** the following functions are used by sasa *) val get_vars : algo_id -> vars val get_enable : algo_id -> enable_fun val get_step : algo_id -> step_fun - val get_init_vars : algo_id -> (string * varT) list -> (neighbor list -> local_env) val get_actions : algo_id -> action list -- GitLab