Browse Source

Minor patches; output AL in a different way

Yentl Van Tendeloo 7 years ago
parent
commit
c3d694ba1d

+ 6 - 7
bootstrap/metamodels.alt

@@ -109,8 +109,8 @@ Element function initialize_SCD(location : String):
 	instantiate_attribute(scd, "attr_optional", "optional", False)
 	instantiate_attribute(scd, "attr_optional", "optional", False)
 	instantiate_attribute(scd, "attr_name", "optional", False)
 	instantiate_attribute(scd, "attr_name", "optional", False)
 
 
-	instantiate_node(scd, "Class", "ComplexAttribute")
-	instantiate_link(scd, "Inheritance", "", "ComplexAttribute", "Attribute")
+	instantiate_node(scd, "Class", "ActionLanguage")
+	instantiate_link(scd, "Inheritance", "", "ActionLanguage", "Attribute")
 
 
 	model_define_attribute(scd, "Class", "lower_cardinality", True, "Natural")
 	model_define_attribute(scd, "Class", "lower_cardinality", True, "Natural")
 	model_define_attribute(scd, "Class", "upper_cardinality", True, "Natural")
 	model_define_attribute(scd, "Class", "upper_cardinality", True, "Natural")
@@ -118,7 +118,6 @@ Element function initialize_SCD(location : String):
 	model_define_attribute(scd, "Association", "target_lower_cardinality", True, "Natural")
 	model_define_attribute(scd, "Association", "target_lower_cardinality", True, "Natural")
 	model_define_attribute(scd, "Association", "source_upper_cardinality", True, "Natural")
 	model_define_attribute(scd, "Association", "source_upper_cardinality", True, "Natural")
 	model_define_attribute(scd, "Association", "target_upper_cardinality", True, "Natural")
 	model_define_attribute(scd, "Association", "target_upper_cardinality", True, "Natural")
-	model_define_attribute(scd, "ComplexAttribute", "type", False, "Location")
 
 
 	model_define_attribute(scd, "Class", "name", False, "String")
 	model_define_attribute(scd, "Class", "name", False, "String")
 	model_define_attribute(scd, "SimpleAttribute", "name", False, "String")
 	model_define_attribute(scd, "SimpleAttribute", "name", False, "String")
@@ -138,9 +137,9 @@ Element function initialize_SCD(location : String):
 	initialize_AL(location, al_location)
 	initialize_AL(location, al_location)
 
 
 	// Define additional attributes that define functions
 	// Define additional attributes that define functions
-	instantiate_node(scd, "ComplexAttribute", "ActionLanguage")
-	instantiate_attribute(scd, "ActionLanguage", "type", al_location)
-	model_define_attribute(scd, "Element", "constraint", True, "ActionLanguage")
+	instantiate_node(scd, "ActionLanguage", "ActionCode")
+	instantiate_attribute(scd, "ActionCode", "name", "ActionCode")
+	model_define_attribute(scd, "Element", "constraint", True, "ActionCode")
 
 
 	// Define some constraints
 	// Define some constraints
 	//instantiate_attribute_code(scd, "Natural", "constraint", constraint_Natural)
 	//instantiate_attribute_code(scd, "Natural", "constraint", constraint_Natural)
@@ -150,7 +149,7 @@ Element function initialize_SCD(location : String):
 	//instantiate_attribute_code(scd, "ActionLanguage", "constraint", constraint_ActionLanguage)
 	//instantiate_attribute_code(scd, "ActionLanguage", "constraint", constraint_ActionLanguage)
 
 
 	instantiate_node(scd, "Class", "GlobalConstraint")
 	instantiate_node(scd, "Class", "GlobalConstraint")
-	model_define_attribute(scd, "GlobalConstraint", "global_constraint", False, "ActionLanguage")
+	model_define_attribute(scd, "GlobalConstraint", "global_constraint", False, "ActionCode")
 	instantiate_attribute(scd, "GlobalConstraint", "name", "GlobalConstraint")
 	instantiate_attribute(scd, "GlobalConstraint", "name", "GlobalConstraint")
 
 
 	dict_overwrite(scd, "types", get_type_mapping(scd))
 	dict_overwrite(scd, "types", get_type_mapping(scd))

+ 8 - 48
bootstrap/mini_modify.alc

@@ -12,51 +12,6 @@ include "utils.alh"
 
 
 Boolean verbose = True
 Boolean verbose = True
 
 
