Forráskód Böngészése

Use operators in pn_interface.alc

Yentl Van Tendeloo 9 éve
szülő
commit
dd4f217e00
1 módosított fájl, 60 hozzáadás és 58 törlés
  1. 60 58
      integration/code/pn_interface.alc

+ 60 - 58
integration/code/pn_interface.alc

@@ -126,24 +126,24 @@ String function petrinet_constraints(pn_mo : Element):
 	Element all_elems
 	Element elem_constraint
 	all_elems = allInstances(pn_mo, dict_read(dict_read(dict_read(pn_mo, "metamodel"), "model"), "Place"))
-	while (integer_lt(0, read_nr_out(all_elems))):
+	while (0 < read_nr_out(all_elems)):
 		elem_constraint = set_pop(all_elems)
 		if (integer_lt(readAttribute(pn_mo, elem_constraint, "tokens"), 0)):
-			return string_join("Negative number of tokens in Place ", getName(pn_mo, elem_constraint))
+			return "Negative number of tokens in Place " + getName(pn_mo, elem_constraint)
 
 	// Check P2T transitions to have positive weight
 	all_elems = allInstances(pn_mo, dict_read(dict_read(dict_read(pn_mo, "metamodel"), "model"), "P2T"))
-	while (integer_lt(0, read_nr_out(all_elems))):
+	while (0 < read_nr_out(all_elems)):
 		elem_constraint = set_pop(all_elems)
 		if (integer_lt(readAttribute(pn_mo, elem_constraint, "weight"), 0)):
-			return string_join("Negative weight in arc ", getName(pn_mo, elem_constraint))
+			return "Negative weight in arc " + getName(pn_mo, elem_constraint)
 
 	// Check T2P transitions to have positive weight
 	all_elems = allInstances(pn_mo, dict_read(dict_read(dict_read(pn_mo, "metamodel"), "model"), "T2P"))
-	while (integer_lt(0, read_nr_out(all_elems))):
+	while (0 < read_nr_out(all_elems)):
 		elem_constraint = set_pop(all_elems)
 		if (integer_lt(readAttribute(pn_mo, elem_constraint, "weight"), 0)):
-			return string_join("Negative weight in arc ", getName(pn_mo, elem_constraint))
+			return "Negative weight in arc " + getName(pn_mo, elem_constraint)
 
 	return "OK"
 
@@ -158,7 +158,7 @@ Element function petrinet_enabled(pn_m : Element):
 	Element set_enabled
 	set_enabled = petrinet_enabled_set(pn_m)
 	output("Enabled transitions:")
-	while (integer_lt(0, read_nr_out(set_enabled))):
+	while (0 < read_nr_out(set_enabled)):
 		output(getName(pn_m, set_pop(set_enabled)))
 	return pn_m
 
@@ -173,21 +173,21 @@ Element function petrinet_enabled_set(pn_mod : Element):
 	Element in_arcs
 	Element arc_under_study
 	Boolean enabled
-	while (integer_lt(0, read_nr_out(all_transitions))):
+	while (0 < read_nr_out(all_transitions)):
 		under_study = set_pop(all_transitions)
 		enabled = True
 
 		// Find all incoming transitions
 		in_arcs = allIncomingAssociationInstances(pn_mod, under_study, dict_read(dict_read(dict_read(pn_mod, "metamodel"), "model"), "P2T"))
 
-		while (integer_lt(0, read_nr_out(in_arcs))):
+		while (0 < read_nr_out(in_arcs)):
 			arc_under_study = set_pop(in_arcs)
 
 			Integer present_tokens
 			Integer required_tokens
 			required_tokens = readAttribute(pn_mod, arc_under_study, "weight")
 			present_tokens = readAttribute(pn_mod, read_edge_src(arc_under_study), "tokens")
-			if (integer_lt(present_tokens, required_tokens)):
+			if (present_tokens < required_tokens):
 				// Less tokens than required, so disable the transition completely
 				enabled = False
 
@@ -209,19 +209,19 @@ Element function petrinet_fire(pn_mode : Element):
 
 			// Consume tokens
 			workset = allIncomingAssociationInstances(pn_mode, transition, dict_read(dict_read(dict_read(pn_mode, "metamodel"), "model"), "P2T"))
-			while (integer_lt(0, read_nr_out(workset))):
+			while (0 < read_nr_out(workset)):
 				working_arc = set_pop(workset)
 				working_place = read_edge_src(working_arc)
 				setAttribute(pn_mode, working_place, "tokens", integer_subtraction(readAttribute(pn_mode, working_place, "tokens"), readAttribute(pn_mode, working_arc, "weight")))
