Browse Source

Add some basic scheduling to delay matching of variables (+ bugfixes to rules)

Yentl Van Tendeloo 8 years ago
parent
commit
d5b2785fc1
3 changed files with 36 additions and 26 deletions
  1. 1 1
      kernel/rules/MvK_rules.mvc
  2. 34 24
      kernel/rules/to_python.alc
  3. 1 1
      wrappers/modelverse_SCCD.py

+ 1 - 1
kernel/rules/MvK_rules.mvc

@@ -488,7 +488,7 @@ Rule Call_Call_Params_N8 {
         value = "'IP'"
         value = "'IP'"
     }
     }
     MatchEdge (N8_3, N8_4) {
     MatchEdge (N8_3, N8_4) {
-        value = "!call"
+        value = "'IP'"
     }
     }
     CreateEdge (N8_3, N8_7) {
     CreateEdge (N8_3, N8_7) {
         value = "'finish'"
         value = "'finish'"

+ 34 - 24
kernel/rules/to_python.alc

@@ -128,6 +128,7 @@ Boolean function main(model : Element):
 		// For "delete" edges, we match using "RD" and "RDE"
 		// For "delete" edges, we match using "RD" and "RDE"
 		Element create_edges
 		Element create_edges
 		Element all_nodes
 		Element all_nodes
+		Element assigned
 
 
 		log("Matching rule " + rule)
 		log("Matching rule " + rule)
 		nodes = allAssociationDestinations(model, rule, "Rules/contains")
 		nodes = allAssociationDestinations(model, rule, "Rules/contains")
@@ -135,6 +136,10 @@ Boolean function main(model : Element):
 
 
 		create_edges = set_create()
 		create_edges = set_create()
 		explored = set_create()
 		explored = set_create()
+		assigned = set_create()
+		// Username is always assigned in the beginning
+		set_add(assigned, "username")
+		set_add(assigned, "taskname")
 		while (set_len(nodes) > 0):
 		while (set_len(nodes) > 0):
 			node = set_pop(nodes)
 			node = set_pop(nodes)
 			if (read_type(model, node) == "Rules/Root"):
 			if (read_type(model, node) == "Rules/Root"):
@@ -176,31 +181,36 @@ Boolean function main(model : Element):
 									result = result + "\t" + destination + "_DEL, = yield [('RDNE', [" + source + ", " + string_replace(node_key, "/", "_") + "])]\n"
 									result = result + "\t" + destination + "_DEL, = yield [('RDNE', [" + source + ", " + string_replace(node_key, "/", "_") + "])]\n"
 									result = result + "\tyield [('DE', [" + destination + "_DEL])]\n"
 									result = result + "\tyield [('DE', [" + destination + "_DEL])]\n"
 							else:
 							else:
-								if (set_in(explored, new_node)):
-									// Already visited this one in another way, so try to merge!
-									String rand
-									rand = random_string(10)
-									result = result + "\t" + rand + ", = yield [('RD', [" + source + ", " + name + "])]\n"
-									result = result + "\t" + "if " + rand + " != " + destination + ":\n"
-									// If the values don't agree, this is not a correct match, and we say that this element remains unmatched (i.e., assign None)
-									result = result + "\t" + "\t" + destination + " = None\n"
+								if (bool_or(string_get(name, 0) == "'", set_in(assigned, name))):
+									if (set_in(explored, new_node)):
+										// Already visited this one in another way, so try to merge!
+										String rand
+										rand = random_string(10)
+										result = result + "\t" + rand + ", = yield [('RD', [" + source + ", " + name + "])]\n"
+										result = result + "\t" + "if " + rand + " != " + destination + ":\n"
+										// If the values don't agree, this is not a correct match, and we say that this element remains unmatched (i.e., assign None)
+										result = result + "\t" + "\t" + destination + " = None\n"
+									else:
+										// First visit to this element, so just assign
+										result = result + "\t" + destination + ", = yield [('RD', [" + source + ", " + name + "])]\n"
+
+										String value
+										value = read_attribute(model, new_node, "value")
+										if (element_neq(value, read_root())):
+											// Match node has a value we should compare as well!
+											// Read out the value from the Modelverse
+											if (bool_and(string_get(value, 0) != "!", string_get(value, 0) != "'")):
+												result = result + "\t" + value + ", = yield [('RV', [" + destination + "])]\n"
+												set_add(assigned, value)
+
+										set_add(to_explore, new_node)
+
+									if (read_type(model, edge) == "Rules/DeleteEdge"):
+										// Delete edge
+										result = result + "\t" + destination + "_DEL, = yield [('RDE', [" + source + ", " + name + "])]\n"
+										result = result + "\tyield [('DE', [" + destination + "_DEL])]\n"
 								else:
 								else:
-									// First visit to this element, so just assign
-									result = result + "\t" + destination + ", = yield [('RD', [" + source + ", " + name + "])]\n"
-
-									String value
-									value = read_attribute(model, new_node, "value")
-									if (element_neq(value, read_root())):
-										// Match node has a value we should compare as well!
-										// Read out the value from the Modelverse
-										result = result + "\t" + destination + "_V, = yield [('RV', [" + destination + "])]\n"
-
-									set_add(to_explore, new_node)
-
-								if (read_type(model, edge) == "Rules/DeleteEdge"):
-									// Delete edge
-									result = result + "\t" + destination + "_DEL, = yield [('RDE', [" + source + ", " + name + "])]\n"
-									result = result + "\tyield [('DE', [" + destination + "_DEL])]\n"
+									set_add(remainder_to_explore, node)
 
 
 						if (bool_and(set_len(to_explore) == 0, set_len(remainder_to_explore) > 0)):
 						if (bool_and(set_len(to_explore) == 0, set_len(remainder_to_explore) > 0)):
 							to_explore = remainder_to_explore
 							to_explore = remainder_to_explore

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Mon Nov 27 10:48:12 2017
+Date:   Mon Nov 27 11:24:44 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server