Skip to content

Commit

Permalink
print guards in site_graph and translate_to_natural_language and handler
Browse files Browse the repository at this point in the history
  • Loading branch information
reb-ddm committed Jan 21, 2025
1 parent 16c7bce commit 03412de
Show file tree
Hide file tree
Showing 12 changed files with 804 additions and 662 deletions.
6 changes: 3 additions & 3 deletions core/KaSa_rep/backend/ckappa_site_graph.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ let print_internal_pattern ?logger parameters error kappa_handler list =
let print_for_list logger parameter error t =
let error, _ =
List.fold_left
(fun (error, bool) (agent_string, site_map) ->
(fun (error, bool) ((agent_string, site_map), guard_map) ->
let error =
Site_graphs.KaSa_site_graph.print_agent logger parameter error
agent_string site_map bool
agent_string site_map guard_map bool
in
error, true)
(error, false) t
Expand Down Expand Up @@ -172,7 +172,7 @@ let _print_pattern ?logger parameters error _kappa_handler list =
let site_graph_to_list error string_version =
let error, current_list =
Ckappa_sig.Agent_id_map_and_set.Map.fold
(fun _ (agent_string, site_map) (error, current_list) ->
(fun _ ((agent_string, site_map), _guardmap) (error, current_list) ->
(*-----------------------------------------*)
let site_graph = (agent_string, site_map) :: current_list in
error, site_graph)
Expand Down
11 changes: 6 additions & 5 deletions core/KaSa_rep/backend/ckappa_site_graph.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ val print_internal_pattern :

val site_graph_to_list :
Exception.exceptions_caught_and_uncaught ->
(string
* (string option
* Site_graphs.KaSa_site_graph.binding_state option
* (int option * int option) option)
Wrapped_modules.LoggedStringMap.t)
((string
* (string option
* Site_graphs.KaSa_site_graph.binding_state option
* (int option * int option) option)
Wrapped_modules.LoggedStringMap.t)
* string option Wrapped_modules.LoggedStringMap.t)
Ckappa_sig.Agent_id_map_and_set.Map.t ->
Exception.exceptions_caught_and_uncaught
* (string
Expand Down
21 changes: 20 additions & 1 deletion core/KaSa_rep/frontend/ckappa_sig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ let next_link_value (i : c_link_value) : c_link_value = i + 1
let site_name_of_int (a : int) : c_site_name = a
let int_of_site_name (a : c_site_name) : int = a
let string_of_site_name (a : c_site_name) : string = string_of_int a
let string_of_guard_p_then_site (a : c_guard_p_then_site) : string = string_of_int a

let string_of_guard_p_then_site (a : c_guard_p_then_site) : string =
string_of_int a

let string_of_site_or_guard (a : c_site_or_guard_p) : string =
match a with
Expand Down Expand Up @@ -238,6 +240,16 @@ let agent_id_of_int (a : int) : c_agent_id = a
let string_of_agent_id (a : c_agent_id) : string = string_of_int a
let string_of_c_link_value (a : c_link_value) : string = string_of_int a

let bool_of_state_index parameter error (a : c_state) =
match a with
| 0 -> error, false
| 1 -> error, true
| _ -> Exception.warn parameter error __POS__ Exit false

let string_of_guard_state parameter error (a : c_state) =
let error, bool = bool_of_state_index parameter error a in
error, string_of_bool bool

let get_agent_shape n_sites parameters =
Misc_sa.fetch_array (int_of_site_name n_sites)
(Remanent_parameters.get_agent_shape_array parameters)
Expand Down Expand Up @@ -869,6 +881,13 @@ module Site_map_and_set = Map_wrapper.Make (SetMap.Make (struct
let print = Format.pp_print_int
end))

module GuardP_map_and_set = Map_wrapper.Make (SetMap.Make (struct
type t = c_guard_parameter

let compare = compare
let print = Format.pp_print_int
end))

module GuardSite_map_and_set = Map_wrapper.Make (SetMap.Make (struct
type t = c_guard_p_then_site

Expand Down
15 changes: 15 additions & 0 deletions core/KaSa_rep/frontend/ckappa_sig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ val string_of_state_index_option_min :
val string_of_state_index_option_max :
Remanent_parameters_sig.parameters -> c_state option -> string

val bool_of_state_index :
Remanent_parameters_sig.parameters ->
Exception_without_parameter.exceptions_caught_and_uncaught ->
c_state ->
Exception_without_parameter.exceptions_caught_and_uncaught * bool

val string_of_guard_state :
Remanent_parameters_sig.parameters ->
Exception_without_parameter.exceptions_caught_and_uncaught ->
c_state ->
Exception_without_parameter.exceptions_caught_and_uncaught * counter_name

val int_of_rule_id : c_rule_id -> int
val rule_id_of_int : int -> c_rule_id
val string_of_rule_id : c_rule_id -> string
Expand Down Expand Up @@ -392,6 +404,9 @@ module Site_map_and_set : Map_wrapper.S_with_logs with type elt = c_site_name
module GuardSite_map_and_set :
Map_wrapper.S_with_logs with type elt = c_guard_p_then_site

module GuardP_map_and_set :
Map_wrapper.S_with_logs with type elt = c_guard_parameter

type c_interface = c_port Site_map_and_set.Map.t

type c_proper_agent = {
Expand Down
50 changes: 40 additions & 10 deletions core/KaSa_rep/frontend/handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let nrules _parameter _error handler = handler.Cckappa_sig.nrules
let nvars _parameter _error handler = handler.Cckappa_sig.nvars
let nagents _parameter _error handler = handler.Cckappa_sig.nagents
let get_nr_guard_parameters handler = handler.Cckappa_sig.nguard_params
let get_guard_parameters handler = handler.Cckappa_sig.guard_parameters

let check_pos parameter ka_pos ml_pos message error error' =
match ml_pos with
Expand Down Expand Up @@ -563,6 +564,19 @@ let string_of_state = string_of_state_gen print_state
let string_of_state_fully_deciphered =
string_of_state_gen print_state_fully_deciphered

let string_of_state_fully_deciphered_with_guard parameter error handler_kappa
agent_name site_or_guard state =
let nr_guard_params = get_nr_guard_parameters handler_kappa in
match
Ckappa_sig.site_or_guard_p_of_guard_p_then_site site_or_guard
nr_guard_params
with
| Ckappa_sig.Site site_name ->
string_of_state_gen print_state_fully_deciphered parameter error
handler_kappa agent_name site_name state
| Ckappa_sig.Guard_p _ ->
Ckappa_sig.string_of_guard_state parameter error state

let string_of_site_aux ?(ml_pos = None) ?(ka_pos = None) ?(message = "")
parameter error handler_kappa ?state agent_name
(site_int : Ckappa_sig.c_site_name) =
Expand All @@ -587,19 +601,17 @@ let string_of_site parameter error handler_kappa ?state
in
error, print_site parameter ?state ~add_parentheses site_type

let string_of_guard g guard_params ?state error =
let string_of_guard parameter guardp guard_params ?state error =
let guard_param_name =
List.nth guard_params (Ckappa_sig.int_of_guard_parameter g)
List.nth guard_params (Ckappa_sig.int_of_guard_parameter guardp)
in
match state with
| None -> error, guard_param_name
| Some s ->
(match Ckappa_sig.int_of_state_index s with
| 0 -> error, guard_param_name ^ "{false}"
| 1 -> error, guard_param_name ^ "{true}"
| _ -> error, guard_param_name ^ "{undefined}")

(*rTODO error handling*)
let error, guard_string =
Ckappa_sig.string_of_guard_state parameter error s
in
error, guard_param_name ^ "{" ^ guard_string ^ "}"

let string_of_site_or_guard parameter error handler_kappa ?state
?(add_parentheses = false) agent_type site_int =
Expand All @@ -608,7 +620,8 @@ let string_of_site_or_guard parameter error handler_kappa ?state
string_of_site parameter error handler_kappa ?state ~add_parentheses
agent_type s
| Ckappa_sig.Guard_p g ->
string_of_guard g handler_kappa.Cckappa_sig.guard_parameters ?state error
string_of_guard parameter g handler_kappa.Cckappa_sig.guard_parameters
?state error

(*this function used in views_domain*)
let string_of_site_update_views parameter error handler_kappa agent_type
Expand All @@ -629,6 +642,23 @@ let string_of_site_in_natural_language parameter error handler_kapp agent_type
| Ckappa_sig.Binding x -> error, "the binding state of site " ^ x
| Ckappa_sig.Counter x -> error, "the value of counter " ^ x

let string_of_site_or_guard_in_natural_language parameter error handler_kapp
agent_type (site_or_guard_int : Ckappa_sig.c_guard_p_then_site) =
let nr_guard_parameters = get_nr_guard_parameters handler_kapp in
let guard_parameters = get_guard_parameters handler_kapp in
match
Ckappa_sig.site_or_guard_p_of_guard_p_then_site site_or_guard_int
nr_guard_parameters
with
| Ckappa_sig.Site site_int ->
string_of_site_in_natural_language parameter error handler_kapp agent_type
site_int
| Ckappa_sig.Guard_p guardp ->
let error, string =
string_of_guard parameter guardp guard_parameters error
in
error, "the value of the guard parameter " ^ string

let string_of_site_in_file_name parameter error handler_kapp agent_type
(site_int : Ckappa_sig.c_site_name) =
let error, site_type, _ =
Expand Down Expand Up @@ -658,7 +688,7 @@ let string_of_site_or_guard_contact_map ?(ml_pos = None) ?(ka_pos = None)
string_of_site_contact_map ~ml_pos ~ka_pos ~message parameter error
handler_kappa agent_name s
| Ckappa_sig.Guard_p g ->
string_of_guard g handler_kappa.Cckappa_sig.guard_parameters error
string_of_guard parameter g handler_kappa.Cckappa_sig.guard_parameters error

let print_labels parameters error handler couple =
let _ = Quark_type.Labels.dump_couple parameters error handler couple in
Expand Down
19 changes: 19 additions & 0 deletions core/KaSa_rep/frontend/handler.mli
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ val string_of_site_in_natural_language :
Ckappa_sig.c_site_name ->
Exception_without_parameter.exceptions_caught_and_uncaught * string

val string_of_site_or_guard_in_natural_language :
Remanent_parameters_sig.parameters ->
Exception_without_parameter.exceptions_caught_and_uncaught ->
Cckappa_sig.kappa_handler ->
Quark_type.agent_quark ->
Ckappa_sig.c_guard_p_then_site ->
Exception_without_parameter.exceptions_caught_and_uncaught * string

val string_of_state :
Remanent_parameters_sig.parameters ->
Exception_without_parameter.exceptions_caught_and_uncaught ->
Expand All @@ -286,6 +294,15 @@ val string_of_state_fully_deciphered :
Ckappa_sig.c_state ->
Exception_without_parameter.exceptions_caught_and_uncaught * string

val string_of_state_fully_deciphered_with_guard :
Remanent_parameters_sig.parameters ->
Exception_without_parameter.exceptions_caught_and_uncaught ->
Cckappa_sig.kappa_handler ->
Ckappa_sig.c_agent_name ->
Ckappa_sig.c_guard_p_then_site ->
Ckappa_sig.c_state ->
Exception_without_parameter.exceptions_caught_and_uncaught * string

val string_of_rule :
?with_rule:bool ->
?with_rule_name:bool ->
Expand Down Expand Up @@ -453,3 +470,5 @@ val nrules :
Exception_without_parameter.exceptions_caught_and_uncaught ->
Cckappa_sig.kappa_handler ->
int

val get_nr_guard_parameters : Cckappa_sig.kappa_handler -> int
Loading

0 comments on commit 03412de

Please sign in to comment.