Browse Source

Ported some code to [] syntax instead of dict_read (where possible)

Yentl Van Tendeloo 9 years ago
parent
commit
c0082ee27b
3 changed files with 59 additions and 51 deletions
  1. 10 7
      bootstrap/compilation_manager.alc
  2. 42 37
      bootstrap/conformance_scd.alc
  3. 7 7
      bootstrap/constructors.alc

+ 10 - 7
bootstrap/compilation_manager.alc

@@ -5,13 +5,16 @@ Element function compilation_manager():
 	String operation
 	String object_name
 	Element root
+	Element mv_root
 	Element node
 
-	if (dict_in(dict_read(read_root(), "__hierarchy"), "objects")):
-		root = dict_read(dict_read(read_root(), "__hierarchy"), "objects")
+	mv_root = read_root()
+
+	if (dict_in(mv_root["__hierarchy"], "objects")):
+		root = mv_root["__hierarchy"]["objects"]
 	else:
 		root = create_node()
-		dict_add(dict_read(read_root(), "__hierarchy"), "objects", root)
+		dict_add(mv_root["__hierarchy"], "objects", root)
 
 	operation = input()
 	if (operation == "upload"):
@@ -32,27 +35,27 @@ Element function compilation_manager():
 	elif (operation == "read_symbols"):
 		Element keys
 		object_name = input()
-		node = dict_read(dict_read(root, object_name), "symbols")
+		node = root[object_name]["symbols"]
 		keys = dict_keys(node)
 		String rv
 		rv = ""
 		String key
 		while (0 < read_nr_out(keys)):
 			key = set_pop(keys)
-			if (dict_read(node, key)):
+			if (node[key]):
 				rv = (rv + key) + ":1\n"
 			else:
 				rv = (rv + key) + ":0\n"
 		output(rv)
 	elif (operation == "read_initializers"):
-		node = dict_read(dict_read(root, input()), "initializers")
+		node = root[input()]["initializers"]
 		output(node)
 	elif (operation == "remove_obj"):
 		dict_delete(root, input())
 	elif (operation == "is_defined"):
 		object_name = input()
 		if (dict_in(root, object_name)):
-			output(dict_read(dict_read(root, object_name), "hash_md5"))
+			output(root[object_name]["hash_md5"])
 		else:
 			output(create_node())
 	else:

+ 42 - 37
bootstrap/conformance_scd.alc

@@ -21,10 +21,10 @@ Element function set_copy(elem_to_copy : Element):
 
 Boolean function is_direct_instance(model : Element, instance : Element, type : Element):
 	// Just check whether or not the type mapping specifies the type as the type of the instance
-	return dict_read_node(dict_read(model, "type_mapping"), instance) == type
+	return dict_read_node(model["type_mapping"], instance) == type
 
 Boolean function is_nominal_instance(model : Element, instance : Element, type : Element):
-	return is_nominal_subtype(type, dict_read_node(dict_read(model, "type_mapping"), instance), dict_read(dict_read(model, "metamodel"), "type_mapping"), dict_read(model, "inheritance"))
+	return is_nominal_subtype(type, dict_read_node(model["type_mapping"], instance), model["metamodel"]["type_mapping"], model["inheritance"])
 
 Boolean function is_nominal_subtype(superclass : Element, subclass : Element, types : Element, inheritance_link : Element):
 	Integer counter
