Bladeren bron

Made conformance_scd a bit more readable and fixed some latent bugs in
the code

Yentl Van Tendeloo 9 jaren geleden
bovenliggende
commit
c18fc802c0

+ 1 - 1
bootstrap/bootstrap.py

@@ -105,7 +105,7 @@ primitives = {  "integer_addition": ["Integer", "Integer", "Integer"],
                 "element_neq": ["Boolean", "Element", "Element"],
                 "read_root": ["Element"],
                 "deserialize": ["Element", "String"],
-                "log": ["Element", "String"],
+                "log": ["String", "String"],
             }
 
 initial_user = "user_manager"

+ 31 - 31
bootstrap/conformance_scd.alc

@@ -13,15 +13,15 @@ Element function set_copy(elem_to_copy : Element):
 	// Expand the provided list by including all elements that need to be checked
 	counter_copy = 0
 	max = read_nr_out(elem_to_copy)
-	while (integer_lt(counter_copy, max)):
+	while (counter_copy < max):
 		set_add(result, read_edge_dst(read_out(elem_to_copy, counter_copy)))
-		counter_copy = integer_addition(counter_copy, 1)
+		counter_copy = counter_copy + 1
 
 	return result
 
 Boolean function is_direct_instance(model_idi : Element, instance_idi : Element, type_idi : Element):
 	// Just check whether or not the type mapping specifies the type as the type of the instance
-	return element_eq(dict_read_node(dict_read(model_idi, "type_mapping"), instance_idi), type_idi)
+	return dict_read_node(dict_read(model_idi, "type_mapping"), instance_idi) == type_idi
 
 Boolean function is_nominal_instance(model_ini : Element, instance_ini : Element, type_ini : Element):
 	return is_nominal_subtype(type_ini, dict_read_node(dict_read(model_ini, "type_mapping"), instance_ini), dict_read(dict_read(model_ini, "metamodel"), "type_mapping"), dict_read(model_ini, "inheritance"))
