瀏覽代碼

Add code to idle when no rules match (necessary for the input case if
there is no input available)

Yentl Van Tendeloo 7 年之前
父節點
當前提交
b5cd97e2e6
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      kernel/rules/to_python.alc

+ 8 - 1
kernel/rules/to_python.alc

@@ -84,12 +84,15 @@ Boolean function main(model : Element):
 				remainder_to_explore = set_create()
 
 	rules = allInstances(model, "Rules/Rule")
+	result = result + "if (False):\n"
+	result = result + "\t# here to make code generation nicer...\n"
+	result = result + "\tpass\n"
 	while (set_len(rules) > 0):
 		// Check if this rule is applicable
 		rule = set_pop(rules)
 
 		// Fetch all elements with a "match" label and check that they are not None (and possibly, that they have a value)
-		result = result + "if (True "
+		result = result + "elif (True "
 		nodes = allAssociationDestinations(model, rule, "Rules/contains")
 		while (set_len(nodes) > 0):
 			node = set_pop(nodes)
@@ -217,6 +220,10 @@ Boolean function main(model : Element):
 			else:
 				result = result + "\t" + string_replace(edge, "/", "_") + ", = yield [('CE', [" + string_replace(readAssociationSource(model, edge), "/", "_") + ", " + string_replace(readAssociationDestination(model, edge), "/", "_") + "])]\n"
 
+	result = result + "else:\n"
+	result = result + "\t# no rules were applicable, so idle for some time\n"
+	result = result + "\tTODO
+
 	log("Got result:")
 	log(result)
 	return True!