-				output(string_join(string_join(string_join("  ", getName(pn_mode, working_place)), ": "), cast_i2s(readAttribute(pn_mode, working_place, "tokens"))))
+				output((("  " + getName(pn_mode, working_place)) + ": ") + cast_i2s(readAttribute(pn_mode, working_place, "tokens")))
 
 			// Add tokens
 			workset = allOutgoingAssociationInstances(pn_mode, transition, dict_read(dict_read(dict_read(pn_mode, "metamodel"), "model"), "T2P"))
-			while (integer_lt(0, read_nr_out(workset))):
+			while (0 < read_nr_out(workset)):
 				working_arc = set_pop(workset)
 				working_place = read_edge_dst(working_arc)
 				setAttribute(pn_mode, working_place, "tokens", integer_addition(readAttribute(pn_mode, working_place, "tokens"), readAttribute(pn_mode, working_arc, "weight")))
-				output(string_join(string_join(string_join("  ", getName(pn_mode, working_place)), ": "), cast_i2s(readAttribute(pn_mode, working_place, "tokens"))))
+				output((("  " + getName(pn_mode, working_place)) + ": ") + cast_i2s(readAttribute(pn_mode, working_place, "tokens")))
 			output("Transition fired!")
 		else:
 			output("Cannot fire if not enabled; aborting")
@@ -234,7 +234,7 @@ Element function petrinet_loaded(pn_model : Element):
 
 	Element attr_list_pn
 	Element attr_keys_pn
-	Element attr_key_pn
+	String attr_key_pn
 	Element metamodel_element_pn
 	String typename
 	Boolean bottom
@@ -253,7 +253,7 @@ Element function petrinet_loaded(pn_model : Element):
 	while (True):
 		output("Please give your command.")
 		cmd = input()
-		if (string_eq(cmd, "help")):
+		if (cmd == "help"):
 			output("Generic model operations:")
 			output("  instantiate -- Create a new model element")
 			output("  delete      -- Delete an existing element")
@@ -270,11 +270,13 @@ Element function petrinet_loaded(pn_model : Element):
 				output("Model-specific operations:")
 				Element specific_ops
 				specific_ops = dict_keys(pn_operations())
-				while (integer_lt(0, dict_len(specific_ops))):
-					output(string_join("  ", set_pop(specific_ops)))
-		elif (string_eq(cmd, "exit")):
+				String specific_op
+				while (0 < dict_len(specific_ops)):
+					specific_op = set_pop(specific_ops)
+					output("  " + specific_op)
+		elif (cmd == "exit"):
 			return pn_model
-		elif (string_eq(cmd, "instantiate")):
+		elif (cmd == "instantiate"):
 			String mm_type_name
 			output("Type to instantiate?")
 			mm_type_name = input()
@@ -316,16 +318,16 @@ Element function petrinet_loaded(pn_model : Element):
 						attr_keys_pn = dict_keys(attr_list_pn)
 						Element attrs
 						attrs = create_node()
-						while (integer_lt(0, read_nr_out(attr_keys_pn))):
+						while (0 < read_nr_out(attr_keys_pn)):
 							attr_key_pn = set_pop(attr_keys_pn)
-							output(string_join(string_join(string_join(attr_key_pn, " : "), cast_t2s(dict_read(attr_list_pn, attr_key_pn))), "?"))
+							output(((attr_key_pn + " : ") + cast_t2s(dict_read(attr_list_pn, attr_key_pn))) + "?")
 							dict_add(attrs, attr_key_pn, input())
 						Element resulting_element
 						resulting_element = instantiate_model_lib(pn_model, metamodel_element_pn, element_name, additional_opts, create_node(), attrs)
 						output("Instantiation successful!")
 			else:
 				output("Unknown type specified; aborting")
-		elif (string_eq(cmd, "delete")):
+		elif (cmd == "delete"):
 			output("What is the name of the element you want to delete?")
 			cmd = input()
 			if (dict_in(dict_read(pn_model, "model"), cmd)):
@@ -333,7 +335,7 @@ Element function petrinet_loaded(pn_model : Element):
 				output("Deleted!")
 			else:
 				output("No such element; aborting")
-		elif (string_eq(cmd, "modify")):
+		elif (cmd == "modify"):
 			output("Element to modify?")
 			cmd = input()
 			if (dict_in(dict_read(pn_model, "model"), cmd)):
@@ -343,9 +345,9 @@ Element function petrinet_loaded(pn_model : Element):
 
 				attr_list_pn = getAttributeList(pn_model, metamodel_element_pn)
 				attr_keys_pn = dict_keys(attr_list_pn)
