소스 검색

More bugfixes to transformations and execution

Yentl Van Tendeloo 8 년 전
부모
커밋
9e027ab90c

+ 23 - 31
bootstrap/core_algorithm.alc

@@ -295,23 +295,17 @@ Boolean function pm_finished(worklist : Element, pm : String):
 	Element finished
 	Integer cnt
 	Integer i
-
 	// Check if any of the "finish" elements are in the worklist
 	// If so, we can already finish, and therefore will stop immediately
 	finished = allInstances(pm, "Finish")
-	i = 0
-	cnt = set_len(finished)
-
 	worklist = set_copy(worklist)
 	while (set_len(worklist) > 0):
 		// Check each finished element individually
-		if (set_in(finished, set_pop(worklist))):
+		if (set_in(finished, list_read(set_pop(worklist), 0))):
 			return True!
-		i = i + 1
-
 	return False!
 
-Element function execute_operation(operation_id : String, input_models : Element, output_models : Element, tracability_model : Element):
+Element function execute_operation(operation_id : String, input_models : Element, tracability_model : Element):
 	// Operations are always in-place and uses only a single metamodel
 	// Therefore, we must:
 	//		1) Find merged metamodel
@@ -376,10 +370,10 @@ Element function execute_operation(operation_id : String, input_models : Element
 
 		merged_model = model_join(model_tuples, get_full_model(merged_metamodel_id, get_model_id("SimpleClassDiagrams")), tracability_model)
 	else:
-		if (bool_and(dict_len(input_models) == 1, dict_len(output_models) == 0)):
+		if (bool_and(dict_len(input_models) == 1, dict_len(output_metamodels) == 0)):
 			// Just skip the merge...
 			merged_model = model_copy(get_full_model(get_model_id(input_models[set_pop(dict_keys(input_models))]), get_model_id(input_metamodels[set_pop(dict_keys(input_metamodels))])))
-		elif (bool_and(dict_len(input_models) == 0, dict_len(output_models) == 0)):
+		elif (bool_and(dict_len(input_models) == 0, dict_len(output_metamodels) == 0)):
 			merged_model = read_root()
 		else:
 			log("Could not resolve intermediate merged metamodel")
@@ -419,10 +413,10 @@ Element function execute_operation(operation_id : String, input_models : Element
 
 	if (result):
 		model_tuples = set_create()
-		keys = dict_keys(output_models)
+		keys = dict_keys(output_metamodels)
 		while (set_len(keys) > 0):
 			key = set_pop(keys)
-			set_add_node(model_tuples, create_tuple(key, get_full_model(get_model_id(output_models[key]), get_model_id(output_metamodels[key]))))
+			set_add_node(model_tuples, create_tuple(key, get_full_model(get_model_id(output_metamodels[key]), get_model_id("SimpleClassDiagrams"))))
 
 		result = model_split(merged_model, model_tuples, tracability)
 
@@ -494,7 +488,7 @@ Boolean function enact_action(pm : Element, element : String, prefix : String, u
 		log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
 		output(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
 		
-	result = execute_operation(transformation_id, inputs, outputs, read_root())
+	result = execute_operation(transformation_id, inputs, read_root())
 
 	if (element_eq(result, read_root())):
 		// Something went wrong!
@@ -530,10 +524,11 @@ Void function enact_PM(pm : Element, prefix : String, user_id : String):
 
 	// Create the worklist with the Start instance as first element
 	worklist = set_create()
-	set_add(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
+	set_add_node(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
 
 	while (bool_not(pm_finished(worklist, pm))):
 		// Pop a random element from the list and execute it
+		log("POP WL")
 		tuple = set_pop(worklist)
 		element = tuple[0]
 		result = tuple[1]
@@ -581,11 +576,13 @@ Void function enact_PM(pm : Element, prefix : String, user_id : String):
 			// in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
 			if (bool_not(result)):
 				// Apparently it is False, so map this to the "Else" branch
-				set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
+				log("POP ELSE")
+				set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
 				continue!
 			else:
 				// Apparently it is True, so map this to the "Then" branch
-				set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
+				log("POP THEN")
+				set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
 				continue!
 
 		// We have finished the execution, so add all outgoing edges to the worklist
@@ -593,8 +590,9 @@ Void function enact_PM(pm : Element, prefix : String, user_id : String):
 		all_next = allAssociationDestinations(pm, element, "Next")
 		String next
 		while (set_len(all_next) > 0):
+			log("POP1")
 			next = set_pop(all_next)
-			set_add(worklist, create_tuple(next, result))
+			set_add_node(worklist, create_tuple(next, result))
 
 	// Reached a finish element, so stop
 	output("Success")
@@ -774,15 +772,18 @@ String function cmd_model_render(user_id : String, model_name : String, mapper_n
 						tracability_model = get_full_model(get_model_id(tracability_name), get_model_id("TracabilityModel"))
 
 					// Do the operation itself!
-					result = execute_operation(mapper_ID, inputs, output_map, tracability_model)
+					result = execute_operation(mapper_ID, inputs, tracability_model)
 
 					// Overwrite the previous rendered model
+					log("Rendered model: " + cast_v2s(get_model_id(output_map["rendered"])))
 					model_overwrite(result["rendered"], get_model_id(rendered_name), get_model_id(output_map["rendered"]))
+					log("Abstract model: " + cast_v2s(get_model_id(output_map["abstract"])))
 					model_overwrite(result["abstract"], get_model_id(model_name), get_model_id(output_map["abstract"]))
 
 					// Tracability updated in-place
-					model_overwrite(tracability_model, get_model_id(tracability_name), get_model_id("TracabilityModel"))
-					tracability_model = get_full_model(get_model_id(tracability_name), get_model_id("TracabilityModel"))
+					log("Tracability model: " + cast_v2s(get_model_id("Tracability")))
+					model_overwrite(tracability_model, get_model_id(tracability_name), get_model_id("Tracability"))
+					tracability_model = get_full_model(get_model_id(tracability_name), get_model_id("Tracability"))
 
 					// Also output the resulting model
 					return "Success: " + JSON_print(get_full_model(get_model_id(rendered_name), get_model_id(output_map["rendered"])))!
@@ -880,7 +881,7 @@ String function cmd_transformation_execute(user_id : String, transformation_name
 					output("Success: ready for MT execution")
 
 				log("Start execution: " + cast_e2s(transformation_id))
-				result = execute_operation(transformation_id, inputs, output_map, read_root())
+				result = execute_operation(transformation_id, inputs, read_root())
 
 				// Now write out the models again
 				if (element_eq(result, read_root())):
@@ -935,7 +936,7 @@ String function cmd_new_verify(user_id : String, model_name : String, metamodel_
 			conformance_operation = set_pop(allAssociationDestinations(core, get_instanceOf_link(model_id, get_model_id(metamodel_name)), "semantics"))
 			inputs = dict_create()
 			dict_add(inputs, "SimpleClassDiagrams", model_name)
-			result = execute_operation(conformance_operation, inputs, dict_create(), read_root())
+			result = execute_operation(conformance_operation, inputs, read_root())
 			return ""!
 		else:
 			return "Permission denied to model: " + model_name!
@@ -1104,7 +1105,6 @@ String function transformation_add(user_id : String, source_models : Element, ta
 		// Write out a merged metamodel containing all these models: this is the MM for the manual operation
 		// New location is available, so write
 		if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
-			log("Formalism map: " + list_to_string(formalism_map))
 			merged_formalism = model_fuse(formalism_map)
 			modify(merged_formalism, True)
 
@@ -1230,14 +1230,10 @@ String function cmd_transformation_add_MT(user_id : String, source_models : Elem
 		else:
 			return "Model not found: " + name!
 
-	log("FUSE")
 	merged_formalism = model_fuse(to_ramify)
-	log("MODIFY")
 	modify(merged_formalism, True)
-	log("RAMIFY")
 
 	ramified_metamodel = ramify(merged_formalism)
-	log("RAMify OK")
 	model_create(ramified_metamodel, "__RAM_" + operation_name, user_id, get_model_id("SimpleClassDiagrams"), "Model")
 	ramified_metamodel_id = get_model_id("__RAM_" + operation_name)
 	
@@ -1246,11 +1242,9 @@ String function cmd_transformation_add_MT(user_id : String, source_models : Elem
 		String new_model
 		// Finished with all information, now create the model itself!
 		output("Waiting for model constructors...")
-		log("Uploading model")
 		new_model = construct_model_raw(get_full_model(ramified_metamodel_id, get_model_id("SimpleClassDiagrams")))
 		model_create(new_model, operation_name, user_id, ramified_metamodel_id, "ModelTransformation")
 		model_id = get_model_id(operation_name)
-		log("Uploaded model")
 
 		// Write out a merged metamodel containing all these models: this is the MM for the manual operation
 		// New location is available, so write
@@ -1264,7 +1258,6 @@ String function cmd_transformation_add_MT(user_id : String, source_models : Elem
 		// Add tracability links at this level
 		tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, ramified_metamodel_id)
 		instantiate_attribute(core, tracability_link, "type", "RAMified")
-		log("Tracability OK")
 
 		// Extend metadata with info on source and target
 		String link
@@ -1283,7 +1276,6 @@ String function cmd_transformation_add_MT(user_id : String, source_models : Elem
 			dst = target[key]
 			link = instantiate_link(core, "transformOutput", "", model_id, dst)
 			instantiate_attribute(core, link, "name", key)
-		log("Transform links oK")
 
 		return "Success"!
 	else:

+ 2 - 2
bootstrap/modelling.alc

@@ -467,7 +467,7 @@ Void function add_AL_links(model : Element, list : Element, element : Element, t
 		dict_add_fast(model["type_mapping"], link_name, "StringAttr")
 
 	// Now add the destination to the worker list
-	set_add(list, create_tuple(element[linkname], expected_type))
+	set_add_node(list, create_tuple(element[linkname], expected_type))
 
 	return!
 
@@ -480,7 +480,7 @@ String function add_AL(model : Element, element : Element):
 	String elem_name
 
 	todo = set_create()
-	set_add(todo, create_tuple(element, "funcdef"))
+	set_add_node(todo, create_tuple(element, "funcdef"))
 
 	while (0 < dict_len(todo)):
 		work_node = set_pop(todo)

+ 7 - 14
bootstrap/transform.alc

@@ -16,6 +16,7 @@ Element function make_matching_schedule(schedule_model : Element, LHS : String,
 	Integer counter
 	String next
 	Element tmp
+	String elem_id
 
 	Element reverse
 	reverse = make_reverse_dictionary(schedule_model["model"])
@@ -62,15 +63,17 @@ Element function make_matching_schedule(schedule_model : Element, LHS : String,
 					counter = read_nr_out(schedule_model["model"][next])
 					while (counter > 0):
 						counter = counter - 1
-						if (set_in_node(schedule_model["model"], read_out(schedule_model["model"][next], counter))):
-							set_add(workset, reverse[cast_id2s(read_out(schedule_model["model"][next], counter))])
+						elem_id = cast_id2s(read_out(schedule_model["model"][next], counter))
+						if (dict_in(reverse, elem_id)):
+							set_add(workset, reverse[elem_id])
 
 					// And incoming links
 					counter = read_nr_in(schedule_model["model"][next])
 					while (counter > 0):
 						counter = counter - 1
-						if (set_in_node(schedule_model["model"], read_in(schedule_model["model"][next], counter))):
-							set_add(workset, reverse[cast_id2s(read_in(schedule_model["model"][next], counter))])
+						elem_id = cast_id2s(read_in(schedule_model["model"][next], counter))
+						if (dict_in(reverse, elem_id)):
+							set_add(workset, reverse[elem_id])
 
 	return schedule!
 
@@ -152,7 +155,6 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 			// Multiple "only" options, which will not work out: no options!
 			return set_create()!
 
-	log("INT1 options: " + set_to_string(options))
 	// Filter options further
 	Element filtered_options
 	String option
@@ -198,7 +200,6 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 	Element attributes_copy
 
 	options = filtered_options
-	log("INT2 options: " + set_to_string(options))
 	filtered_options = set_create()
 
 	// Check whether all attributes have a satisfied condition
@@ -230,7 +231,6 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 			set_add(filtered_options, option)
 
 	options = filtered_options
-	log("Return options: " + set_to_string(options))
 	return options!
 
 Element function full_match(host_model : Element, schedule_model : Element, current : String, single_ok : Boolean):
@@ -255,7 +255,6 @@ Element function full_match(host_model : Element, schedule_model : Element, curr
 	// For each possible mapping, we check all NACs!
 	while (set_len(mappings) > 0):
 		mapping = set_pop(mappings)
-		log("Got mapping from match: " + dict_to_string(mapping))
 		allowed = True
 		while (set_len(NACs) > 0):
 			NAC = set_pop(NACs)
@@ -279,7 +278,6 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 	// Make the schedule first
 	Element schedule
 	schedule = make_matching_schedule(schedule_model, LHS, dict_keys(initial_mapping))
-	log("Got schedule: " + list_to_string(schedule))
 
 	// Now follow the schedule, incrementally building all mappings
 	Element mappings
@@ -300,17 +298,12 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 		while (set_len(mappings) > 0):
 			map = set_pop(mappings)
 			options = get_possible_bindings(host_model, schedule_model, current_element, map)
-			log("Options to bind: " + set_to_string(options))
 
 			while (set_len(options) > 0):
 				option = set_pop(options)
-				log("Pop option: " + option)
 				new_map = dict_copy(map)
-				log("Copied: " + dict_to_string(new_map))
 				dict_add_fast(new_map, read_attribute(schedule_model, current_element, "label"), option)
-				log("PRE Got new mapping: " + dict_to_string(new_map))
 				set_add_node(new_mappings, new_map)
-				log("Got new mapping: " + dict_to_string(new_map))
 
 		mappings = new_mappings
 		//log("Remaining options: " + cast_v2s(set_len(mappings)))

+ 1 - 1
integration/code/pn_simulate.alc

@@ -48,7 +48,7 @@ Boolean function simulate(model : Element):
 	// Pick random enabled transition
 	String transition
 
-	transition = random_choice(enabled_transitions)
+	transition = random_choice(set_to_list(enabled_transitions))
 
 	// Consume tokens
 	Element workset

+ 2 - 2
integration/code/reachabilitygraph_print.mvc

@@ -19,9 +19,9 @@ Composite schedule {
                         Element dict_values
                         Element all_values
                         String place
-                        dict_values = create_node()
+                        dict_values = dict_create()
                         all_values = allAssociationDestinations(model, name, "ReachabilityGraph/Contains")
-                        while (read_nr_out(all_values) > 0):
+                        while (set_len(all_values) > 0):
                             place = set_pop(all_values)
                             dict_add(dict_values, read_attribute(model, place, "name"), read_attribute(model, place, "tokens"))
                         log((cast_v2s(read_attribute(model, name, "name")) + ": ") + dict_to_string(dict_values))

+ 2 - 2
kernel/modelverse_jit/intrinsics.py

@@ -299,8 +299,8 @@ MISC_INTRINSICS = {
         tree_ir.ReadDictionaryEdgeInstruction(
             a, tree_ir.ReadValueInstruction(b)),
 
-    #'dict_add' : __dict_add,
-    #'dict_add_fast' : __dict_add_fast,
+    'dict_add' : __dict_add,
+    'dict_add_fast' : __dict_add_fast,
     'dict_len' : __read_nr_out,
 
     # Set operations

+ 7 - 7
models/SCCD_execute.alc

@@ -263,7 +263,7 @@ Element function get_enabled_transitions(model : Element, state : String, data :
 						// Condition failed, so skip
 						continue!
 				// Fine to add this one with the specified parameters
-				set_add(result, create_tuple(transition, param))
+				set_add_node(result, create_tuple(transition, param))
 		else:
 			// No event to think about, just add the transition
 			if (element_neq(cond, read_root())):
@@ -272,7 +272,7 @@ Element function get_enabled_transitions(model : Element, state : String, data :
 					// Condition false, so skip
 					continue!
 			// Fine to add this one without event parameters (no event)
-			set_add(result, create_tuple(transition, read_root()))
+			set_add_node(result, create_tuple(transition, read_root()))
 
 	return result!
 
@@ -309,14 +309,14 @@ Void function process_raised_event(model : Element, event : Element, parameter_a
 		Element classes
 		classes = dict_keys(data["classes"])
 		while(read_nr_out(classes) > 0):
-			set_add(data["classes"][set_pop(classes)]["new_events"], create_tuple(read_attribute(model, event, "event"), parameter_action))
+			set_add_node(data["classes"][set_pop(classes)]["new_events"], create_tuple(read_attribute(model, event, "event"), parameter_action))
 	elif (scope == "narrow"):
 		// Send to the specified class only
 		// TODO some error checking would be nice...
-		set_add(data["classes"][read_attribute(model, event, "target")]["new_events"], create_tuple(read_attribute(model, event, "event"), parameter_action))
+		set_add_node(data["classes"][read_attribute(model, event, "target")]["new_events"], create_tuple(read_attribute(model, event, "event"), parameter_action))
 	else:
 		// Same as local
-		set_add(data["current_class_handle"]["new_events"], create_tuple(read_attribute(model, event, "event"), parameter_action))
+		set_add_node(data["current_class_handle"]["new_events"], create_tuple(read_attribute(model, event, "event"), parameter_action))
 
 	return !
 
@@ -397,7 +397,7 @@ Boolean function step_class(model : Element, data : Element, class : String):
 
 			if (read_nr_out(transitions) > 0):
 				// Found an enabled transition, so store that one
-				transition = random_choice(transitions)
+				transition = random_choice(set_to_list(transitions))
 				
 				// Execute transition
 				set_merge(new_states, execute_transition(model, data, transition))
@@ -743,7 +743,7 @@ Boolean function main(model : Element):
 
 			if (element_neq(interrupt, read_root())):
 				// Got interrupt, so append it already
-				set_add(data["classes"][class]["events"], create_tuple(interrupt, read_root()))
+				set_add_node(data["classes"][class]["events"], create_tuple(interrupt, read_root()))
 
 		// Else we timeout, and thus keep the time_sim
 		dict_overwrite(data, "time_sim", time_sim)