@@ -16,26 +16,16 @@ type agent = (string * port list)
16
16
17
17
type mixture = agent list
18
18
19
- type lnk_or_int = INT of string
20
- | LNK of link
21
-
22
- type q = int * string * lnk_or_int
23
-
24
- type quarks = Tested of q list
25
- | TestedMod of (q * q) list
26
- | Modified of q list
27
-
28
19
type rule = {
29
20
lhs : mixture ;
30
21
bidirectional : bool ;
31
22
rhs : mixture ;
32
- prefix_map : quarks list ;
33
23
}
24
+
34
25
type t = INIT of mixture
35
26
| OBS of string * mixture
36
27
| RULE of string * rule
37
28
38
-
39
29
let add_free_to_port_lnk plinks = match plinks with
40
30
| [] -> [FREE ]
41
31
| ls -> ls
@@ -53,25 +43,35 @@ let add_free_to_mix mix =
53
43
let split_ports_quarks count port =
54
44
let quark_int = match port.port_int with
55
45
| [] -> []
56
- | s ::_ -> [(count,port.port_nme,(INT s))] in
46
+ | s ::_ -> [(count,port.port_nme,(Rule. INT s))] in
57
47
match port.port_lnk with
58
48
| [] -> []
59
- | l ::_ -> (count,port.port_nme,(LNK l))::quark_int
49
+ | l ::_ -> match l with
50
+ | LNK_VALUE i ->
51
+ let rule_lnk = Rule. LNK (Idgraph. LNK_VALUE i) in
52
+ (count,port.port_nme,rule_lnk)::quark_int
53
+ | FREE ->
54
+ let rule_lnk = Rule. LNK (Idgraph. FREE ) in
55
+ (count,port.port_nme,rule_lnk)::quark_int
56
+ | LNK_ANY -> quark_int
57
+ | LNK_SOME | LNK_TYPE _ ->
58
+ (raise (ExceptionDefn. Not_Supported
59
+ (" rules with side effects not supported" )))
60
60
61
61
let create_quarks mixture count =
62
62
List. fold_left
63
- (fun (qs ,agent_names ,count ) (name ,plist ) ->
63
+ (fun (qs ,agent_names ,count ) (( name :string ) ,plist ) ->
64
64
let qs' =
65
65
List. fold_left
66
66
(fun acc port -> (split_ports_quarks count port)@ acc) [] plist in
67
- (qs'@ qs,(name, count)::agent_names,count+ 1 ))
67
+ (qs'@ qs,(count,name )::agent_names,count+ 1 ))
68
68
([] ,[] ,count) mixture
69
69
70
70
let create_rhs_quarks agent_names mixture =
71
71
let rec aux qs mixt count ag_nm =
72
72
match mixt with
73
73
| (name ,plist )::mixt' ->
74
- if (List. mem (name, count) ag_nm) then
74
+ if (List. mem (count,name ) ag_nm) then
75
75
let qs' =
76
76
List. fold_left
77
77
(fun acc port -> (split_ports_quarks count port)@ acc) [] plist in
@@ -83,7 +83,7 @@ let create_rhs_quarks agent_names mixture =
83
83
aux [] mixture 0 agent_names
84
84
85
85
let match_il il il' = match (il,il') with
86
- | (INT _ ,INT _ ) | (LNK _ ,LNK _ ) -> true
86
+ | (Rule. INT _ ,Rule. INT _ ) | (Rule. LNK _ ,Rule. LNK _ ) -> true
87
87
| _ -> false
88
88
89
89
let remove_quark (n ,p ,il ) ls =
@@ -95,52 +95,55 @@ let partition_quarks lhs_quarks rhs_quarks =
95
95
let find (n ,p ,il ) rhs =
96
96
List. find (fun (n' ,p' ,il' ) ->
97
97
(n= n')&& (String. equal p p')&& (match_il il il')) rhs in
98
- let (tested,tested_mod ,rhs)=
98
+ let (qlist ,rhs)=
99
99
List. fold_left
100
- (fun (tested ,tested_mod ,rhs ) (n ,p ,il ) ->
101
- if (List. mem (n,p,il) rhs_quarks) then
102
- (((n,p,il)::tested),tested_mod,(remove_quark (n,p,il) rhs))
100
+ (fun (qlist' ,rhs' ) (n ,p ,il ) ->
101
+ if (List. mem (n,p,il) rhs') then
102
+ let new_quark = Rule. Tested (n,p,il) in
103
+ (new_quark::qlist',(remove_quark (n,p,il) rhs'))
103
104
else
104
105
let (n',p',il') =
105
- (try (find (n,p,il) rhs)
106
+ (try (find (n,p,il) rhs' )
106
107
with _ ->
107
108
(raise
108
109
(ExceptionDefn. Syntax_Error
109
110
(" agent does not have the same ports in lhs and rhs" )))) in
110
- (tested,(( n,p,il),(n',p',il'))::tested_mod,
111
- ( remove_quark (n,p,il) rhs)))
112
- ([] ,[] , rhs_quarks) lhs_quarks in
113
- let () =
114
- List. iter ( fun ( ag , _ , _ ) ->
115
- List. iter
116
- ( fun ( ag' , _ , _ ) ->
117
- if (ag= ag' ) then
118
- (raise
119
- (ExceptionDefn. Syntax_Error
120
- (" agent does not have the same ports
121
- in lhs and rhs" )))) rhs)
122
- tested in
123
- (tested,tested_mod,rhs )
111
+ let new_quark = Rule. TestedMod (( n,p,il),(n',p',il')) in
112
+ (new_quark::qlist',( remove_quark (n,p,il) rhs' )))
113
+ ([] ,rhs_quarks) lhs_quarks in
114
+ let modified =
115
+ List. map
116
+ ( fun (( ag , _ , _ ) as q ) ->
117
+ let () =
118
+ List. iter ( fun q -> if (ag= ( Rule. get_agent q) ) then
119
+ (raise
120
+ (ExceptionDefn. Syntax_Error
121
+ (" agent does not have the same ports
122
+ in lhs and rhs" )))) qlist in
123
+ Rule. Modified q) rhs in
124
+ (modified @ qlist )
124
125
125
126
let create_prefix_map lhs rhs =
126
127
let (lhs_quarks,lhs_agent_nm,_) = create_quarks lhs 0 in
127
128
let (rhs_quarks,rhs_agent_nm) = create_rhs_quarks lhs_agent_nm rhs in
128
- let (t_quarks,tm_quarks,m_quarks) =
129
- partition_quarks lhs_quarks rhs_quarks in
130
- [Tested t_quarks; TestedMod tm_quarks; Modified m_quarks]
131
-
132
- let clean_rules = function
133
- | INIT mix -> INIT (add_free_to_mix mix)
134
- | OBS (name ,mix ) -> OBS (name,add_free_to_mix mix)
129
+ (partition_quarks lhs_quarks rhs_quarks,rhs_agent_nm)
130
+
131
+ let clean_rule = function
132
+ | INIT mix ->
133
+ let (quarks,agent_names) = create_prefix_map (add_free_to_mix mix) [] in
134
+ let label = List. fold_left (fun acc (nme ,_ ) -> acc^ nme) " " mix in
135
+ Rule. INIT (label,quarks,agent_names)
136
+ | OBS (name ,mix ) ->
137
+ let (quarks,agent_names) = create_prefix_map [] (add_free_to_mix mix) in
138
+ Rule. OBS (name,quarks,agent_names)
135
139
| RULE (name ,r ) ->
136
140
let () = if (r.bidirectional) then
137
141
(raise (ExceptionDefn. Not_Supported
138
142
(" bidirectional rules not supported" ))) in
139
143
let lhs = add_free_to_mix r.lhs in
140
144
let rhs = add_free_to_mix r.rhs in
141
- let r' = {lhs; bidirectional= r.bidirectional;rhs;
142
- prefix_map = (create_prefix_map lhs rhs)} in
143
- RULE (name,r')
145
+ let (quarks,agent_names) = create_prefix_map lhs rhs in
146
+ Rule. RULE (name,quarks,agent_names)
144
147
145
148
let print_link = function
146
149
| LNK_VALUE i -> Format. printf " !%d" i
@@ -149,27 +152,6 @@ let print_link = function
149
152
| LNK_SOME -> Format. printf " !_"
150
153
| LNK_TYPE (i ,a ) -> Format. printf " !%s.%s" i a
151
154
152
- let print_quarks qs =
153
- let print_q (n ,p ,il ) =
154
- Format. printf " (%d,%s," n p;
155
- (match il with
156
- INT i -> Format. printf " int=%s " i
157
- | LNK lnk ->
158
- Format. printf " lnk= " ; print_link lnk);
159
- Format. printf " )" in
160
- let print_qlist qlist =
161
- List. iter (fun q -> print_q q) qlist in
162
- match qs with
163
- | Tested qlist ->
164
- Format. printf " \n Tested: " ; print_qlist qlist
165
- | Modified qlist ->
166
- Format. printf " \n Modified: " ; print_qlist qlist
167
- | TestedMod qqlist ->
168
- Format. printf " \n TestedMod " ;
169
- List. iter (fun (q1 ,q2 ) ->
170
- Format. printf" [before = " ;print_q q1;Format. printf " ] " ;
171
- Format. printf" [after = " ;print_q q2;Format. printf " ] " ) qqlist
172
-
173
155
let print_port p =
174
156
Format. printf " %s~[" p.port_nme;
175
157
List. iter (fun intern -> Format. printf " %s " intern;) p.port_int;
@@ -185,42 +167,13 @@ let print_rule r =
185
167
List. iter (fun a -> print_agent a) r.lhs;
186
168
if (r.bidirectional) then Format. printf " <-> "
187
169
else Format. printf " -> " ;
188
- List. iter (fun a -> print_agent a) r.rhs;
189
- List. iter (fun quarks -> print_quarks quarks) r.prefix_map
170
+ List. iter (fun a -> print_agent a) r.rhs
190
171
191
172
let print = function
192
173
| INIT mix -> Format. printf " \n init " ; List. iter (fun a -> print_agent a) mix
193
174
| OBS (name ,mix ) -> Format. printf " \n obs '%s' " name;
194
175
List. iter (fun a -> print_agent a) mix
195
176
| RULE (name ,r ) -> Format. printf " \n rule '%s' " name; print_rule r
196
177
197
- let empty_rule = {lhs = [] ;rhs= [] ;bidirectional= false ;prefix_map= [] }
198
-
178
+ let empty_rule = {lhs = [] ;rhs= [] ;bidirectional= false ;}
199
179
let empty = RULE (" empty" ,empty_rule)
200
-
201
- let get_label = function
202
- | INIT mix -> List. fold_left (fun acc (nme ,_ ) -> acc^ nme) " " mix
203
- | OBS (name ,_ ) -> name
204
- | RULE (name ,_ ) -> name
205
-
206
- let get_rule_by_label nme rules =
207
- List. find
208
- (fun r -> String. equal (get_label r) nme) rules
209
-
210
- let get_lhs = function
211
- | INIT mix -> []
212
- | OBS (name ,mix ) -> mix
213
- | RULE (name ,r ) -> r.lhs
214
-
215
- let get_rhs = function
216
- | INIT mix -> mix
217
- | OBS (name ,mix ) -> mix
218
- | RULE (name ,r ) -> r.rhs
219
-
220
- let is_init = function
221
- | INIT _ -> true
222
- | OBS _ | RULE _ -> false
223
-
224
- let is_obs = function
225
- | OBS _ -> true
226
- | INIT _ | RULE _ -> false
0 commit comments