Explorar o código

Working AL execution

Yentl Van Tendeloo %!s(int64=8) %!d(string=hai) anos
pai
achega
8a7a98c49c

BIN=BIN
bootstrap/bootstrap.m.gz


+ 1 - 1
bootstrap/conformance_scd.alc

@@ -214,7 +214,7 @@ String function conformance_scd(model : Element):
 				String result
 				Element func
 
-				func = get_func_AL_model(constraint_function)
+				func = get_func_AL_model(import_node(constraint_function))
 				result = func(model, model_name)
 
 				if (result != "OK"):

+ 0 - 3
bootstrap/model_management.alc

@@ -56,9 +56,6 @@ Element function model_copy(src_model : Element):
 	String type
 
 	dst_model = instantiate_model(src_model["metamodel"])
-	dict_add(dst_model, "model", create_node())
-	dict_add(dst_model, "type_mapping", create_node())
-
 	queue = set_to_list(dict_keys(src_model["model"]))
 
 	while (read_nr_out(queue) > 0):

+ 1 - 5
bootstrap/modelling.alc

@@ -629,13 +629,11 @@ Element function construct_model_raw(metamodel : Element):
 		else:
 			log("Modelling error: did not understand command " + command)
 
-Element function get_func_AL_model(model_location : String):
+Element function get_func_AL_model(al_model : Element):
 	Element result
-	Element al_model
 	Element initial_function
 
 	// Fetch the model to execute
-	al_model = import_node(model_location)
 	log("Imported model: " + cast_e2s(al_model))
 	log("Outgoing: " + set_to_string(dict_keys(al_model)))
 
@@ -653,7 +651,5 @@ Element function get_func_AL_model(model_location : String):
 		log("Retrieving")
 		initial_function = al_model["model"][set_pop(allAssociationDestinations(al_model, set_pop(initial_function), "initial_funcdef"))]
 		log("Found initial_function: " + cast_e2s(initial_function))
-		log("Keys: " + set_to_string(dict_keys(initial_function)))
-		log("Resolved " + model_location)
 
 	return initial_function!

+ 15 - 6
bootstrap/transform.alc

@@ -4,6 +4,7 @@ include "modelling.alh"
 include "random.alh"
 include "conformance_scd.alh"
 include "model_management.alh"
+include "library.alh"
 
 Element function make_matching_schedule(schedule_model : Element, LHS : String, ignore : Element):
 	Element schedule
@@ -146,7 +147,8 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 				Element func
 
 				constraint_function = read_attribute(schedule_model, current_element, "constraint")
-				func = get_func_AL_model(constraint_function)
+				log("1")
+				func = get_func_AL_model(import_node(constraint_function))
 				result = func(host_model, option)
 
 				if (result):
@@ -178,7 +180,8 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 			value = read_attribute(schedule_model, current_element, attribute)
 			// Attribute might be undefined, so skip if it is
 			if (element_neq(value, read_root())):
-				func = get_func_AL_model(value)
+				log("2")
+				func = get_func_AL_model(import_node(value))
 				result = func(read_attribute(host_model, option, string_substr(attribute, string_len("constraint_"), string_len(attribute) + 1)))
 			else:
 				result = True
@@ -276,7 +279,8 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 	if (element_neq(constraint, read_root())):
 		while (read_nr_out(mappings) > 0):
 			map = set_pop(mappings)
-			func = get_func_AL_model(constraint)
+			log("3")
+			func = get_func_AL_model(import_node(constraint))
 			result = func(host_model, map)
 
 			if (result):
@@ -373,7 +377,8 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 
 			value = read_attribute(schedule_model, RHS_map[label], attribute)
 			if (element_neq(value, read_root())):
-				func = get_func_AL_model(value)
+				log("4")
+				func = get_func_AL_model(import_node(value))
 				result = func(host_model, new_mapping[label], mapping)
 
 				if (has_value(result)):
@@ -387,7 +392,10 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 		action = read_attribute(schedule_model, RHS_map[label], "action")
 		if (element_neq(action, read_root())):
 			Element func
-			func = get_func_AL_model(action)
+			log("5")
+			log("Got action: " + cast_e2s(action))
+			log("After import: " + cast_e2s(import_node(action)))
+			func = get_func_AL_model(import_node(action))
 			func(host_model, new_mapping[label], mapping)
 
 	while (read_nr_out(labels_to_remove) > 0):
@@ -400,7 +408,8 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 	action = read_attribute(schedule_model, RHS, "action")
 	if (element_neq(action, read_root())):
 		Element func
-		func = get_func_AL_model(action)
+		log("6")
+		func = get_func_AL_model(import_node(action))
 		func(host_model, new_mapping)
 
 	return!

+ 18 - 5
core/core_algorithm.alc

@@ -163,6 +163,7 @@ Element function get_full_model(model_id : String):
 	Element m
 	Element all_links
 	String choice
+	log("Getting full model!")
 
 	choice = get_instanceOf_link(model_id)
 
@@ -176,6 +177,7 @@ Element function get_full_model(model_id : String):
 	else:
 		dict_add(m, "metamodel", get_full_model(readAssociationDestination(core, choice)))
 
+	log("Finished!")
 	return m!
 
 Integer function get_relation_to_model(user_id : String, model_id : String):