@@ -56,7 +56,7 @@ Boolean function is_nominal_subtype(superclass : Element, subclass : Element, ty
 	return False
 
 Boolean function is_structural_instance(model : Element, instance : Element, type : Element):
-	return is_structural_subtype(dict_read_node(dict_read(model, "type_mapping"), instance), type)
+	return is_structural_subtype(dict_read_node(model["type_mapping"], instance), type)
 	
 Boolean function is_structural_subtype(subtype : Element, supertype : Element):
 	// Determine whether it is just the exact type or not
@@ -84,7 +84,7 @@ Boolean function is_structural_subtype(subtype : Element, supertype : Element):
 			// TODO
 
 			// Still check whether the types match
-			if (bool_not(is_structural_subtype(dict_read(subtype, key), dict_read(supertype, key)))):
+			if (bool_not(is_structural_subtype(subtype[key], supertype[key]))):
 				return False
 
 			// All clear, so pass on to the next attribute
@@ -104,15 +104,15 @@ String function conformance_scd(model : Element):
 	Element metamodel_dst
 	Element models
 	Element metamodels
-	models = set_copy(dict_read(model, "model"))
+	models = set_copy(model["model"])
 
 	Element typing
-	typing = dict_read(model, "type_mapping")
-	metamodels = set_copy(dict_read(dict_read(model, "metamodel"), "model"))
+	typing = model["type_mapping"]
+	metamodels = set_copy(model["metamodel"]["model"])
 	Element inheritance
-	inheritance = dict_read(dict_read(model, "metamodel"), "inheritance")
+	inheritance = model["metamodel"]["inheritance"]
 	Element metamodel_typing
-	metamodel_typing = dict_read(dict_read(model, "metamodel"), "type_mapping")
+	metamodel_typing = 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 (dict_len(models) > 0):
@@ -145,9 +145,9 @@ String function conformance_scd(model : Element):
 				return "Destination of model edge not typed by destination of type: " + getName(model, work_node)
 
 	// Structure seems fine, now do static semantics
-	if (dict_in(dict_read(model, "metamodel"), "constraints")):
+	if (dict_in(model["metamodel"], "constraints")):
 		Element constraint_function
-		constraint_function = dict_read(dict_read(model, "metamodel"), "constraints")
+		constraint_function = model["metamodel"]["constraints"]
 		return constraint_function(model)
 	else:
 		return "OK"
@@ -173,9 +173,9 @@ Element function retype(model : Element, metamodel : Element, inheritance : Elem
 Element function add_to_model(model : Element, name : String, element : Element):
 	if (name == ""):
 		// No name desired
-		dict_add(dict_read(model, "model"), "__" + cast_id2s(element), element)
+		dict_add(model["model"], "__" + cast_id2s(element), element)
 	else:
-		dict_add(dict_read(model, "model"), name, element)
+		dict_add(model["model"], name, element)
 	return element
 
 Element function instantiate_bottom_node(model : Element, name : String):
@@ -211,7 +211,7 @@ Element function instantiate_model_lib(model : Element, type : Element, name : S
 			new_element = instantiate_bottom_node(model, name)
 
 	// Add it to the type mapping
-	dict_add(dict_read(model, "type_mapping"), new_element, type)
+	dict_add(model["type_mapping"], new_element, type)
 
 	// Add all attribute types at this level
 	Integer counter
@@ -226,27 +226,32 @@ Element function instantiate_model_lib(model : Element, type : Element, name : S
 	Element created_attr
 	Element created_edge
 	Element metamodel
-	metamodel = dict_read(dict_read(model, "metamodel"), "model")
+	metamodel = model["metamodel"]["model"]
 
 	// For all new attributes
 	while (counter < max):
 		attr_name = set_pop(keys)
-		attr_type = dict_read(attribute_types, attr_name)
+		attr_type = attribute_types[attr_name]
 
 		created_attr = create_edge(new_element, attr_type)
 		created_edge = create_edge(created_attr, attr_name)
 		
+		Element m
+		Element tm
+		m = model["model"]
+		tm = model["type_mapping"]
+
 		// Add it to the model
-		dict_add(dict_read(model, "model"), "__" + cast_id2s(attr_name), attr_name)
-		dict_add(dict_read(model, "model"), "__" + cast_id2s(attr_type), attr_type)
-		dict_add(dict_read(model, "model"), "__" + cast_id2s(created_attr), created_attr)
-		dict_add(dict_read(model, "model"), "__" + cast_id2s(created_edge), created_edge)
+		dict_add(m, "__" + cast_id2s(attr_name), attr_name)
+		dict_add(m, "__" + cast_id2s(attr_type), attr_type)
+		dict_add(m, "__" + cast_id2s(created_attr), created_attr)
+		dict_add(m, "__" + cast_id2s(created_edge), created_edge)
 
 		// And add the typing
-		dict_add(dict_read(model, "type_mapping"), attr_name, dict_read(metamodel, "__String"))
-		dict_add(dict_read(model, "type_mapping"), attr_type, dict_read(metamodel, "Type"))
-		dict_add(dict_read(model, "type_mapping"), created_attr, dict_read(metamodel, "Attribute"))
-		dict_add(dict_read(model, "type_mapping"), created_edge, dict_read(metamodel, "__Name"))
+		dict_add(tm, attr_name, metamodel["__String"])
+		dict_add(tm, attr_type, metamodel["Type"])
+		dict_add(tm, created_attr, metamodel["Attribute"])
+		dict_add(tm, created_edge, metamodel["__Name"])
 
 		// Increase while loop counter
 		counter = counter + 1
@@ -263,19 +268,19 @@ Element function instantiate_model_lib(model : Element, type : Element, name : S
 	while (counter < max):
 		// Look it up
 		attr_name = set_pop(keys)
-		attr_value = dict_read(attribute_instances, attr_name)
-		attr_definer_class = find_attribute(type, attr_name, dict_read(dict_read(model, "metamodel"), "type_mapping"), dict_read(model, "inheritance"))
-		attr_type = dict_read(attr_definer_class, attr_name)
+		attr_value = attribute_instances[attr_name]
+		attr_definer_class = find_attribute(type, attr_name, model["metamodel"]["type_mapping"], model["inheritance"])
+		attr_type = attr_definer_class[attr_name]
 		attr_type_edge = dict_read_edge(attr_definer_class, attr_name)
 		attr_edge = create_edge(new_element, attr_value)
 
 		// Add to model
-		dict_add(dict_read(model, "model"), "__" + cast_id2s(attr_value), attr_value)
-		dict_add(dict_read(model, "model"), "__" + cast_id2s(attr_edge), attr_edge)
+		dict_add(model["model"], "__" + cast_id2s(attr_value), attr_value)
+		dict_add(model["model"], "__" + cast_id2s(attr_edge), attr_edge)
 
 		// Type the new elements
-		dict_add(dict_read(model, "type_mapping"), attr_value, attr_type)
-		dict_add(dict_read(model, "type_mapping"), attr_edge, attr_type_edge)
+		dict_add(model["type_mapping"], attr_value, attr_type)
+		dict_add(model["type_mapping"], attr_edge, attr_type_edge)
 
 		counter = counter + 1
 
@@ -292,7 +297,7 @@ Element function instantiate_new_model(metamodel : Element, inheritance : Elemen
 
 Element function generate_bottom_type_mapping(model : Element):
 	Element mm
-	mm = dict_read(dict_read(model, "metamodel"), "model")
+	mm = model["metamodel"]["model"]
 	dict_delete(model, "type_mapping")
 	Element tm
 	tm = create_node()
@@ -301,15 +306,15 @@ Element function generate_bottom_type_mapping(model : Element):
 	// Iterate over every element
 	Element elem_keys
 	Element elem
-	elem_keys = dict_keys(dict_read(model, "model"))
+	elem_keys = dict_keys(model["model"])
 	while (0 < read_nr_out(elem_keys)):
-		elem = dict_read(dict_read(model, "model"), set_pop(elem_keys))
+		elem = model["model"][set_pop(elem_keys)]
 		if (is_edge(elem)):
-			dict_add(tm, elem, dict_read(mm, "Edge"))
+			dict_add(tm, elem, mm["Edge"])
 		else:
 			if (cast_v2s(elem) != "None"):
-				dict_add(tm, elem, dict_read(mm, cast_v2s(typeof(elem))))
+				dict_add(tm, elem, mm[cast_v2s(typeof(elem))])
 			else:
-				dict_add(tm, elem, dict_read(mm, "Node"))
+				dict_add(tm, elem, mm["Node"])
 
 	return model

+ 7 - 7
bootstrap/constructors.alc

@@ -321,13 +321,13 @@ Action function construct_funcdef():
 Action function construct_break():
 	Action this_element
 	this_element = create_value(!break)
-	dict_add(this_element, "while", dict_read(while_stack, list_len(while_stack) - 1))
+	dict_add(this_element, "while", while_stack[list_len(while_stack) - 1])
 	return this_element
 
 Action function construct_continue():
 	Action this_element
 	this_element = create_value(!continue)
-	dict_add(this_element, "while", dict_read(while_stack, list_len(while_stack) - 1))
+	dict_add(this_element, "while", while_stack[list_len(while_stack) - 1])
 	return this_element
 
 Element function instantiate_bottom(model : Element):
@@ -343,7 +343,7 @@ Element function instantiate_bottom(model : Element):
 	elif (bottom_type == "value"):
 		instantiate_bottom_value(model, element_name, input())
 	elif (bottom_type == "edge"):
-		instantiate_bottom_edge(model, element_name, dict_read(dict_read(model, "model"), input()), dict_read(dict_read(model, "model"), input()))
+		instantiate_bottom_edge(model, element_name, model["model"][input()], model["model"][input()])
 
 	// If there is more to come, we also add these elements
 	if (input()):
@@ -353,7 +353,7 @@ Element function instantiate_bottom(model : Element):
 
 Void function instantiate_model(model : Element):
 	Element type
-	type = dict_read(dict_read(dict_read(model, "metamodel"), "model"), input())
+	type = model["metamodel"]["model"][input()]
 
 	String name
 	name = input()
@@ -361,8 +361,8 @@ Void function instantiate_model(model : Element):
 	Element params
 	params = create_node()
 	if (is_edge(type)):
-		list_append(params, dict_read(dict_read(model, "model"), input()))
-		list_append(params, dict_read(dict_read(model, "model"), input()))
+		list_append(params, model["model"][input()])
+		list_append(params, model["model"][input()])
 	elif (type_eq(typeof(type), Type)):
 		list_append(params, input())
 
@@ -393,7 +393,7 @@ Element function retype_model(model : Element):
 	Element mapping
 	mapping = create_node()
 	while (input()):
-		dict_add(mapping, dict_read(dict_read(model, "model"), input()), dict_read(dict_read(metamodel, "model"), input()))
+		dict_add(mapping, model["model"][input()], metamodel["model"][input()])
 
 	return retype(model, metamodel, inheritance, mapping)