Kaynağa Gözat

Faster allInstances function

Yentl Van Tendeloo 8 yıl önce
ebeveyn
işleme
4d29670d2f

+ 33 - 0
bootstrap/modelling.alc

@@ -153,6 +153,39 @@ String function find_attribute_type(model : Element, elem : String, name : Strin
 		result = reverseKeyLookup(model["metamodel"]["model"], dict_read_edge(model["metamodel"]["model"][mm_elem], name))
 		return result!
 
+Element function get_subclasses(model : Element, name : String):
+	Element result
+	Integer i
+	Integer j
+	Integer num_edges
+	Element edge
+	String elem
+	Element nodes
+	Element inheritance
+
+	nodes = create_node()
+	set_add(nodes, name)
+	inheritance = "Inheritance"
+
+	// Initialize empty set
+	result = create_node()
+	i = 0
+
+	while (list_len(nodes) > 0):
+		elem = set_pop(nodes)
+		if (bool_not(set_in(result, elem))):
+			create_edge(result, elem)
+			// Read out all incoming edges
+			num_edges = read_nr_in(model["model"][elem])
+			j = 0
+			while (j < num_edges):
+				edge = read_in(model["model"][elem], j)
+				if (value_eq(model["type_mapping"][reverseKeyLookup(model["model"], edge)], inheritance)):
+					set_add(nodes, reverseKeyLookup(model["model"], read_edge_src(edge)))
+				j = j + 1
+
+	return result!
+
 Element function get_superclasses(model : Element, name : String):
 	Element result
 	Integer i

+ 26 - 6
bootstrap/object_operations.alc

@@ -3,20 +3,20 @@ include "conformance_scd.alh"
 include "constructors.alh"
 include "modelling.alh"
 
-Element function allInstances(model : Element, type_name : String):
+Element function allInstancesSlow(model : Element, type_name : String):
 	Element result
-	Element type
 
 	String key
 	Element keys
 
+	// TODO more efficient implementation!
 	keys = dict_keys(model["model"])
 	if (dict_in(model["metamodel"]["model"], type_name)):
-		type = model["metamodel"]["model"][type_name]
 		result = create_node()
 
 		// TODO more efficient to work backwards: find all instances of an element through the type mapping directly
 		//      must then take into account all inheritance links ourselves...
+		log(cast_v2s(list_len(keys)))
 		while (0 < list_len(keys)):
 			key = set_pop(keys)
 			if (is_nominal_instance(model, key, type_name)):
@@ -27,19 +27,39 @@ Element function allInstances(model : Element, type_name : String):
 		log("No such type in the metamodel!")
 		return create_node()!
 
+Element function allInstances(model : Element, type_name : String):
+	if (dict_in(model["metamodel"]["model"], type_name)):
+		Element result
+		Element accepted
+		Element keys
+		Element tm
+		String key
+
+		result = create_node()
+		accepted = get_subclasses(model["metamodel"], type_name)
+
+		tm = model["type_mapping"]
+		keys = dict_keys(tm)
+		while (0 < list_len(keys)):
+			key = set_pop(keys)
+			if (set_in(accepted, tm[key])):
+				set_add(result, key)
+
+		return result!
+	else:
+		log("No such type in the metamodel!")
+		return create_node()!
+
 Element function selectPossibleIncoming(model : Element, target : String, limit_set : Element):
 	// Find all possible incoming link types for the target model
 	// Should also include those specified on the superclass(es)
-
 	String type
 	Element model_dict
 	Element elem
 	Element result
 	Element target_element
-
 	result = create_node()
 	model_dict = model["model"]
-
 	while (0 < list_len(limit_set)):
 		type = set_pop(limit_set)
 		elem = model_dict[type]

+ 1 - 0
core/core_algorithm.alc

@@ -429,6 +429,7 @@ Void function user_function_skip_init(user_id : String):
 			output("    model_list                      -- List all models")
 			output("    model_list_full                 -- List all models with full info")
 			output("    model_overwrite                 -- Overwrites a model with an uploaded model, leaving all metadata")
+			output("    verify                          -- Check whether a model conforms to its metamodel")
 			output("")
 			output("Transformation-specific operations")
 			output("    transformation_add_MT_language  -- Create a RAMified metamodel of a set of models")

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

@@ -10,6 +10,7 @@ String function instantiate_node(model : Element, type_name : String, instance_n
 String function instantiate_value(model : Element, type_name : String, instance_name : String, value : Element)
 Element function find_attribute_type(model : Element, elem : String, name : String)
 Element function get_superclasses(model : Element, elem : Element)
+Element function get_subclasses(model : Element, elem : Element)
 Element function find_attribute_definer(model : Element, elem : Element, name : String)
 Void function instantiate_attribute(model : Element, element : String, attribute_name : String, value : Element)
 Void function instantiate_attribute_code(model : Element, element : String, attribute_name : String, code : Element)

+ 4 - 4
kernel/modelverse_kernel/primitives.py

@@ -395,18 +395,18 @@ def read_nr_out(a, **remainder):
     result, = yield [("CNV", [len(outgoing)])]
     raise PrimitiveFinished(result)
 
-def read_out(a, b, **remainder):
+def read_out(a, b, root, **remainder):
     outgoing, b_value = yield [("RO", [a]), ("RV", [b])]
-    raise PrimitiveFinished(sorted(outgoing)[b_value])
+    raise PrimitiveFinished(sorted(outgoing)[b_value] if len(outgoing) > b_value else root)
 
 def read_nr_in(a, **remainder):
     incoming, = yield [("RI", [a])]
     result, = yield [("CNV", [len(incoming)])]
     raise PrimitiveFinished(result)
 
-def read_in(a, b, **remainder):
+def read_in(a, b, root, **remainder):
     incoming, b_value = yield [("RI", [a]), ("RV", [b])]
-    raise PrimitiveFinished(sorted(incoming)[b_value])
+    raise PrimitiveFinished(sorted(incoming)[b_value] if len(incoming) > b_value else root)
 
 def read_edge_src(a, **remainder):
     result, = yield [("RE", [a])]

+ 1 - 1
scripts/run_MvC_server.py

@@ -19,7 +19,7 @@ subprocess.check_call([sys.executable, "-m", "sccd.compiler.sccdc", "-p", "threa
 
 # Start up the MvK as a subprocess
 try:
-    obj = subprocess.Popen([sys.executable, "run_mvk_server.py", str(MVK_PORT), "--kernel=baseline-jit"], cwd="hybrid_server")
+    obj = subprocess.Popen([sys.executable, "run_mvk_server.py", str(MVK_PORT)], cwd="hybrid_server")
     #obj = subprocess.Popen([sys.executable, "run_mvk_server.py", str(MVK_PORT), "--kernel=legacy-interpreter"], cwd="hybrid_server")
 
     # Compile all MvC code