-String function pretty_print(model : Element):
-	Element keys_m
-	String type
-	String v_m
-	Element attr_list
-	Element attr_keys
-	String attr_key
-	String result
-
-	result = ""
-	keys_m = dict_keys(model["model"])
-
-	while (set_len(keys_m) > 0):
-		v_m = set_pop(keys_m)
-		type = read_type(model["metamodel"], read_type(model, v_m))
-
-		if (bool_or(type == "Class", type == "Association")):
-			result = result + "  " + v_m + " : " + read_type(model, v_m)
-			result = result + "\n"
-			if (type == "Association"):
-				result = result + "    " + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m])) + " --> " + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m]))
-				result = result + "\n"
-
-			// Defines attributes
-			attr_list = getInstantiatableAttributes(model, v_m, "AttributeLink")
-			attr_keys = dict_keys(attr_list)
-			while (set_len(attr_keys) > 0):
-				attr_key = set_pop(attr_keys)
-				result = result + "      " + attr_key + " : " + cast_value(attr_list[attr_key])
-				result = result + "\n"
-
-			// Has attributes
-			attr_list = getAttributeList(model, v_m)
-			attr_keys = dict_keys(attr_list)
-			while (set_len(attr_keys) > 0):
-				attr_key = set_pop(attr_keys)
-				if (element_eq(read_attribute(model, v_m, attr_key), read_root())):
-					result = result + "      " + cast_string(attr_key) + " : " + cast_string(attr_list[attr_key]) + " = (undefined)"
-				else:
-					result = result + "      " + cast_string(attr_key) + " : " + cast_string(attr_list[attr_key]) + " = " + cast_value(read_attribute(model, v_m, attr_key))
-				result = result + "\n"
-		else:
-			log("Skip instance: " + type)
-	return result!
-
 String function cmd_help_m(write : Boolean):
 String function cmd_help_m(write : Boolean):
 	String result
 	String result
 	result = ""
 	result = ""
@@ -407,6 +362,8 @@ String function cmd_read_attrs(model : Element, element_name : String):
 	Element attr_list
 	Element attr_list
 	Element attr_keys
 	Element attr_keys
 	String attr_key
 	String attr_key
+	String attr
+	String type_attr
 
 
 	result = "Success: "
 	result = "Success: "
 	if (dict_in(model["model"], element_name)):
 	if (dict_in(model["model"], element_name)):
@@ -414,7 +371,12 @@ String function cmd_read_attrs(model : Element, element_name : String):
 		attr_keys = dict_keys(attr_list)
 		attr_keys = dict_keys(attr_list)
 		while (0 < set_len(attr_keys)):
 		while (0 < set_len(attr_keys)):
 			attr_key = set_pop(attr_keys)
 			attr_key = set_pop(attr_keys)
-			result = string_join(result, attr_key) + " : " + cast_value(attr_list[attr_key]) + " = " + cast_value(read_attribute(model, element_name, attr_key)) + "\n"
+			attr = read_attribute(model, element_name, attr_key)
+			type_attr = read_type(model, reverseKeyLookup(model["model"], attr))
+			if (read_type(model["metamodel"], type_attr) == "ActionLanguage"):
+				result = result + attr_key + " : " + cast_value(attr_list[attr_key]) + " = {\"AL\": " + cast_value(attr) + "}\n"
+			else:
+				result = result + attr_key + " : " + cast_value(attr_list[attr_key]) + " = " + cast_value(attr) + "\n"
 		return result!
 		return result!
 	else:
 	else:
 		return "Element not found: " + element_name!
 		return "Element not found: " + element_name!
@@ -530,8 +492,6 @@ Boolean function modify(model : Element, write : Boolean):
 			output(cmd_attr_optional(write, model, single_input("Name?"), single_input("Attribute name?"), input()))
 			output(cmd_attr_optional(write, model, single_input("Name?"), single_input("Attribute name?"), input()))
 		elif (cmd == "delete"):
 		elif (cmd == "delete"):
 			output(cmd_delete(write, model, single_input("Name?")))
 			output(cmd_delete(write, model, single_input("Name?")))
-		elif (cmd == "nice_list"):
-			output(pretty_print(model))
 		elif (cmd == "list"):
 		elif (cmd == "list"):
 			output(cmd_list(model))
 			output(cmd_list(model))
 		elif (cmd == "list_full"):
 		elif (cmd == "list_full"):