-				while (integer_lt(0, read_nr_out(attr_keys_pn))):
+				while (0 < read_nr_out(attr_keys_pn)):
 					attr_key_pn = set_pop(attr_keys_pn)
-					output(string_join(string_join(string_join("   ", attr_key_pn), " : "), cast_t2s(dict_read(attr_list_pn, attr_key_pn))))
+					output((("   " + attr_key_pn) + " : ") + cast_t2s(dict_read(attr_list_pn, attr_key_pn)))
 
 				output("Attribute to modify?")
 				String attr_name
@@ -358,7 +360,7 @@ Element function petrinet_loaded(pn_model : Element):
 					output("Unknown attribute; aborting")
 			else:
 				output("Element does not exist; aborting")
-		elif (string_eq(cmd, "rename")):
+		elif (cmd == "rename"):
 			output("Old name?")
 			String old_name_e
 			old_name_e = input()
@@ -374,18 +376,18 @@ Element function petrinet_loaded(pn_model : Element):
 					output("Rename complete!")
 			else:
 				output("Unknown element; aborting")
-		elif (string_eq(cmd, "list")):
+		elif (cmd == "list"):
 			Element keys_m
 			keys_m = dict_keys(dict_read(pn_model, "model"))
 			output("List of all elements:")
-			Element v_m
-			while (integer_gt(read_nr_out(keys_m), 0)):
+			String v_m
+			while (read_nr_out(keys_m) > 0):
 				v_m = set_pop(keys_m)
 				// Filter out anonymous objects
 				typename = getName(dict_read(pn_model, "metamodel"), dict_read_node(dict_read(pn_model, "type_mapping"), dict_read(dict_read(pn_model, "model"), v_m)))
 				if (bool_not(string_startswith(v_m, "__"))):
-					output(string_join(string_join(string_join("  ", v_m), " : "), typename))
-		elif (string_eq(cmd, "read")):
+					output((("  " + v_m) + " : ") + typename)
+		elif (cmd == "read"):
 			output("Element to read?")
 			cmd = input()
 			if (dict_in(dict_read(pn_model, "model"), cmd)):
@@ -393,39 +395,39 @@ Element function petrinet_loaded(pn_model : Element):
 				read_elem = dict_read(dict_read(pn_model, "model"), cmd)
 				metamodel_element_pn = dict_read_node(dict_read(pn_model, "type_mapping"), read_elem)
 
-				output(string_join("Name: ", cmd))
-				output(string_join("Type: ", getName(dict_read(pn_model, "metamodel"), metamodel_element_pn)))
+				output("Name: " + cmd)
+				output("Type: " + getName(dict_read(pn_model, "metamodel"), metamodel_element_pn))
 				if (is_edge(read_elem)):
-					output(string_join("Source: ", getName(pn_model, read_edge_src(read_elem))))
-					output(string_join("Destination: ", getName(pn_model, read_edge_dst(read_elem))))
-				if (string_neq(cast_v2s(read_elem), "None")):
-					output(string_join("Value: ", cast_v2s(read_elem)))
+					output("Source: " + getName(pn_model, read_edge_src(read_elem)))
+					output("Destination: " + getName(pn_model, read_edge_dst(read_elem)))
+				if (cast_v2s(read_elem) != "None"):
+					output("Value: " + cast_v2s(read_elem))
 				output("Defines attributes:")
 				attr_list_pn = getInstantiatableAttributes(pn_model, read_elem)
 				attr_keys_pn = dict_keys(attr_list_pn)
-				while (integer_lt(0, read_nr_out(attr_keys_pn))):
+				while (0 < read_nr_out(attr_keys_pn)):
 					attr_key_pn = set_pop(attr_keys_pn)
-					output(string_join(string_join(string_join("   ", attr_key_pn), " : "), cast_t2s(dict_read(attr_list_pn, attr_key_pn))))
+					output(((("   " + attr_key_pn) + " : ") + cast_t2s(dict_read(attr_list_pn, attr_key_pn))))
 				output("Attributes:")
 				attr_list_pn = getAttributeList(pn_model, metamodel_element_pn)
 				attr_keys_pn = dict_keys(attr_list_pn)
-				while (integer_lt(0, read_nr_out(attr_keys_pn))):
+				while (0 < read_nr_out(attr_keys_pn)):
 					attr_key_pn = set_pop(attr_keys_pn)