@@ -366,7 +368,7 @@ Void function model_create(model : Element, name : String, user_id : String, typ
 	String model_id
 	String instance_of
 
-	location = "/models/" + cast_id2s(model)
+	location = "models/" + cast_id2s(model)
 	export_node(location, model["model"])
 
 	// Manage meta-info
@@ -385,7 +387,7 @@ Void function model_overwrite(model : Element, model_id : String):
 	String location
 	String instanceOf_link
 
-	location = "/models/" + cast_id2s(model)
+	location = "models/" + cast_id2s(model)
 	export_node(location, model["model"])
 
 	// Change location in meta-data
@@ -636,6 +638,7 @@ Void function user_function_skip_init(user_id : String):
 								output("Could not resolve intermediate merged metamodel")
 						elif (exact_type == "ActionLanguage"):
 							Element dictionary
+							Element new_inputs
 							Element input_keys
 							Element output_keys
 							Element result
@@ -647,11 +650,21 @@ Void function user_function_skip_init(user_id : String):
 							log("Got model: " + cast_e2s(read_attribute(core, transformation_id, "location")))
 
 							// 1) Group source models in dictionary
-							//  --> This is just the "inputs" variable
+							//  --> This is just the "inputs" variable, but resolve all references
 							log("Create inputs")
+							new_inputs = create_node()
+							input_keys = dict_keys(inputs)
+							while (read_nr_out(input_keys) > 0):
+								key = set_pop(input_keys)
+								log("Resolving " + cast_e2s(key))
+								log("  --> " + cast_e2s(inputs[key]))
+								log("  ID " + cast_e2s(get_model_id(inputs[key])))
+								log("  full m " + cast_e2s(get_full_model(get_model_id(inputs[key]))))
+								dict_add(new_inputs, key, get_full_model(get_model_id(inputs[key])))
+							inputs = new_inputs
 
 							// 2) Execute action language model
-							func = get_func_AL_model(read_attribute(core, transformation_id, "location"))
+							func = get_func_AL_model(get_full_model(transformation_id))
 							log("Ready to execute: " + cast_e2s(func))
 							result = func(inputs)
 							log("Result: " + cast_e2s(result))
@@ -931,7 +944,7 @@ Void function user_function_skip_init(user_id : String):
 				log("AL model: " + cast_e2s(get_model_id("ActionLanguage")))
 				log("Location: " + cast_e2s(read_attribute(core, get_model_id("ActionLanguage"), "location")))
 				log("Imported: " + cast_e2s(import_node(read_attribute(core, get_model_id("ActionLanguage"), "location"))))
-				add_code_model(import_node(read_attribute(core, get_model_id("ActionLanguage"), "location")), "AL/" + name, construct_function())
+				add_code_model(get_full_model(get_model_id("ActionLanguage")), "AL/" + name, construct_function())
 				log("Exported to " + cast_e2s(import_node("AL/" + name)))
 				model_create(import_node("AL/" + name), name, user_id, get_model_id("ActionLanguage"), "ActionLanguage")
 				model_id = get_model_id(name)

+ 10 - 2
integration/code/pn_simulate.alc

@@ -6,15 +6,22 @@ include "object_operations.alh"
 include "modelling.alh"
 
 Element function simulate(inputs : Element):
+	log("Start PN step!")
 	Element outputs
 	outputs = create_node()
 
+	log("Inputs: " + dict_to_string(inputs))
+	log("PN input: " + cast_e2s(inputs["PetriNets_Runtime"]))
+	log("Outgoing: " + set_to_string(dict_keys(inputs["PetriNets_Runtime"])))
+
 	// Copy over the model to the output dictionary
-	dict_add(outputs, "models/PetriNets_Runtime", model_copy(inputs["models/PetriNets_Runtime"]))
+	dict_add(outputs, "PetriNets_Runtime", model_copy(inputs["PetriNets_Runtime"]))
+
+	log("Copy OK!")
 
 	// Do a single simulation step
 	Element model
-	model = outputs["models/PetriNets_Runtime"]
+	model = outputs["PetriNets_Runtime"]
 
 	// Find enabled transitions
 	Element all_transitions
@@ -77,4 +84,5 @@ Element function simulate(inputs : Element):
 		instantiate_attribute(model, working_place, "tokens", new_value)
 
 	// Finish up
+	log("Finished PN Step!")
 	return outputs!

+ 0 - 1
integration/test_mvc.py

@@ -1472,7 +1472,6 @@ class TestModelverseCore(unittest.TestCase):
                 "Which transformation do you want to execute?",
                 "Which model to bind for source element PetriNets_Runtime",
                 "Which model to create for target element PetriNets_Runtime",
-                "Transformation executed with result: True",
                 "Ready for command...",
                 # transformation_execute (pn_runtime_to_design)
                 "Which transformation do you want to execute?",

+ 1 - 1
interface/HUTN/includes/modelling.alh

@@ -21,5 +21,5 @@ Element function read_attribute(model : Element, elem : String, name : String)
 Void function model_delete_element(model : Element, name : String)
 String function model_define_attribute(model : Element, elem : String, name : String, optional : Boolean, type : String)
 Element function construct_model_raw(metamodel : Element)
-Element function get_func_AL_model(model_location : String)
+Element function get_func_AL_model(model : Element)
 Void function add_code_model(model : Element, export_name : String, code : Element)