+ 1 - 0
bootstrap/modelling.alc

@@ -6,6 +6,7 @@ include "metamodels.alh"
 include "library.alh"
 include "library.alh"
 include "typing.alh"
 include "typing.alh"
 include "utils.alh"
 include "utils.alh"
+include "core_algorithm.alh"
 
 
 Element global_models = ?
 Element global_models = ?
 
 

+ 6 - 1
bootstrap/utils.alc

@@ -12,6 +12,7 @@ String function JSON_print(model : Element):
 	Element attr_keys
 	Element attr_keys
 	Boolean first
 	Boolean first
 	Element attr_value
 	Element attr_value
+	String type_attr
 
 
 	result = "["
 	result = "["
 	keys_m = dict_keys(model["model"])
 	keys_m = dict_keys(model["model"])
@@ -48,7 +49,11 @@ String function JSON_print(model : Element):
 						else:
 						else:
 							result = result + ", \"" + attr_key + "\": false"
 							result = result + ", \"" + attr_key + "\": false"
 					else:
 					else:
-						result = result + ", \"" + attr_key + "\": " + cast_value(attr_value)
+						type_attr = read_type(model, reverseKeyLookup(model["model"], attr_value))
+						if (read_type(model["metamodel"], type_attr) == "ComplexAttribute"):
+							result = result + ", \"" + attr_key + "\": {\"AL\": " + cast_value(attr_value) + "}"
+						else:
+							result = result + ", \"" + attr_key + "\": " + cast_value(attr_value)
 
 
 			result = result + "}"
 			result = result + "}"
 	result = result + "]"
 	result = result + "]"

+ 4 - 0
kernel/modelverse_kernel/primitives.py

@@ -306,8 +306,12 @@ def is_physical_action(a, **remainder):
     yield [("RETURN", [{'value': isinstance(a['value'], dict) and a['value']["value"] in ["if", "while", "assign", "call", "break", "continue", "return", "resolve", "access", "constant", "global", "declare"]}])]
     yield [("RETURN", [{'value': isinstance(a['value'], dict) and a['value']["value"] in ["if", "while", "assign", "call", "break", "continue", "return", "resolve", "access", "constant", "global", "declare"]}])]
 
 
 def is_physical_none(a, **remainder):
 def is_physical_none(a, **remainder):
+    if a['id'] is None:
+        yield [("RETURN", [{"value": True}])]
     if "value" not in a:
     if "value" not in a:
         a['value'], = yield [("RV", [a['id']])]
         a['value'], = yield [("RV", [a['id']])]
+    elif a['value'] is None:
+        yield [("RETURN", [{"value": True}])]
     yield [("RETURN", [{'value': isinstance(a['value'], dict) and a['value']["value"] == "none"}])]
     yield [("RETURN", [{'value': isinstance(a['value'], dict) and a['value']["value"] == "none"}])]
 
 
 def create_node(**remainder):
 def create_node(**remainder):

+ 1 - 0
wrappers/classes/modelverse.xml

@@ -422,6 +422,7 @@
                         <transition target="../../wait_for_action/history">
                         <transition target="../../wait_for_action/history">
                             <script>
                             <script>
                                 self.registered_metamodel[self.parameters[0]] = self.parameters[1]
                                 self.registered_metamodel[self.parameters[0]] = self.parameters[1]
+                                #print("Alter context of " + str(self.parameters[0]) + " to " + str(self.parameters[1]))
                             </script>
                             </script>
                         </transition>
                         </transition>
                     </state>
                     </state>

+ 2 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Mon May 28 17:39:21 2018
+Date:   Tue May 29 13:30:50 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server
@@ -2592,6 +2592,7 @@ class Modelverse(RuntimeClassBase):
     
     
     def _initialized_behaviour_operations_alter_context_0_exec(self, parameters):
     def _initialized_behaviour_operations_alter_context_0_exec(self, parameters):
         self.registered_metamodel[self.parameters[0]] = self.parameters[1]
         self.registered_metamodel[self.parameters[0]] = self.parameters[1]
+        #print("Alter context of " + str(self.parameters[0]) + " to " + str(self.parameters[1]))
     
     
     def _initialized_behaviour_operations_model_overwrite_init_0_guard(self, parameters):
     def _initialized_behaviour_operations_model_overwrite_init_0_guard(self, parameters):
         return self.parameters[0] in self.registered_metamodel
         return self.parameters[0] in self.registered_metamodel