@@ -33,24 +33,24 @@ Boolean function is_nominal_subtype(superclass : Element, subclass : Element, ty
 	Element destination_iso
 
 	// End of recursion
-	if (element_eq(superclass, subclass)):
+	if (superclass == subclass):
 		return True
 
 	// Iterate over all superclasses of the found class
 	counter_iso = read_nr_out(subclass)
 	i_iso = 0
-	while (integer_lt(i_iso, counter_iso)):
+	while (i_iso < counter_iso):
 		edge_iso = read_out(subclass, i_iso)
 		// Check if it even has a type (to prevent errors)
 		if (dict_in_node(types, edge_iso)):
 			// Check whether it is an inheritance edge, as there is no other distinction between them
-			if (element_eq(dict_read_node(types, edge_iso), inheritance_link)):
+			if (dict_read_node(types, edge_iso) == inheritance_link):
 				// It is an inheritance edge, so follow it to its destination
 				destination_iso = read_edge_dst(edge_iso)
 				// Found a new superclass to test
 				if (is_nominal_subtype(superclass, destination_iso, types, inheritance_link)):
 					return True
-		i_iso = integer_addition(i_iso, 1)
+		i_iso = i_iso + 1
 	
 	// No link seems to have been found, so it is False
 	return False
@@ -60,7 +60,7 @@ Boolean function is_structural_instance(model_isi : Element, instance_isi : Elem
 	
 Boolean function is_structural_subtype(subtype_isi : Element, supertype_isi : Element):
 	// Determine whether it is just the exact type or not
-	if (element_eq(subtype_isi, supertype_isi)):
+	if (subtype_isi == supertype_isi):
 		return True
 
 	// Find all links that are required (name and type) from the specified type
@@ -75,7 +75,7 @@ Boolean function is_structural_subtype(subtype_isi : Element, supertype_isi : El
 	i_isi = 0
 
 	// Go over all keys that we require
-	while (integer_lt(i_isi, required_keys_len_isi)):
+	while (i_isi < required_keys_len_isi):
 		key_isi = set_pop(required_keys_isi)
 		// Check whether they exist in the instance
 		if (dict_in(subtype_isi, key_isi)):
@@ -88,7 +88,7 @@ Boolean function is_structural_subtype(subtype_isi : Element, supertype_isi : El
 				return False
 
 			// All clear, so pass on to the next attribute
-			i_isi = integer_addition(i_isi, 1)
+			i_isi = i_isi + 1
 		else:
 			return False
 
@@ -115,34 +115,34 @@ String function conformance_scd(model : Element):
 	metamodel_typing = dict_read(dict_read(model, "metamodel"), "type_mapping")
 
 	// Iterate over all model elements and check if they are typed (in "typing") and their type is in the metamodel
-	while (integer_gt(dict_len(models), 0)):
+	while (dict_len(models) > 0):
 		work_conf = set_pop(models)
 		// Basic check: does the element have a type
 		if (bool_not(dict_in_node(typing, work_conf))):
-			return string_join("Model has no type specified: ", getName(model, work_conf))
+			return "Model has no type specified: " + getName(model, work_conf)
 
 		// Basic check: is the type of the element part of the metamodel
 		if (bool_not(set_in_node(metamodels, dict_read_node(typing, work_conf)))):
-			return string_join("Type of element not in specified metamodel: ", getName(model, work_conf))
+			return "Type of element not in specified metamodel: " + getName(model, work_conf)
 
 		// Basic check: type of the value agrees with the actual type
 		// this is always checked, as it falls back to a sane default for non-values
 		if (bool_not(type_eq(dict_read_node(typing, work_conf), typeof(work_conf)))):
-			return string_join("Primitive type does not agree with actual type: ", getName(model, work_conf))
+			return "Primitive type does not agree with actual type: " + getName(model, work_conf)
 
 		// For edges only: check whether the source is typed according to the metamodel
 		if (is_edge(work_conf)):
 			model_src = read_edge_src(work_conf)
 			metamodel_src = read_edge_src(dict_read_node(typing, work_conf))
 			if (bool_not(is_nominal_instance(model, model_src, metamodel_src))):
-				return string_join("Source of model edge not typed by source of type: ", getName(model, work_conf))
+				return "Source of model edge not typed by source of type: " + getName(model, work_conf)
 
 		// For edges only: check whether the destination is typed according to the metamodel
 		if (is_edge(work_conf)):
 			model_dst = read_edge_dst(work_conf)
 			metamodel_dst = read_edge_dst(dict_read_node(typing, work_conf))
 			if (bool_not(is_nominal_instance(model, model_dst, metamodel_dst))):
-				return string_join("Destination of model edge not typed by destination of type: ", getName(model, work_conf))
+				return "Destination of model edge not typed by destination of type: " + getName(model, work_conf)
 
 	// Structure seems fine, now do static semantics
 	if (dict_in(dict_read(model, "metamodel"), "constraints")):
@@ -171,9 +171,9 @@ Element function retype(model_rt : Element, metamodel_rt : Element, inheritance_
 	return model_rt
 
 Element function add_to_model(model_atm : Element, name_atm : String, element_atm : Element):
-	if (string_eq(name_atm, "")):
+	if (name_atm == ""):
 		// No name desired
-		dict_add(dict_read(model_atm, "model"), string_join("__", cast_id2s(element_atm)), element_atm)
+		dict_add(dict_read(model_atm, "model"), "__" + cast_id2s(element_atm), element_atm)
 	else:
 		dict_add(dict_read(model_atm, "model"), name_atm, element_atm)
 	return element_atm
@@ -205,7 +205,7 @@ Element function instantiate_model_lib(model_mo : Element, type_mo : Element, na
 		// Create a new edge from "optionals[0]" to "optionals[1]"
 		new_element_mo = instantiate_bottom_edge(model_mo, name_mo, list_read(optionals, 0), list_read(optionals, 1))
 	else:
-		if (type_eq(typeof(type_mo), Type)):
+		if (typeof(type_mo) == Type):
 			new_element_mo = instantiate_bottom_value(model_mo, name_mo, list_read(optionals, 0))
 		else:
 			new_element_mo = instantiate_bottom_node(model_mo, name_mo)
@@ -229,7 +229,7 @@ Element function instantiate_model_lib(model_mo : Element, type_mo : Element, na
 	metamodel_mo = dict_read(dict_read(model_mo, "metamodel"), "model")
 
 	// For all new attributes
-	while (integer_lt(counter_mo, max_mo)):
+	while (counter_mo < max_mo):
 		attr_name_mo = set_pop(keys_mo)
 		attr_type_mo = dict_read(attribute_types, attr_name_mo)
 
@@ -237,10 +237,10 @@ Element function instantiate_model_lib(model_mo : Element, type_mo : Element, na
 		created_edge_mo = create_edge(created_attr_mo, attr_name_mo)
 		
 		// Add it to the model
-		dict_add(dict_read(model_mo, "model"), string_join("__", cast_id2s(attr_name_mo)), attr_name_mo)
-		dict_add(dict_read(model_mo, "model"), string_join("__", cast_id2s(attr_type_mo)), attr_type_mo)
-		dict_add(dict_read(model_mo, "model"), string_join("__", cast_id2s(created_attr_mo)), created_attr_mo)
-		dict_add(dict_read(model_mo, "model"), string_join("__", cast_id2s(created_edge_mo)), created_edge_mo)
+		dict_add(dict_read(model_mo, "model"), "__" + cast_id2s(attr_name_mo), attr_name_mo)
+		dict_add(dict_read(model_mo, "model"), "__" + cast_id2s(attr_type_mo), attr_type_mo)
+		dict_add(dict_read(model_mo, "model"), "__" + cast_id2s(created_attr_mo), created_attr_mo)
+		dict_add(dict_read(model_mo, "model"), "__" + cast_id2s(created_edge_mo), created_edge_mo)
 
 		// And add the typing
 		dict_add(dict_read(model_mo, "type_mapping"), attr_name_mo, dict_read(metamodel_mo, "__String"))
@@ -249,7 +249,7 @@ Element function instantiate_model_lib(model_mo : Element, type_mo : Element, na
 		dict_add(dict_read(model_mo, "type_mapping"), created_edge_mo, dict_read(metamodel_mo, "__Name"))
 
 		// Increase while loop counter
-		counter_mo = integer_addition(counter_mo, 1)
+		counter_mo = counter_mo + 1
 
 	// Similarly for instantiated attributes
 	counter_mo = 0
@@ -260,7 +260,7 @@ Element function instantiate_model_lib(model_mo : Element, type_mo : Element, na
 	Element attr_value_mo
 	Element attr_edge_mo
 
-	while (integer_lt(counter_mo, max_mo)):
+	while (counter_mo < max_mo):
 		// Look it up
 		attr_name_mo = set_pop(keys_mo)
 		attr_value_mo = dict_read(attribute_instances, attr_name_mo)
@@ -270,14 +270,14 @@ Element function instantiate_model_lib(model_mo : Element, type_mo : Element, na
 		attr_edge_mo = create_edge(new_element_mo, attr_value_mo)
 
 		// Add to model
-		dict_add(dict_read(model_mo, "model"), string_join("__", cast_id2s(attr_value_mo)), attr_value_mo)
-		dict_add(dict_read(model_mo, "model"), string_join("__", cast_id2s(attr_edge_mo)), attr_edge_mo)
+		dict_add(dict_read(model_mo, "model"), "__" + cast_id2s(attr_value_mo), attr_value_mo)
+		dict_add(dict_read(model_mo, "model"), "__" + cast_id2s(attr_edge_mo), attr_edge_mo)
 
 		// Type the new elements
 		dict_add(dict_read(model_mo, "type_mapping"), attr_value_mo, attr_type_mo)
 		dict_add(dict_read(model_mo, "type_mapping"), attr_edge_mo, attr_type_edge_mo)
 
-		counter_mo = integer_addition(counter_mo, 1)
+		counter_mo = counter_mo + 1
 
 	return new_element_mo
 
@@ -302,12 +302,12 @@ Element function generate_bottom_type_mapping(model_tm : Element):
 	Element elem_keys_tm
 	Element elem_tm
 	elem_keys_tm = dict_keys(dict_read(model_tm, "model"))
-	while (integer_lt(0, read_nr_out(elem_keys_tm))):
+	while (0 < read_nr_out(elem_keys_tm)):
 		elem_tm = dict_read(dict_read(model_tm, "model"), set_pop(elem_keys_tm))
 		if (is_edge(elem_tm)):
 			dict_add(tm_tm, elem_tm, dict_read(mm_tm, "Edge"))
 		else:
-			if (string_neq(cast_v2s(elem_tm), "None")):
+			if (cast_v2s(elem_tm) != "None"):
 				dict_add(tm_tm, elem_tm, dict_read(mm_tm, cast_v2s(typeof(elem_tm))))
 			else:
 				dict_add(tm_tm, elem_tm, dict_read(mm_tm, "Node"))

+ 7 - 1
interface/HUTN/hutn_compiler/semantics_visitor.py

@@ -128,8 +128,13 @@ class SemanticsVisitor(Visitor):
             l, op, r = child.get_tail()
             l_type, r_type = self.get_type(l), self.get_type(r)
             if type(l_type) != type(r_type):
+                print("Error: " + str(l_type) + " <-> " + str(r_type))
                 raise RuntimeError(
-                    "error in visit_conjuction: children were not casted")
+                    "{}:{}:{}: error: children were not casted".format(
+                        self.inputfiles[0],
+                        tree.startpos['line'],
+                        tree.startpos['column']
+                    ))
             call_name = SemanticsVisitor.call_name_binary(l_type, op)
             call_tree = SemanticsVisitor.func_call(call_name, [l, r])
             try:
@@ -258,6 +263,7 @@ class SemanticsVisitor(Visitor):
         "Boolean": "bool",
         "String": "string",
         "Action": "action",
+        "Element": "element",
         "Type": "type"
     }
 

+ 2 - 2
interface/HUTN/includes/object_operations.alh

@@ -8,5 +8,5 @@ Element function setAttribute(a: Element, b: Element, c: String, d: Element)
 Element function deleteAttribute(a: Element, b: Element, c: Element)
 Element function getAttributeList(a: Element, b: Element)
 Element function getInstantiatableAttributes(a: Element, b: Element)
-Element function getName(a: Element, b: Element)
-Element function reverseNameLookup(a: Element, b: Element)
+String function getName(a: Element, b: Element)
+String function reverseNameLookup(a: Element, b: Element)

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

@@ -89,7 +89,7 @@ Boolean function type_eq(a: Type, b: Type)
 Boolean function type_neq(a: Type, b: Type) 
 Type function typeof(a: Element) 
 Element function deserialize(a: String) 
-Element function log(a: String)
+String function log(a: String)
 Element function read_root()
 Element function exec(a : Element)
 Element function input()