Browse Source

Minor tweak

Yentl Van Tendeloo 3 years ago
parent
commit
6abefdf018

+ 21 - 14
bootstrap/model_management.alc

@@ -79,36 +79,41 @@ Element function model_copy(src_model : Element):
 	Integer prev_length
 	Element reverse
 
-	reverse = make_reverse_dictionary(src_model["model"])
+	Element src_model_model
+	Element dst_model_model
+	src_model_model = src_model["model"]
+
+	reverse = make_reverse_dictionary(src_model_model)
 
 	dst_model = instantiate_model(src_model["metamodel"])
-	keys = dict_keys(src_model["model"])
+	dst_model_model = dst_model["model"]
+	keys = dict_keys(src_model_model)
 	second_keys = set_create()
 	prev_length = -1
 
 	while (set_len(keys) > 0):
 		name = set_pop(keys)
 
-		if (is_edge(src_model["model"][name])):
+		if (is_edge(src_model_model[name])):
 			// Is an edge, so potentially queue it
 			String src
 			String dst
 
-			src = reverse[cast_id(read_edge_src(src_model["model"][name]))]
-			dst = reverse[cast_id(read_edge_dst(src_model["model"][name]))]
+			src = reverse[cast_id(read_edge_src(src_model_model[name]))]
+			dst = reverse[cast_id(read_edge_dst(src_model_model[name]))]
 
 			type = read_type(src_model, name)
 
-			if (bool_and(dict_in(dst_model["model"], src), dict_in(dst_model["model"], dst))):
+			if (bool_and(dict_in(dst_model_model, src), dict_in(dst_model_model, dst))):
 				// All present, so create the link between them
 				instantiate_link(dst_model, type, name, src, dst)
 			else:
 				set_add(second_keys, name)
 
-		elif (has_value(src_model["model"][name])):
+		elif (has_value(src_model_model[name])):
 			// Has a value, so copy that as well
 			type = read_type(src_model, name)
-			instantiate_value(dst_model, type, name, src_model["model"][name])
+			instantiate_value(dst_model, type, name, src_model_model[name])
 
 		else:
 			// Is a node
@@ -140,6 +145,7 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 	String key
 	String type
 	Integer prev_length
+	Element model_model
 
 	new_model = instantiate_model(metamodel)
 	elem_map = dict_create()
@@ -152,6 +158,7 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 		tagged_model = set_pop(models)
 		retyping_key = string_join(list_read(tagged_model, 0), "/")
 		model = list_read(tagged_model, 1)
+		model_model = model["model"]
 		set_add(retyping_keys, retyping_key)
 
 		// Add all elements from 'model'
@@ -166,22 +173,22 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 
 			new_name = retyping_key + key
 
-			if (is_edge(model["model"][key])):
-				src = cast_id(read_edge_src(model["model"][key]))
-				dst = cast_id(read_edge_dst(model["model"][key]))
+			if (is_edge(model_model[key])):
+				src = cast_id(read_edge_src(model_model[key]))
+				dst = cast_id(read_edge_dst(model_model[key]))
 				if (bool_and(dict_in(elem_map, src), dict_in(elem_map, dst))):
 					new_name = instantiate_link(new_model, retyping_key + type, new_name, elem_map[src], elem_map[dst])
 				else:
 					set_add(second_keys, key)
 					new_name = ""
-			elif (has_value(model["model"][key])):
-				new_name = instantiate_value(new_model, retyping_key + type, new_name, model["model"][key])
+			elif (has_value(model_model[key])):
+				new_name = instantiate_value(new_model, retyping_key + type, new_name, model_model[key])
 			else:
 				new_name = instantiate_node(new_model, retyping_key + type, new_name)
 
 			if (new_name != ""):
 				// Add the new name to a map which registers the mapping to the new name
-				dict_add_fast(elem_map, cast_id(model["model"][key]), new_name)
+				dict_add_fast(elem_map, cast_id(model_model[key]), new_name)
 
 			if (set_len(keys) == 0):
 				if (set_len(second_keys) == prev_length):

+ 1 - 1
interface/HUTN/hutn_compiler/compiler.py

@@ -17,7 +17,7 @@ import hashlib
 global parsers
 parsers = {}
 
-sys.setrecursionlimit(2000)
+sys.setrecursionlimit(200000)
 
 def read(filename):
   with open(filename, 'r') as f:

+ 13 - 0
interface/HUTN/hutn_compiler/hutnparser.py

@@ -767,9 +767,22 @@ class Parser(object):
             if not j in self.countcard[cardrule]:  # # if we already know the count for j, then ignore..
                 d = self.countcard[cardrule]
                 lastcount = 0
+                ## Performance bottleneck
+                #print("J: %s, d: %s" % (j, d))
                 for i in range(0, j):
                     if i in d:
                         lastcount = d[i]
+                #print("Result: " + str(lastcount))
+                ## End of performance bottleneck
+                new_lastcount = 0
+                for i in sorted(d.keys()):
+                    if i < j:
+                        new_lastcount = d[i]
+                    else:
+                        break
+                if lastcount != new_lastcount:
+                    raise Exception()
+                ## End new code
                 count = lastcount + delta
                 d.update({j: count})
             else: