Pārlūkot izejas kodu

Changed execution operations of AL_model

Yentl Van Tendeloo 8 gadi atpakaļ
vecāks
revīzija
b755821846

BIN
bootstrap/bootstrap.m.gz


+ 4 - 9
bootstrap/conformance_scd.alc

@@ -211,16 +211,11 @@ String function conformance_scd(model : Element):
 
 			constraint_function = read_attribute(metamodel, typing[model_name], "constraint")
 			if (element_neq(constraint_function, read_root())):
-				log("Constraint function: " + cast_e2s(constraint_function))
 				String result
-				Element params
-				params = create_node()
-				dict_add(params, "model", model)
-				dict_add(params, "name", model_name)
-
-				log("Invoke!")
-				result = execute_AL_model(constraint_function, params)
-				log("Result: " + cast_e2s(result))
+				Element func
+
+				func = get_func_AL_model(constraint_function)
+				result = func(model, model_name)
 
 				if (result != "OK"):
 					return result!

+ 10 - 11
bootstrap/metamodels.alc

@@ -4,9 +4,9 @@ include "library.alh"
 include "conformance_scd.alh"
 include "modelling.alh"
 
-String function constraint_Natural(params : Element):
+String function constraint_Natural(model : Element, name : String):
 	Element self
-	self = params["model"]["model"][params["name"]]
+	self = model["model"][name]
 	if (is_physical_int(self)):
 		if (integer_gte(self, 0)):
 			return "OK"!
@@ -15,27 +15,26 @@ String function constraint_Natural(params : Element):
 	else:
 		return "Natural number not larger than or equal to zero"!
 
-Element function constraint_String(params : Element):
+Element function constraint_String(model : Element, name : String):
 	Element self
 	log("Invoked!")
-	log("params: " + dict_to_string(params))
-	self = params["model"]["model"][params["name"]]
+	self = model["model"][name]
 	if (is_physical_string(self)):
 		return "OK"!
 	else:
 		return "String has non-string instance"!
 
-Element function constraint_Boolean(params : Element):
+Element function constraint_Boolean(model : Element, name : String):
 	Element self
-	self = params["model"]["model"][params["name"]]
+	self = model["model"][name]
 	if (is_physical_boolean(self)):
 		return "OK"!
 	else:
 		return "Boolean has non-boolean instance"!
 
-Element function constraint_Location(params : Element):
+Element function constraint_Location(model : Element, name : String):
 	Element self
-	self = params["model"]["model"][params["name"]]
+	self = model["model"][name]
 	if (is_physical_string(self)):
 		if (element_neq(import_node(self), read_root())):
 			return "OK"!
@@ -44,9 +43,9 @@ Element function constraint_Location(params : Element):
 	else:
 		return "Location has non-string instance"!
 
-Element function constraint_ActionLanguage(params : Element):
+Element function constraint_ActionLanguage(model : Element, name : String):
 	Element self
-	self = params["model"]["model"][params["name"]]
+	self = model["model"][name]
 	if (is_physical_string(self)):
 		if (element_neq(import_node(self), read_root())):
 			return "OK"!

+ 2 - 4
bootstrap/modelling.alc

@@ -627,7 +627,7 @@ Element function construct_model_raw(metamodel : Element):
 		else:
 			log("Modelling error: did not understand command " + command)
 
-Element function execute_AL_model(model_location : String, params : Element):
+Element function get_func_AL_model(model_location : String):
 	Element result
 	Element al_model
 	Element initial_function
@@ -649,6 +649,4 @@ Element function execute_AL_model(model_location : String, params : Element):
 		log("Found initial_function: " + cast_e2s(initial_function))
 		log("Keys: " + set_to_string(dict_keys(initial_function)))
 
-	// Execute that function
-	result = initial_function(params)
-	return result!
+	return initial_function!

+ 10 - 22
bootstrap/transform.alc

@@ -144,15 +144,12 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 				// Check local constraints and add only if positive
 				Element constraint_function
 				Boolean result
-				Element params
+				Element func
 
 				constraint_function = read_attribute(schedule_model, current_element, "constraint")
-				params = create_node()
-				dict_add(params, "model", host_model)
-				dict_add(params, "option", option)
-				log("Invoking constraint in match!")
-				result = execute_AL_model(constraint_function, params)
-				log("Result of constraint: " + cast_e2s(result))
+				func = get_func_AL_model(constraint_function)
+				result = func(host_model, option)
+
 				if (result):
 					set_add(filtered_options, option)
 
@@ -330,14 +327,9 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 		label = set_pop(original_RHS_labels)
 		action = read_attribute(schedule_model, RHS_map[label], "action")
 		if (element_neq(action, read_root())):
-			Element params
-			params = create_node()
-			dict_add(params, "model", host_model)
-			dict_add(params, "name", new_mapping[label])
-			dict_add(params, "mapping", mapping)
-			log("Execute RHS Action")
-			execute_AL_model(action, params)
-			log("Finished!")
+			Element func
+			func = get_func_AL_model(action)
+			func(host_model, new_mapping[label], mapping)
 
 	while (read_nr_out(labels_to_remove) > 0):
 		// Remove the elements linked to these labels
@@ -348,13 +340,9 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 	// Execute global action (whatever it may be)
 	action = read_attribute(schedule_model, RHS, "action")
 	if (element_neq(action, read_root())):
-		Element params
-		params = create_node()
-		dict_add(params, "model", host_model)
-		dict_add(params, "mapping", new_mapping)
-		log("Execute global RHS Action")
-		execute_AL_model(action, params)
-		log("Finished!")
+		Element func
+		func = get_func_AL_model(action)
+		func(host_model, new_mapping)
 
 	return!
 

+ 2 - 2
integration/code/my_petrinet_with_MM_and_constraints.mvc

@@ -7,9 +7,9 @@ SCD PetriNets{
             $
             include "primitives.alh"
 
-            String function constraint_Natural(params : Element):
+            String function constraint_Natural(model : Element, name : String):
                 Element self
-                self = params["model"]["model"][params["name"]]
+                self = model["model"][name]
                 if (is_physical_int(self)):
                     if (integer_gte(self, 0)):
                         return "OK"!

+ 2 - 2
integration/code/petrinets_constraints.mvc

@@ -7,9 +7,9 @@ SCD PetriNets{
             $
             include "primitives.alh"
 
-            String function constraint_Natural(params : Element):
+            String function constraint_Natural(model : Element, name : String):
                 Element self
-                self = params["model"]["model"][params["name"]]
+                self = model["model"][name]
                 if (is_physical_int(self)):
                     if (integer_gte(self, 0)):
                         return "OK"!

+ 5 - 5
integration/code/pn_design_to_runtime.mvc

@@ -19,8 +19,8 @@ RAM_PN_DR annotate {
                     action = $
                         include "primitives.alh"
                         include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            instantiate_attribute(host_model, name, "executing", False)
+                        Void function action(model : Element, name : String, mapping : Element):
+                            instantiate_attribute(model, name, "executing", False)
                             return!
                         $
                 }
@@ -44,9 +44,9 @@ RAM_PN_DR annotate {
                     action = $
                         include "primitives.alh"
                         include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            instantiate_attribute(host_model, name, "tokens", read_attribute(host_model, mapping["0"], "tokens"))
-                            instantiate_attribute(host_model, name, "name", read_attribute(host_model, mapping["0"], "name"))
+                        Void function action(model : Element, name : String, mapping : Element):
+                            instantiate_attribute(model, name, "tokens", read_attribute(model, mapping["0"], "tokens"))
+                            instantiate_attribute(model, name, "name", read_attribute(model, mapping["0"], "name"))
                             return!
                         $
                 }

+ 2 - 2
integration/code/pn_print.mvc

@@ -15,8 +15,8 @@ RAM_PN_R print {
                     action = $
                         include "primitives.alh"
                         include "modelling.alh"
-                        Void function action(params : Element):
-                            output((cast_v2s(read_attribute(params["model"], params["name"], "name")) + " --> ") + cast_v2s(read_attribute(params["model"], params["name"], "tokens")))
+                        Void function action(model : Element, name : String):
+                            output((cast_v2s(read_attribute(model, name, "name")) + " --> ") + cast_v2s(read_attribute(model, name, "tokens")))
                             return!
                         $
                 }

+ 4 - 4
integration/code/several_petrinets.mvc

@@ -7,16 +7,16 @@ SCD PetriNets{
             $
             include "primitives.alh"
 
-            String function constraint_Natural(params : Element):
+            String function constraint_Natural(model : Element, name : String):
                 Element self
-                self = params["model"]["model"][params["name"]]
+                self = model["model"][name]
                 if (is_physical_int(self)):
                     if (integer_gte(self, 0)):
                         return "OK"!
                     else:
-                        return string_join("Natural does not have a positive or zero value at ", params["name"])!
+                        return ("Natural does not have a positive or zero value at " + name)!
                 else:
-                    return string_join("Natural has no integer value at ", params["name"])!
+                    return ("Natural has no integer value at " + name)!
             $
     }
 

+ 10 - 10
integration/test_constructors_models.py

@@ -303,9 +303,9 @@ def conformance_check(node):
 code_natural = \
     """
         include "primitives.alh"
-        String function constraint(params : Element):
+        String function constraint(model : Element, name : String):
             Element self
-            self = params["model"]["model"][params["name"]]
+            self = model["model"][name]
             if (is_physical_int(self)):
                 if (integer_gte(self, 0)):
                     return "OK"!
@@ -318,9 +318,9 @@ code_natural = \
 code_string = \
     """
         include "primitives.alh"
-        Element function constraint(params : Element):
+        String function constraint(model : Element, name : String):
             Element self
-            self = params["model"]["model"][params["name"]]
+            self = model["model"][name]
             log("In constraint")
             if (is_physical_string(self)):
                 return "OK"!
@@ -331,9 +331,9 @@ code_string = \
 code_boolean = \
     """
         include "primitives.alh"
-        Element function constraint(params : Element):
+        String function constraint(model : Element, name : String):
             Element self
-            self = params["model"]["model"][params["name"]]
+            self = model["model"][name]
             if (is_physical_boolean(self)):
                 return "OK"!
             else:
@@ -344,9 +344,9 @@ code_location = \
     """
         include "primitives.alh"
         include "library.alh"
-        Element function constraint(params : Element):
+        String function constraint(model : Element, name : String):
             Element self
-            self = params["model"]["model"][params["name"]]
+            self = model["model"][name]
             if (is_physical_string(self)):
                 if (element_neq(import_node(self), read_root())):
                     return "OK"!
@@ -360,9 +360,9 @@ code_complex_attribute = \
     """
         include "primitives.alh"
         include "library.alh"
-        Element function constraint(params : Element):
+        String function constraint(model : Element, name : String):
             Element self
-            self = params["model"]["model"][params["name"]]
+            self = model["model"][name]
             if (is_physical_string(self)):
                 if (element_neq(import_node(self), read_root())):
                     return "OK"!

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

@@ -21,4 +21,4 @@ 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 execute_AL_model(model_location : String, params : Element)
+Element function get_func_AL_model(model_location : String)