-					output(string_join(string_join(string_join(string_join(string_join("   ", attr_key_pn), " : "), cast_t2s(dict_read(attr_list_pn, attr_key_pn))), " = "), cast_v2s(readAttribute(pn_model, read_elem, attr_key_pn))))
+					output((((("   " + attr_key_pn) + " : ") + cast_t2s(dict_read(attr_list_pn, attr_key_pn))) + " = ") + cast_v2s(readAttribute(pn_model, read_elem, attr_key_pn)))
 			else:
 				output("Unknown element; aborting")
-		elif (string_eq(cmd, "verify")):
+		elif (cmd == "verify"):
 			output(conformance_scd(pn_model))
-		elif (string_eq(cmd, "types")):
+		elif (cmd == "types"):
 			Element keys_t
 			keys_t = dict_keys(dict_read(dict_read(pn_model, "metamodel"), "model"))
 			output("List of types:")
-			Element v_t
-			while (integer_gt(read_nr_out(keys_t), 0)):
+			String v_t
+			while (read_nr_out(keys_t) > 0):
 				v_t = set_pop(keys_t)
 				if (bool_not(string_startswith(v_t, "__"))):
-					output(string_join(string_join(string_join("  ", v_t), " : "), getName(dict_read(dict_read(pn_model, "metamodel"), "metamodel"), dict_read_node(dict_read(dict_read(pn_model, "metamodel"), "type_mapping"), dict_read(dict_read(dict_read(pn_model, "metamodel"), "model"), v_t)))))
-		elif (string_eq(cmd, "retype")):
+					output(string_join(("  " + v_t) + " : ", getName(dict_read(dict_read(pn_model, "metamodel"), "metamodel"), dict_read_node(dict_read(dict_read(pn_model, "metamodel"), "type_mapping"), dict_read(dict_read(dict_read(pn_model, "metamodel"), "model"), v_t)))))
+		elif (cmd == "retype"):
 			output("Element to retype?")
 			String elementname
 			elementname = input()
@@ -443,7 +445,7 @@ Element function petrinet_loaded(pn_model : Element):
 					output("Unknown type; aborting")
 			else:
 				output("Unknown element; aborting")
-		elif (string_eq(cmd, "switch")):
+		elif (cmd == "switch"):
 			bottom = bool_not(bottom)
 
 			Element tmp_model
@@ -487,7 +489,7 @@ Element function initial_prompt():
 		output("Please give your command.")
 		command = input()
 
-		if (string_eq(command, "help")):
+		if (command == "help"):
 			output("Currently no model is loaded, so your operations are limited to:")
 			output("  new    -- Create a new model and save it for future use")
 			output("  load   -- Load a previously made model")
@@ -495,7 +497,7 @@ Element function initial_prompt():
 			output("  delete -- Delete a previously made model")
 			output("  list   -- Show a list of all stored models")
 			output("  help   -- Show a list of possible commands")
-		elif (string_eq(command, "new")):
+		elif (command == "new"):
 			output("Metamodel to instantiate?")
 			mm_name = input()
 			if (dict_in(root, mm_name)):
@@ -509,7 +511,7 @@ Element function initial_prompt():
 					petrinet_loaded(my_model)
 			else:
 				output("Unknown metamodel; aborting")
-		elif (string_eq(command, "load")):
+		elif (command == "load"):
 			output("Model to load?")
 			name = input()
 			if (dict_in(root, name)):
@@ -517,15 +519,15 @@ Element function initial_prompt():
 				petrinet_loaded(my_model)
 			else:
 				output("Model not found; aborting")
-		elif (string_eq(command, "list")):
+		elif (command == "list"):
 			Element keys
 			keys = dict_keys(root)
 			output("Found models:")
-			while (integer_gt(read_nr_out(keys), 0)):
-				Element m_menu_list
+			String m_menu_list
+			while (read_nr_out(keys) > 0):
 				m_menu_list = set_pop(keys)
-				output(string_join(string_join(string_join("  ", m_menu_list), " : "), reverseNameLookup(root, dict_read(dict_read(root, m_menu_list), "metamodel"))))
-		elif (string_eq(command, "delete")):
+				output((("  " + m_menu_list) + " : ") + reverseNameLookup(root, dict_read(dict_read(root, m_menu_list), "metamodel")))
+		elif (command == "delete"):
 			output("Model to delete?")
 			name = input()
 			if (dict_in(root, name)):
@@ -533,7 +535,7 @@ Element function initial_prompt():
 				output("Deleted!")
 			else:
 				output("Model not found; aborting")
-		elif (string_eq(command, "rename")):
+		elif (command == "rename"):
 			output("Old name?")
 			String old_name
 			old_name = input()