Skip to content
Snippets Groups Projects
Commit 6929ab22 authored by erwan's avatar erwan
Browse files

Remove in Algo.varT the type N (that was meant for Natural number)

and reuse it for Neighbor, which make the naming more consistent.
parent fbd52394
No related branches found
No related tags found
No related merge requests found
(* Time-stamp: <modified the 09/03/2019 (at 11:41) by Erwan Jahier> *) (* Time-stamp: <modified the 10/03/2019 (at 20:35) by Erwan Jahier> *)
type t = { type t = {
pid : string; pid : string;
...@@ -29,7 +29,6 @@ let (make: Topology.node -> t) = ...@@ -29,7 +29,6 @@ let (make: Topology.node -> t) =
user_init_env nl v user_init_env nl v
| Some x -> ( | Some x -> (
match List.assoc_opt v vars with match List.assoc_opt v vars with
| Some(Algo.Neighbor)
| Some(Algo.It) | Some(Algo.It)
| Some(Algo.Nt) -> I (int_of_string x) | Some(Algo.Nt) -> I (int_of_string x)
| Some(Algo.Bt) -> B (bool_of_string x) | Some(Algo.Bt) -> B (bool_of_string x)
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
open Algo open Algo
let (algo_varT: Algo.varT -> string) = function let (algo_varT: Algo.varT -> string) = function
| It -> "int" | It -> "int"
| Nt -> "pos_int"
| Ft -> "float" | Ft -> "float"
| Bt -> "bool" | Bt -> "bool"
| Et i -> Printf.sprintf "enum(%d)" i | Et i -> Printf.sprintf "enum(%d)" i
| Neighbor -> "Neighbor" | Nt -> "Neighbor"
let (algo_vars : Algo.vars -> string) = fun vars -> let (algo_vars : Algo.vars -> string) = fun vars ->
String.concat "," (List.map (fun (n,t) -> Printf.sprintf "%s:%s" n (algo_varT t)) vars) String.concat "," (List.map (fun (n,t) -> Printf.sprintf "%s:%s" n (algo_varT t)) vars)
......
(* Time-stamp: <modified the 09/03/2019 (at 15:04) by Erwan Jahier> *) (* Time-stamp: <modified the 10/03/2019 (at 20:35) by Erwan Jahier> *)
(** Process programmer API *) (** Process programmer API *)
type varT = It | Nt | Ft | Bt | Et of int | Neighbor type varT = It | Nt | Ft | Bt | Et of int
type action = string (* juste un label *) type action = string (* juste un 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 | S of string | N of int
type local_env = string -> value type local_env = string -> value
...@@ -35,12 +35,11 @@ let tbls = { ...@@ -35,12 +35,11 @@ let tbls = {
let verbose_level = ref 0 let verbose_level = ref 0
let vart_to_rif_string = function let vart_to_rif_string = function
| It | It -> "int"
| Nt -> "int"
| Ft -> "real" | Ft -> "real"
| Bt -> "bool" | Bt -> "bool"
| Et _i -> "int" | Et _i -> "int"
| Neighbor -> "int" | Nt -> "int"
let value_to_string = function let value_to_string = function
| I i | I i
...@@ -80,11 +79,10 @@ let (get_init_vars : algo_id -> (string * varT) list -> (neighbor list -> local_ ...@@ -80,11 +79,10 @@ let (get_init_vars : algo_id -> (string * varT) list -> (neighbor list -> local_
(fun nl v -> (fun nl v ->
match List.find_opt (fun (x,_t) -> x=v) vars with match List.find_opt (fun (x,_t) -> x=v) vars with
None -> failwith (v^" unknown var") None -> failwith (v^" unknown var")
| Some(_,Neighbor) -> | Some(_,Nt) ->
assert (nl <> []); assert (nl <> []);
N (Random.int ((List.length nl)-1)) N (Random.int ((List.length nl)-1))
| Some(_,It) | Some(_,It) -> I (Random.int 100000)
| Some(_,Nt) -> I (Random.int 100000)
| Some(_,Bt) -> B (Random.bool ()) | Some(_,Bt) -> B (Random.bool ())
| Some(_,Ft) -> F (Random.float max_float) | Some(_,Ft) -> F (Random.float max_float)
| Some(_,Et i) -> I (Random.int i) | Some(_,Et i) -> I (Random.int i)
......
(* Time-stamp: <modified the 09/03/2019 (at 15:02) by Erwan Jahier> *) (* Time-stamp: <modified the 10/03/2019 (at 20:38) by Erwan Jahier> *)
(** Process programmer API *) (** Process programmer API *)
type value = I of int | F of float | B of bool | S of string type value = I of int | F of float | B of bool | S of string
| N of int (* neighbor canal number *) | N of int (* neighbor canal number *)
type local_env = string -> value (* XXX assez efficace ? *) type local_env = string -> value
type action = string (* label? *) type action = string (* label *)
type varT = It | Nt | Ft | Bt | Et of int | Neighbor type varT = It | Nt | Ft | Bt | Et of int
type vars = (string * varT) list type vars = (string * varT) list
type neighbor = { type neighbor = {
......
(* Time-stamp: <modified the 09/03/2019 (at 12:45) by Erwan Jahier> *) (* Time-stamp: <modified the 10/03/2019 (at 20:39) by Erwan Jahier> *)
(* This is algo 5.4 in the book *) (* This is algo 5.4 in the book *)
open Algo open Algo
let vars = ["d",It; "par",Neighbor ] let vars = ["d",It; "par",Nt ]
let d=10 let d=10
let (init_vars: neighbor list -> local_env) = let (init_vars: neighbor list -> local_env) =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment