Просмотр исходного кода

Merge remote-tracking branch 'yentl/yentl' into jit

jonathanvdc 8 лет назад
Родитель
Сommit
447afabfed
48 измененных файлов с 3073 добавлено и 1609 удалено
  1. 1 1
      .gitattributes
  2. 4 3
      bootstrap/bootstrap.py
  3. 0 0
      bootstrap/initial_code_manager.alb
  4. 0 0
      bootstrap/initial_code_user.alb
  5. 3 0
      bootstrap/metamodels.alc
  6. 95 16
      bootstrap/model_management.alc
  7. 80 3
      bootstrap/modelling.alc
  8. 21 0
      bootstrap/object_operations.alc
  9. 17 0
      bootstrap/primitives.alc
  10. 1 0
      bootstrap/ramify.alc
  11. 4 2
      bootstrap/transform.alc
  12. 1178 9
      core/core_algorithm.alc
  13. 43 2
      core/core_formalism.mvc
  14. 295 0
      core/mini_modify.alc
  15. 1 0
      core/mini_modify.alh
  16. 0 254
      integration/code/mini_modify.alc
  17. 0 1
      integration/code/mini_modify.alh
  18. 2 2
      integration/code/petrinets.mvc
  19. 2 0
      integration/code/pn_design.mvc
  20. 3 0
      integration/code/pn_design_model.mvc
  21. 39 39
      integration/code/pn_design_to_runtime.mvc
  22. 0 494
      integration/code/pn_interface.alc
  23. 2 2
      integration/code/pn_print.mvc
  24. 27 0
      integration/code/pn_print_MR.mvc
  25. 19 0
      integration/code/pn_runtime_MR.mvc
  26. 26 0
      integration/code/pn_runtime_model_MR.mvc
  27. 179 0
      integration/code/pn_runtime_to_design.mvc
  28. 19 18
      integration/code/pn_simulate.mvc
  29. 0 33
      integration/my_petrinet_with_MM_and_constraints.mvc
  30. 851 0
      integration/test_mvc.py
  31. 0 662
      integration/test_pn_interface.py
  32. 15 5
      integration/utils.py
  33. 1 1
      interface/HUTN/grammars/modelling.g
  34. 1 0
      interface/HUTN/hutn_compiler/semantics_visitor.py
  35. 3 1
      interface/HUTN/includes/model_management.alh
  36. 1 0
      interface/HUTN/includes/modelling.alh
  37. 1 0
      interface/HUTN/includes/object_operations.alh
  38. 2 0
      interface/HUTN/includes/primitives.alh
  39. 3 1
      kernel/modelverse_kernel/compiled.py
  40. 13 9
      kernel/modelverse_kernel/legacy.py
  41. 31 22
      kernel/modelverse_kernel/main.py
  42. 7 0
      kernel/modelverse_kernel/primitives.py
  43. 16 10
      scripts/compile.py
  44. 12 2
      scripts/execute_model.py
  45. 9 12
      scripts/prompt.py
  46. 42 0
      scripts/run_MvC_server.py
  47. 4 0
      scripts/test_compile.py
  48. 0 5
      state/modelverse_state/main.py

+ 1 - 1
.gitattributes

@@ -1 +1 @@
-*.m binary
+*.gz merge=keepTheir

+ 4 - 3
bootstrap/bootstrap.py

@@ -8,9 +8,9 @@ def bootstrap():
     root = ["__hierarchy"]
 
     user_manager = "user_manager"
-    bootstrap_files = glob.glob("bootstrap/*.alc")
-    initial_code_manager = "bootstrap/initial_code_manager.alc"
-    initial_code_user = "bootstrap/initial_code_user.alc"
+    initial_code_manager = "bootstrap/initial_code_manager.alb"
+    initial_code_user = "bootstrap/initial_code_user.alb"
+    bootstrap_files = glob.glob("bootstrap/*.alc") + [initial_code_manager, initial_code_user]
 
     user_data = [   "input",
                     "output",
@@ -106,6 +106,7 @@ def bootstrap():
                     "deserialize": ["Element", "String"],
                     "log": ["String", "String"],
                     "time": ["Float"],
+                    "hash": ["String", "String"],
                 }
 
     jit_primitives = {

bootstrap/initial_code_manager.alc → bootstrap/initial_code_manager.alb


bootstrap/initial_code_user.alc → bootstrap/initial_code_user.alb


+ 3 - 0
bootstrap/metamodels.alc

@@ -146,6 +146,9 @@ Element function constraint_call(model : Element, name : String):
 		return "Expected physical action value"!
 
 Element function initialize_SCD(location : String):
+	if (import_node(location) != read_root()):
+		return import_node(location)!
+
 	Element scd
 	scd = instantiate_bottom()
 

+ 95 - 16
bootstrap/model_management.alc

@@ -6,7 +6,7 @@ include "metamodels.alh"
 include "library.alh"
 include "modelling.alh"
 
-Element function model_fuse(name1 : String, model1 : Element, name2 : String, model2 : Element):
+Element function model_fuse(models : Element):
 	Element new_model
 	Element tagged_model
 	String model_name
@@ -15,27 +15,16 @@ Element function model_fuse(name1 : String, model1 : Element, name2 : String, mo
 	String key
 	Element selected_MM
 	String type
-	Element models
 
 	// Read out some data first
-	selected_MM = model1["metamodel"]
-	new_model = instantiate_model(selected_MM)
-
-	// Create a list to nicely iterate over it
-	models = create_node()
-	tagged_model = create_node()
-	list_append(tagged_model, name1)
-	list_append(tagged_model, model1)
-	list_append(models, tagged_model)
-	tagged_model = create_node()
-	list_append(tagged_model, name2)
-	list_append(tagged_model, model2)
-	list_append(models, tagged_model)
+	tagged_model = set_pop(models)
+	set_add(models, tagged_model)
+	new_model = instantiate_model(tagged_model[1]["metamodel"])
 
 	// Do the iteration
 	while (read_nr_out(models)):
 		tagged_model = set_pop(models)
-		model_name = list_read(tagged_model, 0)
+		model_name = string_join(list_read(tagged_model, 0), "/")
 		model = list_read(tagged_model, 1)
 
 		// Add all elements from 'model', but prepend it with the 'model_name'
@@ -133,3 +122,93 @@ Element function model_retype_on_name(model : Element, new_MM : Element, operati
 	dict_add(model, "metamodel", new_MM)
 
 	return model!
+
+Void function model_join(dst_model : Element, src_model : Element, retyping_key : String):
+	Element queue
+	Element mapping
+	String name
+	String type
+	String src
+	String dst
+
+	queue = set_to_list(dict_keys(src_model["model"]))
+	mapping = create_node()
+
+	while (read_nr_out(queue) > 0):
+		name = list_pop(queue, 0)
+
+		type = read_type(src_model, name)
+		log("Instantiate element with old type: " + type)
+		log("New type: " + (retyping_key + type))
+
+		if (is_edge(src_model["model"][name])):
+			// Is an edge, so potentially queue it
+			String src
+			String dst
+
+			src = reverseKeyLookup(src_model["model"], read_edge_src(src_model["model"][name]))
+			dst = reverseKeyLookup(src_model["model"], read_edge_dst(src_model["model"][name]))
+
+			if (bool_and(dict_in(mapping, src), dict_in(mapping, dst))):
+				// All present, so create the link between them
+				dict_add(mapping, name, instantiate_link(dst_model, retyping_key + type, "", mapping[src], mapping[dst]))
+			else:
+				list_append(queue, name)
+
+		elif (has_value(src_model["model"][name])):
+			// Has a value, so copy that as well
+			dict_add(mapping, name, instantiate_value(dst_model, retyping_key + type, "", src_model["model"][name]))
+
+		else:
+			// Is a node
+			dict_add(mapping, name, instantiate_node(dst_model, retyping_key + type, ""))
+
+	return!
+	
+Element function model_split(src_model : Element, target_metamodel : Element, retyping_key : String):
+	Element dst_model
+
+	dst_model = instantiate_model(target_metamodel)
+
+	Element queue
+	Element mapping
+	String name
+	String type
+	String src
+	String dst
+	Integer length
+	String new_type
+
+	queue = set_to_list(dict_keys(src_model["model"]))
+	mapping = create_node()
+	length = string_len(retyping_key)
+
+	while (read_nr_out(queue) > 0):
+		name = list_pop(queue, 0)
+
+		type = read_type(src_model, name)
+		if (string_startswith(type, retyping_key)):
+			new_type = string_substr(type, length, string_len(type))
+			if (is_edge(src_model["model"][name])):
+				// Is an edge, so potentially queue it
+				String src
+				String dst
+
+				src = reverseKeyLookup(src_model["model"], read_edge_src(src_model["model"][name]))
+				dst = reverseKeyLookup(src_model["model"], read_edge_dst(src_model["model"][name]))
+
+				if (bool_and(dict_in(mapping, src), dict_in(mapping, dst))):
+					// All present, so create the link between them
+					dict_add(mapping, name, instantiate_link(dst_model, new_type, "", mapping[src], mapping[dst]))
+				else:
+					list_append(queue, name)
+
+			elif (has_value(src_model["model"][name])):
+				// Has a value, so copy that as well
+				dict_add(mapping, name, instantiate_value(dst_model, new_type, "", src_model["model"][name]))
+
+			else:
+				// Is a node
+				dict_add(mapping, name, instantiate_node(dst_model, new_type, ""))
+
+	return dst_model!

+ 80 - 3
bootstrap/modelling.alc

@@ -83,8 +83,10 @@ Void function retype_model(model : Element, metamodel : Element):
 Void function retype(model : Element, element : String, type : String):
 	// Retype a model, deleting any previous type the element had
 	// The type string is evaluated in the metamodel previously specified
+
 	if (dict_in_node(model["type_mapping"], model["model"][element])):
 		dict_delete_node(model["type_mapping"], model["model"][element])
+
 	dict_add(model["type_mapping"], model["model"][element], model["metamodel"]["model"][type])
 
 	return!
@@ -102,6 +104,11 @@ String function instantiate_node(model : Element, type_name : String, instance_n
 	// Basically create a node and type it immediately
 	String actual_name
 
+	if (bool_not(dict_in(model["metamodel"]["model"], type_name))):
+		log("ERROR: (instantiate_node) no such type in metamodel: " + type_name)
+		log("    for " + instance_name)
+		return ""!
+
 	actual_name = model_add_node(model, instance_name)
 	retype(model, actual_name, type_name)
 
@@ -112,6 +119,11 @@ String function instantiate_value(model : Element, type_name : String, instance_
 	// Basically create a node and type it immediately
 	String actual_name
 
+	if (bool_not(dict_in(model["metamodel"]["model"], type_name))):
+		log("ERROR: (instantiate_value) no such type in metamodel: " + type_name)
+		log("     for " + instance_name)
+		return ""!
+
 	actual_name = model_add_value(model, instance_name, value)
 	retype(model, actual_name, type_name)
 
@@ -121,7 +133,11 @@ String function find_attribute_type(model : Element, elem : String, name : Strin
 	String mm_elem
 	String direct_type
 
-	direct_type = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][elem]))
+	direct_type = read_type(model, elem)
+
+	if (direct_type == ""):
+		return ""!
+	
 	mm_elem = find_attribute_definer(model["metamodel"], direct_type, name)
 
 	if (value_eq(mm_elem, "")):
@@ -194,6 +210,7 @@ Void function instantiate_attribute(model : Element, element : String, attribute
 
 	if (attr_type == ""):
 		log("Could not find attribute " + cast_v2s(attribute_name))
+		log("For element " + element)
 		return!
 		
 	// Make a copy of the value, as it is likely that this value is reused later on
@@ -250,8 +267,6 @@ String function instantiate_link(model : Element, type : String, name : String,
 	// Create a typed link between two nodes
 	String actual_name
 
-	actual_name = model_add_edge(model, name, source, destination)
-
 	if (type == ""):
 		// Have to find the type ourselves, as it isn't defined
 		Element out
@@ -268,6 +283,13 @@ String function instantiate_link(model : Element, type : String, name : String,
 		else:
 			log("ERROR: too many possible links between entries")
 			return ""!
+
+	if (bool_not(dict_in(model["metamodel"]["model"], type))):
+		log("ERROR: (instantiate_link) no such type in metamodel: " + type)
+		log("    for " + name)
+		return ""!
+
+	actual_name = model_add_edge(model, name, source, destination)
 	
 	retype(model, actual_name, type)
 	return actual_name!
@@ -454,6 +476,9 @@ Void function add_constraint(model : Element, element : String, constraint : Act
 
 Void function construct_model():
 	String command
+
+	initialize_SCD("models/SimpleClassDiagrams")
+
 	while (True):
 		command = input()
 		if (command == "instantiate_bottom"):
@@ -508,3 +533,55 @@ Void function construct_model():
 				dict_add(global_models, input(), m)
 		else:
 			log("Modelling error: did not understand command " + command)
+
+Element function construct_model_raw(metamodel : Element):
+	String command
+	Element model
+
+	model = instantiate_model(metamodel)
+
+	while (True):
+		command = input()
+		if (command == "add_node"):
+			input()
+			model_add_node(model, input())
+		elif (command == "add_value"):
+			input()
+			model_add_value(model, input(), input())
+		elif (command == "add_edge"):
+			input()
+			model_add_edge(model, input(), input(), input())
+		elif (command == "exit"):
+			return model!
+		elif (command == "instantiate_node"):
+			input()
+			instantiate_node(model, input(), input())
+		elif (command == "instantiate_attribute"):
+			input()
+			instantiate_attribute(model, input(), input(), input())
+		elif (command == "instantiate_attribute_ref"):
+			input()
+			instantiate_attribute_ref(model, input(), input(), input())
+		elif (command == "instantiate_attribute_code"):
+			input()
+			instantiate_attribute_code(model, input(), input(), construct_function())
+		elif (command == "instantiate_link"):
+			input()
+			instantiate_link(model, input(), input(), input(), input())
+		elif (command == "add_constraint"):
+			input()
+			add_constraint(model, input(), construct_function())
+		elif (command == "import_node"):
+			log("Dropping import_node as not allowed")
+			input()
+			input()
+		elif (command == "export_node"):
+			log("Dropping export_node as not allowed")
+			input()
+			input()
+		elif (command == "instantiate_model"):
+			log("Dropping instantiate_model as not allowed")
+			input()
+			input()
+		else:
+			log("Modelling error: did not understand command " + command)

+ 21 - 0
bootstrap/object_operations.alc

@@ -237,3 +237,24 @@ Element function allowedAssociationsBetween(model : Element, src : String, dst :
 			i = i + 1
 
 	return result!
+
+String function read_type(model : Element, name : String):
+	String result
+
+	Element mm
+	Element tm
+
+	mm = model["metamodel"]["model"]
+	if (dict_in(model["model"], name)):
+		if (dict_in_node(model["type_mapping"], model["model"][name])):
+			tm = dict_read_node(model["type_mapping"], model["model"][name])
+			
+			result = reverseKeyLookup(mm, tm)
+			if (element_eq(mm[result], tm)):
+				return result!
+			else:
+				return ""!
+		else:
+			return ""!
+	else:
+		return ""!

+ 17 - 0
bootstrap/primitives.alc

@@ -81,6 +81,7 @@ Boolean function is_physical_string(a: Element) = ?primitives/is_physical_string
 Boolean function is_physical_boolean(a: Element) = ?primitives/is_physical_boolean
 Boolean function is_physical_action(a: Element) = ?primitives/is_physical_action
 Float function time() = ?primitives/time
+String function hash(a : String) = ?primitives/hash
 
 Element function exec(first_instr : Element):
 	// This does very ugly things, so beware!
@@ -275,6 +276,22 @@ Element function set_overlap(sa : Element, sb : Element):
 
 	return result!
 
+Boolean function set_equality(sa : Element, sb : Element):
+	if (read_nr_out(sa) != read_nr_out(sb)):
+		return False!
+
+	Integer i
+	i = 0
+	while (i < read_nr_out(sa)):
+		if (set_in(sb, read_edge_dst(read_out(sa, i)))):
+			// Shared between both, so all is fine
+			i = i + 1
+		else:
+			// Not shared
+			return False!
+	
+	return True!
+
 Element function dict_copy(d : Element):
 	String result
 	Element keys

+ 1 - 0
bootstrap/ramify.alc

@@ -137,6 +137,7 @@ Element function ramify(model : Element):
 
 		type_name = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], entry))
 		if (type_name == "Class"):
+			log("Added Pre_" + key)
 			instantiate_node(new_model, type_name, "Pre_" + key)
 			instantiate_node(new_model, type_name, "Post_" + key)
 

+ 4 - 2
bootstrap/transform.alc

@@ -360,10 +360,8 @@ Element function transform(host_model : Element, schedule_model : Element):
 
 	if (transform_composite(host_model, schedule_model, current)):
 		// Success, so return True if it is in-place, or the new model if it is out-place
-		log("Transform success!")
 		return True!
 	else:
-		log("Transform failed!")
 		return False!
 
 Boolean function transform_composite(host_model : Element, schedule_model : Element, composite : String):
@@ -400,6 +398,8 @@ Boolean function transform_atomic(host_model : Element, schedule_model : Element
 	Element mappings
 	Element mapping
 	mappings = full_match(host_model, schedule_model, current)
+	log("Execute atomic " + current)
+	log("Mappings: " + cast_v2s(read_nr_out(mappings)))
 
 	if (read_nr_out(mappings) > 0):
 		// Pick one!
@@ -419,6 +419,8 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 	Boolean result
 
 	mappings = full_match(host_model, schedule_model, current)
+	log("Execute forall " + current)
+	log("Mappings: " + cast_v2s(read_nr_out(mappings)))
 
 	if (read_nr_out(mappings) > 0):
 		result = True

Разница между файлами не показана из-за своего большого размера
+ 1178 - 9
core/core_algorithm.alc


+ 43 - 2
core/core_formalism.mvc

@@ -1,4 +1,5 @@
 import models/SimpleClassDiagrams as SimpleClassDiagrams
+include "primitives.alh"
 
 SimpleClassDiagrams CoreFormalism {
     Class String {
@@ -21,15 +22,27 @@ SimpleClassDiagrams CoreFormalism {
 
     Class Boolean {
         $
-            if (bool_not(is_physical_bool(self))):
+            if (bool_not(is_physical_boolean(self))):
                 return "Boolean has no bool value"!
             else:
                 return "OK"!
         $
     }
 
+    Class Natural {
+        $
+            if (bool_not(is_physical_int(self))):
+                return "Natural has no integer value"!
+            elif (integer_lt(self, 0)):
+                return "Natural has negative value"!
+            else:
+                return "OK"!
+        $
+    }
+
     Class User {
         name : String
+        password : String
         admin : Boolean
     }
 
@@ -38,6 +51,7 @@ SimpleClassDiagrams CoreFormalism {
     }
 
     Association ownedBy (Group, User) {}
+    Association belongsTo (User, Group) {}
 
     Class Model {
         name : String
@@ -45,7 +59,19 @@ SimpleClassDiagrams CoreFormalism {
         permissions : Permissions
     }
 
-    Class Transformation {
+    Association instanceOf (Model, Model) {}
+
+    Association owner (Model, User) {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+
+    Association group (Model, Group) {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+
+    Class Transformation : Model {
         name : String
         location : String
     }
@@ -53,6 +79,21 @@ SimpleClassDiagrams CoreFormalism {
     Class ModelTransformation : Transformation {}
 
     Class ActionLanguage : Transformation {}
+
+    Class ExternalTool : Transformation {}
+
+    Class ManualTransformation : Transformation {}
+
+    Association transformInput (Model, Transformation) {
+        name : String
+    }
+    Association transformOutput (Transformation, Model) {
+        name : String
+    }
+
+    Association tracability (Model, Model) {
+        type : String
+    }
 }
 
 export CoreFormalism to models/CoreFormalism

+ 295 - 0
core/mini_modify.alc

@@ -0,0 +1,295 @@
+include "primitives.alh"
+include "constructors.alh"
+include "object_operations.alh"
+include "library.alh"
+include "conformance_scd.alh"
+include "io.alh"
+include "metamodels.alh"
+include "modelling.alh"
+include "compilation_manager.alh"
+
+Element function modify(model : Element, write : Boolean):
+	String cmd
+
+	Element attr_list_pn
+	Element attr_keys_pn
+	String attr_key_pn
+	Element metamodel_element_pn
+	String typename
+
+	output("Model loaded, ready for commands!")
+	output("Use 'help' command for a list of possible commands")
+
+	while (True):
+		output("Please give your command.")
+		cmd = input()
+		if (cmd == "help"):
+			output("Allowed operations:")
+			if (write):
+				output(" == READ/WRITE ==")
+				output("  instantiate -- Create a new model element")
+				output("  delete      -- Delete an existing element")
+				output("  attr_add    -- Add an attribute to an element")
+				output("  attr_del    -- Delete an attribute of an element")
+				output("  attr_modify -- Modify an attribute of an element")
+				output("  constrain   -- Add a constraint function to the model")
+				output("  rename      -- Rename an existing element")
+				output("  modify      -- Modify the attributes of an element")
+				output("  retype      -- Change the type of an element")
+			else:
+				output(" == READ-ONLY ==")
+			output("  list        -- Prints the list of elements in the model")
+			output("  list_full   -- Prints the list of all elements in the model")
+			output("  types       -- Prints the list of elements that can be instantiated")
+			output("  read        -- Prints the current state of a model element")
+			output("  verify      -- Check whether the model conforms to the metamodel")
+			output("  exit        -- Leave the modification interface")
+		elif (cmd == "exit"):
+			return model!
+		elif (cmd == "instantiate"):
+			if (write):
+				String mm_type_name
+				output("Type to instantiate?")
+				mm_type_name = input()
+				if (dict_in(model["metamodel"]["model"], mm_type_name)):
+					String element_name
+					output("Name of new element?")
+					element_name = input()
+					if (dict_in(model["model"], element_name)):
+						output("Element already exists; aborting")
+					else:
+						if (is_edge(model["metamodel"]["model"][mm_type_name])):
+							output("Source name?")
+							String src_name
+							src_name = input()
+							if (dict_in(model["model"], src_name)):
+								output("Destination name?")
+								String dst_name
+								dst_name = input()
+								if (dict_in(model["model"], dst_name)):
+									instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
+									output("Instantiation successful!")
+								else:
+									output("Unknown destination; aborting")
+							else:
+								output("Unknown source; aborting")
+						else:
+							instantiate_node(model, mm_type_name, element_name)
+							output("Instantiation successful!")
+				else:
+					output("Unknown type specified; aborting")
+			else:
+				output("Permission denied")
+
+		elif (cmd == "constrain"):
+			if (write):
+				output("Element to constrain (empty for global)?")
+				String model_name
+				model_name = input()
+
+				if (model_name == ""):
+					// Global constraint
+					output("Give input to function constructors for GLOBAL constraint!")
+					set_model_constraints(model, construct_function())
+				elif (dict_in(model["model"], model_name)):
+					// Local constraint for this model
+					output("Give input to function constructors for LOCAL constraint!")
+					add_constraint(model, model_name, construct_function())
+					output("Added constraint to model!")
+				else:
+					// Local constraint, but model not found
+					output("Unknown model; aborting")
+			else:
+				output("Permission denied")
+
+		elif (cmd == "attr_modify"):
+			if (write):
+				String model_name
+				output("Element to modify?")
+				model_name = input()
+				if (dict_in(model["model"], model_name)):
+					Element attrs
+					attrs = getAttributeList(model, model_name)
+					String attr_name
+					output("Attribute to modify?")
+					attr_name = input()
+					if (set_in(dict_keys(attrs), attr_name)):
+						output("New value?")
+						unset_attribute(model, model_name, attr_name)
+						instantiate_attribute(model, model_name, attr_name, input())
+						output("Modified!")
+					else:
+						output("No such attribute!")
+				else:
+					output("No such model!")
+			else:
+				output("Permission denied")
+
+		elif (cmd == "attr_add"):
+			if (write):
+				String model_name
+				output("Which model do you want to assign an attribute to?")
+				model_name = input()
+				if (dict_in(model["model"], model_name)):
+					Element attrs
+					attrs = getAttributeList(model, model_name)
+					String attr_name
+					output("Which attribute do you wish to assign?")
+					attr_name = input()
+					if (set_in(dict_keys(attrs), attr_name)):
+						output("Value of attribute?")
+						instantiate_attribute(model, model_name, attr_name, input())
+						output("Added attribute!")
+					else:
+						output("No such attribute!")
+				else:
+					output("No such model!")
+			else:
+				output("Permission denied")
+
+		elif (cmd == "attr_del"):
+			if (write):
+				String model_name
+				output("Which model do you want to remove an attribute of?")
+				model_name = input()
+				if (dict_in(model["model"], model_name)):
+					Element attrs
+					attrs = getAttributeList(model, model_name)
+					String attr_name
+					output("Which attribute do you want to delete?")
+					attr_name = input()
+					if (set_in(dict_keys(attrs), attr_name)):
+						unset_attribute(model, model_name, attr_name)
+						output("Attribute deleted!")
+					else:
+						output("No such attribute!")
+				else:
+					output("No such model!")
+			else:
+				output("Permission denied")
+
+		elif (cmd == "delete"):
+			if (write):
+				output("What is the name of the element you want to delete?")
+				cmd = input()
+				if (dict_in(model["model"], cmd)):
+					model_delete_element(model, cmd)
+					output("Deleted!")
+				else:
+					output("No such element; aborting")
+			else:
+				output("Permission denied")
+
+		elif (cmd == "rename"):
+			if (write):
+				output("Old name?")
+				String old_name_e
+				old_name_e = input()
+				if (dict_in(model["model"], old_name_e)):
+					output("New name?")
+					String new_name_e
+					new_name_e = input()
+					if (dict_in(model["model"], new_name_e)):
+						output("New name already used; aborting")
+					else:
+						dict_add(model["model"], new_name_e, model["model"][old_name_e])
+						dict_delete(model["model"], old_name_e)
+						output("Rename complete!")
+				else:
+					output("Unknown element; aborting")
+			else:
+				output("Permission denied")
+
+		elif (cmd == "list"):
+			Element keys_m
+			keys_m = dict_keys(model["model"])
+			output("List of all elements:")
+			String v_m
+			while (read_nr_out(keys_m) > 0):
+				v_m = set_pop(keys_m)
+				// Filter out anonymous objects
+				if (bool_not(string_startswith(v_m, "__"))):
+					typename = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][v_m]))
+					output((("  " + v_m) + " : ") + typename)
+
+		elif (cmd == "list_full"):
+			Element keys_m
+			keys_m = dict_keys(model["model"])
+			output("List of all elements:")
+			String v_m
+			while (read_nr_out(keys_m) > 0):
+				v_m = set_pop(keys_m)
+				// Filter out anonymous objects
+				typename = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][v_m]))
+				output((("  " + v_m) + " : ") + typename)
+
+		elif (cmd == "read"):
+			output("Element to read?")
+			cmd = input()
+			if (dict_in(model["model"], cmd)):
+				Element read_elem
+				read_elem = model["model"][cmd]
+				metamodel_element_pn = dict_read_node(model["type_mapping"], read_elem)
+
+				output("Name: " + cmd)
+				output("Type: " + reverseKeyLookup(model["metamodel"]["model"], metamodel_element_pn))
+				if (is_edge(read_elem)):
+					output("Source: " + reverseKeyLookup(model["model"], read_edge_src(read_elem)))
+					output("Destination: " + reverseKeyLookup(model["model"], read_edge_dst(read_elem)))
+				if (cast_v2s(read_elem) != "None"):
+					output("Value: " + cast_v2s(read_elem))
+				output("Defines attributes:")
+				attr_list_pn = getInstantiatableAttributes(model, read_elem)
+				attr_keys_pn = dict_keys(attr_list_pn)
+				while (0 < read_nr_out(attr_keys_pn)):
+					attr_key_pn = set_pop(attr_keys_pn)
+					output(((("  " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])))
+				output("Attributes:")
+				attr_list_pn = getAttributeList(model, cmd)
+				attr_keys_pn = dict_keys(attr_list_pn)
+				while (0 < read_nr_out(attr_keys_pn)):
+					attr_key_pn = set_pop(attr_keys_pn)
+					output((((("  " + cast_v2s(attr_key_pn)) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(read_attribute(model, reverseKeyLookup(model["model"], read_elem), attr_key_pn)))
+			else:
+				output("Unknown element; aborting")
+
+		elif (cmd == "verify"):
+			output(conformance_scd(model))
+
+		elif (cmd == "types"):
+			Element keys_t
+			keys_t = dict_keys(model["metamodel"]["model"])
+			output("List of types:")
+			String v_t
+			while (read_nr_out(keys_t) > 0):
+				v_t = set_pop(keys_t)
+				if (bool_not(string_startswith(v_t, "__"))):
+					output(string_join(("  " + v_t) + " : ", reverseKeyLookup(model["metamodel"]["metamodel"]["model"], dict_read_node(model["metamodel"]["type_mapping"], model["metamodel"]["model"][v_t]))))
+
+		elif (cmd == "retype"):
+			if (write):
+				output("Element to retype?")
+				String elementname
+				elementname = input()
+				if (dict_in(model["model"], elementname)):
+					output("New type")
+					typename = input()
+					if (dict_in(model["metamodel"]["model"], typename)):
+						// OK, do the retyping
+						// First try removing the previous type if it exists
+						dict_delete_node(model["type_mapping"], model["model"][elementname])
+						// Now add the new type
+						dict_add(model["type_mapping"], model["model"][elementname], model["metamodel"]["model"][typename])
+						output("Retyped!")
+					else:
+						output("Unknown type; aborting")
+				else:
+					output("Unknown element; aborting")
+			else:
+				output("Permission denied")
+
+		else:
+			output("Unknown command: " + cast_v2s(cmd))
+			output("Use command 'help' to get a list of available commands")
+
+	return model!

+ 1 - 0
core/mini_modify.alh

@@ -0,0 +1 @@
+Element function modify(model : Element, write : Boolean)

+ 0 - 254
integration/code/mini_modify.alc

@@ -1,254 +0,0 @@
-include "primitives.alh"
-include "constructors.alh"
-include "object_operations.alh"
-include "library.alh"
-include "conformance_scd.alh"
-include "io.alh"
-include "metamodels.alh"
-include "modelling.alh"
-include "compilation_manager.alh"
-
-Element function modify(model : Element):
-	String cmd
-
-	Element attr_list_pn
-	Element attr_keys_pn
-	String attr_key_pn
-	Element metamodel_element_pn
-	String typename
-
-	output("Model loaded, ready for commands!")
-	output("Use 'help' command for a list of possible commands")
-
-	while (True):
-		output("Please give your command.")
-		cmd = input()
-		if (cmd == "help"):
-			output("Generic model operations:")
-			output("  instantiate -- Create a new model element")
-			output("  delete      -- Delete an existing element")
-			output("  attr_add    -- Add an attribute to an element")
-			output("  attr_del    -- Delete an attribute of an element")
-			output("  constrain   -- Add a constraint function to the model")
-			output("  rename      -- Rename an existing element")
-			output("  modify      -- Modify the attributes of an element")
-			output("  list        -- Prints the list of elements in the model")
-			output("  types       -- Prints the list of elements that can be instantiated")
-			output("  read        -- Prints the current state of a model element")
-			output("  verify      -- Check whether the model conforms to the metamodel")
-			output("  retype      -- Change the type of an element")
-			output("  exit        -- Leave the modification interface")
-		elif (cmd == "exit"):
-			return model!
-		elif (cmd == "instantiate"):
-			String mm_type_name
-			output("Type to instantiate?")
-			mm_type_name = input()
-			if (dict_in(model["metamodel"]["model"], mm_type_name)):
-				String element_name
-				output("Name of new element?")
-				element_name = input()
-				if (dict_in(model["model"], element_name)):
-					output("Element already exists; aborting")
-				else:
-					if (is_edge(model["metamodel"]["model"][mm_type_name])):
-						output("Source name?")
-						String src_name
-						src_name = input()
-						if (dict_in(model["model"], src_name)):
-							output("Destination name?")
-							String dst_name
-							dst_name = input()
-							if (dict_in(model["model"], dst_name)):
-								instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
-								output("Instantiation successful!")
-							else:
-								output("Unknown destination; aborting")
-						else:
-							output("Unknown source; aborting")
-					else:
-						instantiate_node(model, mm_type_name, element_name)
-						output("Instantiation successful!")
-			else:
-				output("Unknown type specified; aborting")
-		elif (cmd == "set_inheritance"):
-			String inh_name
-
-			output("Which link in the metamodel is the inheritance link?")
-			inh_name = input()
-
-			if (dict_in(model["metamodel"]["model"], inh_name)):
-				dict_add(model, "inheritance", model["metamodel"]["model"][inh_name])
-				output("Set inheritance link!")
-			else:
-				output("Element not found in metamodel; aborting")
-
-		elif (cmd == "constrain"):
-			output("Element to constrain (empty for global)?")
-			String model_name
-			model_name = input()
-
-			if (model_name == ""):
-				// Global constraint
-				output("Give input to function constructors for GLOBAL constraint!")
-				set_model_constraints(model, construct_function())
-			elif (dict_in(model["model"], model_name)):
-				// Local constraint for this model
-				output("Give input to function constructors for LOCAL constraint!")
-				add_constraint(model, model_name, construct_function())
-				output("Added constraint to model!")
-			else:
-				// Local constraint, but model not found
-				output("Unknown model; aborting")
-		elif (cmd == "modify"):
-			String model_name
-			output("Element to modify?")
-			model_name = input()
-			if (dict_in(model["model"], model_name)):
-				Element attrs
-				attrs = getAttributeList(model, model_name)
-				String attr_name
-				output("Attribute to modify?")
-				attr_name = input()
-				if (set_in(dict_keys(attrs), attr_name)):
-					output("New value?")
-					unset_attribute(model, model_name, attr_name)
-					instantiate_attribute(model, model_name, attr_name, input())
-					output("Modified!")
-				else:
-					output("No such attribute!")
-			else:
-				output("No such model!")
-		elif (cmd == "attr_add"):
-			String model_name
-			output("Which model do you want to assign an attribute to?")
-			model_name = input()
-			if (dict_in(model["model"], model_name)):
-				Element attrs
-				attrs = getAttributeList(model, model_name)
-				String attr_name
-				output("Which attribute do you wish to assign?")
-				attr_name = input()
-				if (set_in(dict_keys(attrs), attr_name)):
-					output("Value of attribute?")
-					instantiate_attribute(model, model_name, attr_name, input())
-					output("Added attribute!")
-				else:
-					output("No such attribute!")
-			else:
-				output("No such model!")
-		elif (cmd == "attr_del"):
-			String model_name
-			output("Which model do you want to remove an attribute of?")
-			model_name = input()
-			if (dict_in(model["model"], model_name)):
-				Element attrs
-				attrs = getAttributeList(model, model_name)
-				String attr_name
-				output("Which attribute do you want to delete?")
-				attr_name = input()
-				if (set_in(dict_keys(attrs), attr_name)):
-					unset_attribute(model, model_name, attr_name)
-					output("Attribute deleted!")
-				else:
-					output("No such attribute!")
-			else:
-				output("No such model!")
-		elif (cmd == "delete"):
-			output("What is the name of the element you want to delete?")
-			cmd = input()
-			if (dict_in(model["model"], cmd)):
-				model_delete_element(model, cmd)
-				output("Deleted!")
-			else:
-				output("No such element; aborting")
-		elif (cmd == "rename"):
-			output("Old name?")
-			String old_name_e
-			old_name_e = input()
-			if (dict_in(model["model"], old_name_e)):
-				output("New name?")
-				String new_name_e
-				new_name_e = input()
-				if (dict_in(model["model"], new_name_e)):
-					output("New name already used; aborting")
-				else:
-					dict_add(model["model"], new_name_e, model["model"][old_name_e])
-					dict_delete(model["model"], old_name_e)
-					output("Rename complete!")
-			else:
-				output("Unknown element; aborting")
-		elif (cmd == "list"):
-			Element keys_m
-			keys_m = dict_keys(model["model"])
-			output("List of all elements:")
-			String v_m
-			while (read_nr_out(keys_m) > 0):
-				v_m = set_pop(keys_m)
-				// Filter out anonymous objects
-				if (bool_not(string_startswith(v_m, "__"))):
-					typename = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][v_m]))
-					output((("  " + v_m) + " : ") + typename)
-		elif (cmd == "read"):
-			output("Element to read?")
-			cmd = input()
-			if (dict_in(model["model"], cmd)):
-				Element read_elem
-				read_elem = model["model"][cmd]
-				metamodel_element_pn = dict_read_node(model["type_mapping"], read_elem)
-
-				output("Name: " + cmd)
-				output("Type: " + reverseKeyLookup(model["metamodel"]["model"], metamodel_element_pn))
-				if (is_edge(read_elem)):
-					output("Source: " + reverseKeyLookup(model["model"], read_edge_src(read_elem)))
-					output("Destination: " + reverseKeyLookup(model["model"], read_edge_dst(read_elem)))
-				if (cast_v2s(read_elem) != "None"):
-					output("Value: " + cast_v2s(read_elem))
-				output("Defines attributes:")
-				attr_list_pn = getInstantiatableAttributes(model, read_elem)
-				attr_keys_pn = dict_keys(attr_list_pn)
-				while (0 < read_nr_out(attr_keys_pn)):
-					attr_key_pn = set_pop(attr_keys_pn)
-					output(((("  " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])))
-				output("Attributes:")
-				attr_list_pn = getAttributeList(model, cmd)
-				attr_keys_pn = dict_keys(attr_list_pn)
-				while (0 < read_nr_out(attr_keys_pn)):
-					attr_key_pn = set_pop(attr_keys_pn)
-					output((((("  " + cast_v2s(attr_key_pn)) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(read_attribute(model, reverseKeyLookup(model["model"], read_elem), attr_key_pn)))
-			else:
-				output("Unknown element; aborting")
-		elif (cmd == "verify"):
-			output(conformance_scd(model))
-		elif (cmd == "types"):
-			Element keys_t
-			keys_t = dict_keys(model["metamodel"]["model"])
-			output("List of types:")
-			String v_t
-			while (read_nr_out(keys_t) > 0):
-				v_t = set_pop(keys_t)
-				if (bool_not(string_startswith(v_t, "__"))):
-					output(string_join(("  " + v_t) + " : ", reverseKeyLookup(model["metamodel"]["metamodel"]["model"], dict_read_node(model["metamodel"]["type_mapping"], model["metamodel"]["model"][v_t]))))
-		elif (cmd == "retype"):
-			output("Element to retype?")
-			String elementname
-			elementname = input()
-			if (dict_in(model["model"], elementname)):
-				output("New type")
-				typename = input()
-				if (dict_in(model["metamodel"]["model"], typename)):
-					// OK, do the retyping
-					// First try removing the previous type if it exists
-					dict_delete_node(model["type_mapping"], model["model"][elementname])
-					// Now add the new type
-					dict_add(model["type_mapping"], model["model"][elementname], model["metamodel"]["model"][typename])
-					output("Retyped!")
-				else:
-					output("Unknown type; aborting")
-			else:
-				output("Unknown element; aborting")
-		else:
-			output("Unknown command: " + cast_v2s(cmd))
-			output("Use command 'help' to get a list of available commands")
-
-	return model!

+ 0 - 1
integration/code/mini_modify.alh

@@ -1 +0,0 @@
-Element function modify(model : Element)

+ 2 - 2
integration/code/petrinets.mvc

@@ -1,6 +1,6 @@
-import models/SimpleClassDiagrams as SCD
+import models/SimpleClassDiagrams as SimpleClassDiagrams
 
-SCD PetriNets{
+SimpleClassDiagrams PetriNets{
     Class Natural {}
     Class Place{
         tokens : Natural

+ 2 - 0
integration/code/pn_design.mvc

@@ -2,9 +2,11 @@ import models/SimpleClassDiagrams as SimpleClassDiagrams
 
 SimpleClassDiagrams PetriNets_Design{
     Class Natural {}
+    Class String {}
 
     Class Place {
         tokens : Natural
+        name : String
     }
     Class Transition {}
     Association P2T (Place, Transition) {

+ 3 - 0
integration/code/pn_design_model.mvc

@@ -3,12 +3,15 @@ import models/PetriNets_Design as PetriNets
 PetriNets pn {
     Place p1 {
         tokens = 1
+        name = "p1"
     }
     Place p2 {
         tokens = 2
+        name = "p2"
     }
     Place p3 {
         tokens = 3
+        name = "p3"
     }
     Transition t1 {}
     P2T (p1, t1) {

+ 39 - 39
integration/code/pn_design_to_runtime.mvc

@@ -6,15 +6,15 @@ RAM_PN_DR annotate {
         {Contains} Success success {}
         {Contains} ForAll copy_transitions {
             LHS {
-                Pre_SOURCE_Transition {
+                Pre_PetriNets/Transition {
                     label = "0"
                 }
             }
             RHS {
-                Post_SOURCE_Transition ct1 {
+                Post_PetriNets/Transition ct1 {
                     label = "0"
                 }
-                Post_TARGET_Transition ct2 {
+                Post_PetriNets_Runtime/Transition ct2 {
                     label = "1"
                     action = $
                         include "primitives.alh"
@@ -24,84 +24,84 @@ RAM_PN_DR annotate {
                             return!
                         $
                 }
-                Post_TransitionLink (ct1, ct2){
+                Post_D2R_TransitionLink (ct1, ct2){
                     label = "2"
                 }
             }
         }
         {Contains} ForAll copy_places {
             LHS {
-                Pre_SOURCE_Place {
+                Pre_PetriNets/Place {
                     label = "0"
                 }
             }
             RHS {
-                Post_SOURCE_Place cp1 {
+                Post_PetriNets/Place cp1 {
                     label = "0"
                 }
-                Post_TARGET_Place cp2 {
+                Post_PetriNets_Runtime/Place cp2 {
                     label = "1"
                     action = $
                         include "primitives.alh"
                         include "modelling.alh"
                         Void function action(host_model : Element, name : String, mapping : Element):
                             instantiate_attribute(host_model, name, "tokens", read_attribute(host_model, mapping["0"], "tokens"))
-                            instantiate_attribute(host_model, name, "name", mapping["0"])
+                            instantiate_attribute(host_model, name, "name", read_attribute(host_model, mapping["0"], "name"))
                             return!
                         $
                 }
-                Post_PlaceLink (cp1, cp2){
+                Post_D2R_PlaceLink (cp1, cp2){
                     label = "2"
                 }
             }
         }
         {Contains} ForAll copy_P2T {
             LHS {
-                Pre_SOURCE_Place cp2t_p{
+                Pre_PetriNets/Place cp2t_p{
                     label = "0"
                 }
-                Pre_SOURCE_Transition cp2t_t{
+                Pre_PetriNets/Transition cp2t_t{
                     label = "1"
                 }
-                Pre_SOURCE_P2T (cp2t_p, cp2t_t){
+                Pre_PetriNets/P2T (cp2t_p, cp2t_t){
                     label = "2"
                 }
-                Pre_TARGET_Place cp2t_p2{
+                Pre_PetriNets_Runtime/Place cp2t_p2{
                     label = "3"
                 }
-                Pre_TARGET_Transition cp2t_t2{
+                Pre_PetriNets_Runtime/Transition cp2t_t2{
                     label = "4"
                 }
-                Pre_PlaceLink (cp2t_p, cp2t_p2){
+                Pre_D2R_PlaceLink (cp2t_p, cp2t_p2){
                     label = "5"
                 }
-                Pre_TransitionLink (cp2t_t, cp2t_t2){
+                Pre_D2R_TransitionLink (cp2t_t, cp2t_t2){
                     label = "6"
                 }
             }
             RHS {
-                Post_SOURCE_Place rhs_cp2t_p{
+                Post_PetriNets/Place rhs_cp2t_p{
                     label = "0"
                 }
-                Post_SOURCE_Transition rhs_cp2t_t{
+                Post_PetriNets/Transition rhs_cp2t_t{
                     label = "1"
                 }
-                Post_SOURCE_P2T rhs_cp2t_p2t (rhs_cp2t_p, rhs_cp2t_t){
+                Post_PetriNets/P2T rhs_cp2t_p2t (rhs_cp2t_p, rhs_cp2t_t){
                     label = "2"
                 }
-                Post_TARGET_Place rhs_cp2t_p2 {
+                Post_PetriNets_Runtime/Place rhs_cp2t_p2 {
                     label = "3"
                 }
-                Post_TARGET_Transition rhs_cp2t_t2 {
+                Post_PetriNets_Runtime/Transition rhs_cp2t_t2 {
                     label = "4"
                 }
-                Post_PlaceLink (rhs_cp2t_p, rhs_cp2t_p2){
+                Post_D2R_PlaceLink (rhs_cp2t_p, rhs_cp2t_p2){
                     label = "5"
                 }
-                Post_TransitionLink (rhs_cp2t_t, rhs_cp2t_t2){
+                Post_D2R_TransitionLink (rhs_cp2t_t, rhs_cp2t_t2){
                     label = "6"
                 }
-                Post_TARGET_P2T rhs_cp2t_p2t2(rhs_cp2t_p2, rhs_cp2t_t2) {
+                Post_PetriNets_Runtime/P2T rhs_cp2t_p2t2(rhs_cp2t_p2, rhs_cp2t_t2) {
                     label = "7"
                     action = $
                         include "primitives.alh"
@@ -115,51 +115,51 @@ RAM_PN_DR annotate {
         }
         {Contains} ForAll copy_T2P {
             LHS {
-                Pre_SOURCE_Place ct2p_p{
+                Pre_PetriNets/Place ct2p_p{
                     label = "0"
                 }
-                Pre_SOURCE_Transition ct2p_t{
+                Pre_PetriNets/Transition ct2p_t{
                     label = "1"
                 }
-                Pre_SOURCE_T2P (ct2p_t, ct2p_p){
+                Pre_PetriNets/T2P (ct2p_t, ct2p_p){
                     label = "2"
                 }
-                Pre_TARGET_Place ct2p_p2{
+                Pre_PetriNets_Runtime/Place ct2p_p2{
                     label = "3"
                 }
-                Pre_TARGET_Transition ct2p_t2{
+                Pre_PetriNets_Runtime/Transition ct2p_t2{
                     label = "4"
                 }
-                Pre_PlaceLink (ct2p_p, ct2p_p2){
+                Pre_D2R_PlaceLink (ct2p_p, ct2p_p2){
                     label = "5"
                 }
-                Pre_TransitionLink (ct2p_t, ct2p_t2){
+                Pre_D2R_TransitionLink (ct2p_t, ct2p_t2){
                     label = "6"
                 }
             }
             RHS {
-                Post_SOURCE_Place rhs_ct2p_p{
+                Post_PetriNets/Place rhs_ct2p_p{
                     label = "0"
                 }
-                Post_SOURCE_Transition rhs_ct2p_t{
+                Post_PetriNets/Transition rhs_ct2p_t{
                     label = "1"
                 }
-                Post_SOURCE_T2P (rhs_ct2p_t, rhs_ct2p_p){
+                Post_PetriNets/T2P (rhs_ct2p_t, rhs_ct2p_p){
                     label = "2"
                 }
-                Post_TARGET_Place rhs_ct2p_p2 {
+                Post_PetriNets_Runtime/Place rhs_ct2p_p2 {
                     label = "3"
                 }
-                Post_TARGET_Transition rhs_ct2p_t2 {
+                Post_PetriNets_Runtime/Transition rhs_ct2p_t2 {
                     label = "4"
                 }
-                Post_PlaceLink (rhs_ct2p_p, rhs_ct2p_p2){
+                Post_D2R_PlaceLink (rhs_ct2p_p, rhs_ct2p_p2){
                     label = "5"
                 }
-                Post_TransitionLink (rhs_ct2p_t, rhs_ct2p_t2){
+                Post_D2R_TransitionLink (rhs_ct2p_t, rhs_ct2p_t2){
                     label = "6"
                 }
-                Post_TARGET_T2P (rhs_ct2p_t2, rhs_ct2p_p2) {
+                Post_PetriNets_Runtime/T2P (rhs_ct2p_t2, rhs_ct2p_p2) {
                     label = "7"
                     action = $
                         include "primitives.alh"

+ 0 - 494
integration/code/pn_interface.alc

@@ -1,494 +0,0 @@
-include "primitives.alh"
-include "constructors.alh"
-include "object_operations.alh"
-include "library.alh"
-include "conformance_scd.alh"
-include "io.alh"
-include "metamodels.alh"
-include "modelling.alh"
-include "compilation_manager.alh"
-include "ramify.alh"
-include "transform.alh"
-include "model_management.alh"
-include "ftg.alh"
-
-Element function model_loaded(model : Element):
-	String cmd
-
-	Element attr_list_pn
-	Element attr_keys_pn
-	String attr_key_pn
-	Element metamodel_element_pn
-	String typename
-	Boolean bottom
-	Element other_metamodel
-
-	bottom = False
-	other_metamodel = create_node()
-	dict_add(other_metamodel, "model", model["model"])
-	dict_add(other_metamodel, "type_mapping", create_node())
-	dict_add(other_metamodel, "metamodel", import_node("models/LTM_bottom"))
-	dict_add(other_metamodel, "inheritance", other_metamodel["metamodel"]["model"]["__Inheritance"])
-
-	output("Model loaded, ready for commands!")
-	output("Use 'help' command for a list of possible commands")
-
-	while (True):
-		output("Please give your command.")
-		cmd = input()
-		if (cmd == "help"):
-			output("Generic model operations:")
-			output("  instantiate -- Create a new model element")
-			output("  delete      -- Delete an existing element")
-			output("  attr_add    -- Add an attribute to an element")
-			output("  attr_add_code -- Add a code attribute to an element")
-			output("  attr_del    -- Delete an attribute of an element")
-			output("  attr_def    -- Define a new attribute")
-			output("  constrain   -- Add a constraint function to the model")
-			output("  rename      -- Rename an existing element")
-			output("  modify      -- Modify the attributes of an element")
-			output("  list        -- Prints the list of elements in the model")
-			output("  types       -- Prints the list of elements that can be instantiated")
-			output("  read        -- Prints the current state of a model element")
-			output("  verify      -- Check whether the model conforms to the metamodel")
-			output("  retype      -- Change the type of an element")
-			output("  switch      -- Switch between conformance bottom and the linguistic metamodel")
-			output("  exit        -- Unload the model and go back to the loading prompt")
-		elif (cmd == "exit"):
-			return model!
-		elif (cmd == "attr_def"):
-			String name
-			String attr
-			String type
-			output("Which element do you want to define an attribute for?")
-			name = input()
-			output("What is the name of the attribute?")
-			attr = input()
-			output("Type of attribute?")
-			type = input()
-			model_define_attribute(model, name, attr, type)
-		elif (cmd == "instantiate"):
-			String mm_type_name
-			output("Type to instantiate?")
-			mm_type_name = input()
-			if (dict_in(model["metamodel"]["model"], mm_type_name)):
-				String element_name
-				output("Name of new element?")
-				element_name = input()
-				if (dict_in(model["model"], element_name)):
-					output("Element already exists; aborting")
-				else:
-					if (is_edge(model["metamodel"]["model"][mm_type_name])):
-						output("Source name?")
-						String src_name
-						src_name = input()
-						if (dict_in(model["model"], src_name)):
-							output("Destination name?")
-							String dst_name
-							dst_name = input()
-							if (dict_in(model["model"], dst_name)):
-								instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
-								output("Instantiation successful!")
-							else:
-								output("Unknown destination; aborting")
-						else:
-							output("Unknown source; aborting")
-					else:
-						instantiate_node(model, mm_type_name, element_name)
-						output("Instantiation successful!")
-			else:
-				output("Unknown type specified; aborting")
-		elif (cmd == "set_inheritance"):
-			String inh_name
-
-			output("Which link in the metamodel is the inheritance link?")
-			inh_name = input()
-
-			if (dict_in(model["metamodel"]["model"], inh_name)):
-				dict_add(model, "inheritance", model["metamodel"]["model"][inh_name])
-				output("Set inheritance link!")
-			else:
-				output("Element not found in metamodel; aborting")
-
-		elif (cmd == "constrain"):
-			output("Give input to function constructors for GLOBAL constraint!")
-			set_model_constraints(model, construct_function())
-		elif (cmd == "modify"):
-			String model_name
-			output("Element to modify?")
-			model_name = input()
-			if (dict_in(model["model"], model_name)):
-				Element attrs
-				attrs = getAttributeList(model, model_name)
-				String attr_name
-				output("Attribute to modify?")
-				attr_name = input()
-				if (set_in(dict_keys(attrs), attr_name)):
-					output("New value?")
-					unset_attribute(model, model_name, attr_name)
-					instantiate_attribute(model, model_name, attr_name, input())
-					output("Modified!")
-				else:
-					output("No such attribute!")
-			else:
-				output("No such model!")
-		elif (cmd == "attr_add"):
-			String model_name
-			output("Which model do you want to assign an attribute to?")
-			model_name = input()
-			if (dict_in(model["model"], model_name)):
-				Element attrs
-				attrs = getAttributeList(model, model_name)
-				String attr_name
-				output("Which attribute do you wish to assign?")
-				attr_name = input()
-				if (set_in(dict_keys(attrs), attr_name)):
-					output("Value of attribute?")
-					instantiate_attribute(model, model_name, attr_name, input())
-					output("Added attribute!")
-				else:
-					output("No such attribute!")
-			else:
-				output("No such model!")
-		elif (cmd == "attr_add_code"):
-			String model_name
-			output("Which model do you want to assign a coded attribute to?")
-			model_name = input()
-			if (dict_in(model["model"], model_name)):
-				Element attrs
-				attrs = getAttributeList(model, model_name)
-				String attr_name
-				output("Which attribute do you wish to assign?")
-				attr_name = input()
-				if (set_in(dict_keys(attrs), attr_name)):
-					output("Constructors for code?")
-					instantiate_attribute_code(model, model_name, attr_name, construct_function())
-					output("Added code!")
-				else:
-					output("No such attribute!")
-			else:
-				output("No such model!")
-		elif (cmd == "attr_del"):
-			String model_name
-			output("Which model do you want to remove an attribute of?")
-			model_name = input()
-			if (dict_in(model["model"], model_name)):
-				Element attrs
-				attrs = getAttributeList(model, model_name)
-				String attr_name
-				output("Which attribute do you want to delete?")
-				attr_name = input()
-				if (set_in(dict_keys(attrs), attr_name)):
-					unset_attribute(model, model_name, attr_name)
-					output("Attribute deleted!")
-				else:
-					output("No such attribute!")
-			else:
-				output("No such model!")
-		elif (cmd == "delete"):
-			output("What is the name of the element you want to delete?")
-			cmd = input()
-			if (dict_in(model["model"], cmd)):
-				model_delete_element(model, cmd)
-				output("Deleted!")
-			else:
-				output("No such element; aborting")
-		elif (cmd == "rename"):
-			output("Old name?")
-			String old_name_e
-			old_name_e = input()
-			if (dict_in(model["model"], old_name_e)):
-				output("New name?")
-				String new_name_e
-				new_name_e = input()
-				if (dict_in(model["model"], new_name_e)):
-					output("New name already used; aborting")
-				else:
-					dict_add(model["model"], new_name_e, model["model"][old_name_e])
-					dict_delete(model["model"], old_name_e)
-					output("Rename complete!")
-			else:
-				output("Unknown element; aborting")
-		elif (cmd == "list"):
-			Element keys_m
-			keys_m = dict_keys(model["model"])
-			output("List of all elements:")
-			String v_m
-			while (read_nr_out(keys_m) > 0):
-				v_m = set_pop(keys_m)
-				// Filter out anonymous objects
-				if (bool_not(string_startswith(v_m, "__"))):
-					typename = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][v_m]))
-					output((("  " + v_m) + " : ") + typename)
-		elif (cmd == "read"):
-			output("Element to read?")
-			cmd = input()
-			if (dict_in(model["model"], cmd)):
-				Element read_elem
-				read_elem = model["model"][cmd]
-				metamodel_element_pn = dict_read_node(model["type_mapping"], read_elem)
-
-				output("Name: " + cmd)
-				output("Type: " + reverseKeyLookup(model["metamodel"]["model"], metamodel_element_pn))
-				if (is_edge(read_elem)):
-					output("Source: " + reverseKeyLookup(model["model"], read_edge_src(read_elem)))
-					output("Destination: " + reverseKeyLookup(model["model"], read_edge_dst(read_elem)))
-				if (cast_v2s(read_elem) != "None"):
-					output("Value: " + cast_v2s(read_elem))
-				output("Defines attributes:")
-				attr_list_pn = getInstantiatableAttributes(model, cmd)
-				attr_keys_pn = dict_keys(attr_list_pn)
-				while (0 < read_nr_out(attr_keys_pn)):
-					attr_key_pn = set_pop(attr_keys_pn)
-					output(((("  " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])))
-				output("Attributes:")
-				attr_list_pn = getAttributeList(model, cmd)
-				attr_keys_pn = dict_keys(attr_list_pn)
-				while (0 < read_nr_out(attr_keys_pn)):
-					attr_key_pn = set_pop(attr_keys_pn)
-					output((((("  " + cast_v2s(attr_key_pn)) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(read_attribute(model, reverseKeyLookup(model["model"], read_elem), attr_key_pn)))
-			else:
-				output("Unknown element; aborting")
-		elif (cmd == "verify"):
-			output(conformance_scd(model))
-		elif (cmd == "types"):
-			Element keys_t
-			keys_t = dict_keys(model["metamodel"]["model"])
-			output("List of types:")
-			String v_t
-			while (read_nr_out(keys_t) > 0):
-				v_t = set_pop(keys_t)
-				if (bool_not(string_startswith(v_t, "__"))):
-					output(string_join(("  " + v_t) + " : ", reverseKeyLookup(model["metamodel"]["metamodel"]["model"], dict_read_node(model["metamodel"]["type_mapping"], model["metamodel"]["model"][v_t]))))
-		elif (cmd == "retype"):
-			output("Element to retype?")
-			String elementname
-			elementname = input()
-			if (dict_in(model["model"], elementname)):
-				output("New type")
-				typename = input()
-				if (dict_in(model["metamodel"]["model"], typename)):
-					// OK, do the retyping
-					// First try removing the previous type if it exists
-					dict_delete_node(model["type_mapping"], model["model"][elementname])
-					// Now add the new type
-					dict_add(model["type_mapping"], model["model"][elementname], model["metamodel"]["model"][typename])
-					output("Retyped!")
-				else:
-					output("Unknown type; aborting")
-			else:
-				output("Unknown element; aborting")
-		elif (cmd == "switch"):
-			bottom = bool_not(bottom)
-
-			Element tmp_model
-			tmp_model = model
-			model = other_metamodel
-			other_metamodel = tmp_model
-
-			if (bottom):
-				// The type mapping we are using is probably not complete for our model
-				// so we completely recreate it from the model we have.
-				output("Switching to conformance bottom mode!")
-				generate_bottom_type_mapping(model)
-			else:
-				// We already switched the models and such, so we are already done!
-				output("Switching to linguistic metamodel!")
-		else:
-			output("Unknown command: " + cast_v2s(cmd))
-			output("Use command 'help' to get a list of available commands")
-
-	return model!
-
-Void function main():
-	output("Welcome to the Model Management Interface, running live on the Modelverse!")
-	output("Use 'help' command for a list of possible commands")
-	String command
-	Element root
-	Element metamodel
-	String name
-	Element my_model
-	String mm_name
-
-	root = create_metamodels()
-
-	while (True):
-		output("Please give your command.")
-		command = input()
-		if (command == "help"):
-			output("Currently no model is loaded, so your operations are limited to:")
-			output("  new    -- Create a new model and save it for future use")
-			output("  load   -- Load a previously made model")
-			output("  rename -- Rename a previously made model")
-			output("  delete -- Delete a previously made model")
-			output("  list   -- Show a list of all stored models")
-			output("  upload -- Upload a model using the model constructor commands")
-			output("  ramify -- RAMify existing metamodels to generate a language for transformations")
-			output("  transform -- Execute a previously defined model transformation")
-			output("  help   -- Show a list of possible commands")
-		elif (command == "new"):
-			output("Metamodel to instantiate?")
-			mm_name = input()
-			if (dict_in(root, mm_name)):
-				output("Name of model?")
-				name = input()
-				if (dict_in(root, name)):
-					output("Model exists; aborting")
-				else:
-					my_model = instantiate_model(root[mm_name])
-					dict_add(root, name, my_model)
-					model_loaded(my_model)
-			else:
-				output("Unknown metamodel; aborting")
-		elif (command == "upload"):
-			construct_model()
-		elif (command == "load"):
-			output("Model to load?")
-			name = input()
-			if (dict_in(root, name)):
-				my_model = root[name]
-				model_loaded(my_model)
-			else:
-				output("Model not found; aborting")
-		elif (command == "list"):
-			Element keys
-			String m_menu_list
-			keys = dict_keys(root)
-			output("Found models:")
-			while (read_nr_out(keys) > 0):
-				m_menu_list = set_pop(keys)
-				if (bool_not(string_startswith(m_menu_list, "__"))):
-					output((("  " + m_menu_list) + " : ") + reverseKeyLookup(root, root[m_menu_list]["metamodel"]))
-		elif (command == "delete"):
-			output("Model to delete?")
-			name = input()
-			if (dict_in(root, name)):
-				dict_delete(root, name)
-				output("Deleted!")
-			else:
-				output("Model not found; aborting")
-		elif (command == "rename"):
-			output("Old name?")
-			String old_name
-			old_name = input()
-			if (dict_in(root, old_name)):
-				output("New name?")
-				String new_name
-				new_name = input()
-				if (dict_in(root, new_name)):
-					output("Model exists; aborting")
-				else:
-					dict_add(root, new_name, root[old_name])
-					dict_delete(root, old_name)
-					output("Rename complete!")
-			else:
-				output("Model not found; aborting")
-		elif (command == "actions"):
-			output("Switching to compilation manager!")
-			compilation_manager()
-			output("Back in model manager!")
-		elif (command == "unify"):
-			String mm1
-			String mm2
-			String name1
-			String name2
-			Element result
-			name = input()
-			if (dict_in(root, name)):
-				output("Already exists; aborting")
-			else:
-				output("Which language do you want to unify?")
-				mm1 = input()
-				if (dict_in(root, mm1)):
-					output("Name of this language in the unification")
-					name1 = input()
-					output("Second language to unify?")
-					mm2 = input()
-					if (dict_in(root, mm2)):
-						output("Name of this language in the unification")
-						name2 = input()
-						log("Calling model_fuse")
-						result = model_fuse(name1, root[mm1], name2, root[mm2])
-						dict_add(root, name, result)
-					else:
-						output("Second model not found; aborting")
-				else:
-					output("Model not found; aborting")
-		elif (command == "split"):
-			String mm_name
-			String value
-
-			output("Name of the model to split up?")
-			name = input()
-			if (dict_in(root, name)):
-				output("Name of new metamodel?")
-				mm_name = input()
-				if (dict_in(root, mm_name)):
-					output("Typename to split?")
-					value = input()
-					model_retype_on_name(root[name], root[mm_name], "-", value)
-				else:
-					output("No such metamodel; aborting")
-			else:
-				output("No such model; aborting")
-		elif (command == "join"):
-			String mm_name
-			String value
-
-			output("Model name?")
-			name = input()
-			if (dict_in(root, name)):
-				output("New metamodel?")
-				mm_name = input()
-				if (dict_in(root, mm_name)):
-					value = input()
-					model_retype_on_name(root[name], root[mm_name], "+", value)
-				else:
-					output("No such metamodel; aborting")
-			else:
-				output("No such model; aborting")
-		elif (command == "ramify"):
-			Element result
-			String old_name
-			output("Name of the RAMified metamodel to create")
-			name = input()
-			if (dict_in(root, name)):
-				output("Already exists; aborting")
-			else:
-				output("Source language?")
-				String source
-				source = input()
-				if (dict_in(root, source)):
-					result = ramify(root[source])
-					dict_add(root, name, result)
-				else:
-					output("Unknown source language; aborting")
-		elif (command == "transform"):
-			Element result
-			String schedule
-			output("Which model do you want to transform?")
-			name = input()
-			if (dict_in(root, name)):
-				output("Which schedule do you want to execute?")
-				schedule = input()
-				if (dict_in(root, schedule)):
-					result = transform(root[name], root[schedule])
-					output("Transformation result: " + cast_v2s(result))
-				else:
-					output("Unknown transformation selected!")
-			else:
-				output("Unknown host model selected!")
-		elif (command == "generate_ftg"):
-			Element ftg
-			output("Name to store the FTG?")
-			name = input()
-
-			if (dict_in(root, name)):
-				output("Model already exists; aborting")
-			else:
-				ftg = create_ftg(root)
-				dict_add(root, name, ftg)
-		else:
-			output("Command not recognized, use 'help' for a list of possible commands")
-
-	return!

+ 2 - 2
integration/code/pn_print.mvc

@@ -5,12 +5,12 @@ RAM_PN_R print {
         {Contains} Success success {}
         {Contains} ForAll print_tokens {
             LHS {
-                Pre_Place {
+                Pre_PetriNets/Place {
                     label = "0"
                 }
             }
             RHS {
-                Post_Place {
+                Post_PetriNets/Place {
                     label = "0"
                     action = $
                         include "primitives.alh"

+ 27 - 0
integration/code/pn_print_MR.mvc

@@ -0,0 +1,27 @@
+RAM_PN_R print {
+    Composite schedule {
+        {Contains} Success success {}
+        {Contains} ForAll print_tokens {
+            LHS {
+                Pre_PetriNets_Place {
+                    label = "0"
+                }
+            }
+            RHS {
+                Post_PetriNets_Place {
+                    label = "0"
+                    action = $
+                        include "primitives.alh"
+                        include "modelling.alh"
+                        Void function action(host_model : Element, name : String, mapping : Element):
+                            output((cast_v2s(read_attribute(host_model, name, "name")) + " --> ") + cast_v2s(read_attribute(host_model, name, "tokens")))
+                            return!
+                        $
+                }
+            }
+        }
+    }
+    OnSuccess (print_tokens, success) {}
+    OnFailure (print_tokens, success) {}
+    Initial (schedule, print_tokens) {}
+}

+ 19 - 0
integration/code/pn_runtime_MR.mvc

@@ -0,0 +1,19 @@
+SimpleClassDiagrams PetriNets_Runtime{
+    Class Natural {}
+    Class Boolean {}
+    Class String {}
+
+    Class Place {
+        tokens : Natural
+        name : String
+    }
+    Class Transition {
+        executing : Boolean
+    }
+    Association P2T (Place, Transition) {
+        weight : Natural
+    }
+    Association T2P (Transition, Place) {
+        weight : Natural
+    }
+}

+ 26 - 0
integration/code/pn_runtime_model_MR.mvc

@@ -0,0 +1,26 @@
+PetriNets_Runtime pn {
+	Place p1 {
+		tokens = 1
+        name = "p1"
+	}
+	Place p2 {
+		tokens = 2
+        name = "p2"
+	}
+	Place p3 {
+		tokens = 3
+        name = "p3"
+	}
+	Transition t1 {
+		executing = False
+	}
+	P2T (p1, t1) {
+		weight = 1
+	}
+	P2T (p2, t1) {
+		weight = 1
+	}
+	T2P (t1, p3) {
+		weight = 2
+	}
+}

+ 179 - 0
integration/code/pn_runtime_to_design.mvc

@@ -0,0 +1,179 @@
+import models/RAM_PetriNets_Design_Runtime as RAM_PN_DR
+
+RAM_PN_DR annotate {
+    Composite schedule {
+        {Contains} Failure failure {}
+        {Contains} Success success {}
+        {Contains} ForAll copy_transitions {
+            LHS {
+                Pre_PetriNets_Runtime/Transition {
+                    label = "0"
+                }
+            }
+            RHS {
+                Post_PetriNets_Runtime/Transition ct1 {
+                    label = "0"
+                }
+                Post_PetriNets/Transition ct2 {
+                    label = "1"
+                }
+                Post_R2D_TransitionLink (ct1, ct2){
+                    label = "2"
+                }
+            }
+        }
+        {Contains} ForAll copy_places {
+            LHS {
+                Pre_PetriNets_Runtime/Place {
+                    label = "0"
+                }
+            }
+            RHS {
+                Post_PetriNets_Runtime/Place cp1 {
+                    label = "0"
+                }
+                Post_PetriNets/Place cp2 {
+                    label = "1"
+                    action = $
+                        include "primitives.alh"
+                        include "modelling.alh"
+                        Void function action(host_model : Element, name : String, mapping : Element):
+                            instantiate_attribute(host_model, name, "tokens", read_attribute(host_model, mapping["0"], "tokens"))
+                            instantiate_attribute(host_model, name, "name", read_attribute(host_model, mapping["0"], "name"))
+                            return!
+                        $
+                }
+                Post_R2D_PlaceLink (cp1, cp2){
+                    label = "2"
+                }
+            }
+        }
+        {Contains} ForAll copy_P2T {
+            LHS {
+                Pre_PetriNets_Runtime/Place cp2t_p{
+                    label = "0"
+                }
+                Pre_PetriNets_Runtime/Transition cp2t_t{
+                    label = "1"
+                }
+                Pre_PetriNets_Runtime/P2T (cp2t_p, cp2t_t){
+                    label = "2"
+                }
+                Pre_PetriNets/Place cp2t_p2{
+                    label = "3"
+                }
+                Pre_PetriNets/Transition cp2t_t2{
+                    label = "4"
+                }
+                Pre_R2D_PlaceLink (cp2t_p, cp2t_p2){
+                    label = "5"
+                }
+                Pre_R2D_TransitionLink (cp2t_t, cp2t_t2){
+                    label = "6"
+                }
+            }
+            RHS {
+                Post_PetriNets_Runtime/Place rhs_cp2t_p{
+                    label = "0"
+                }
+                Post_PetriNets_Runtime/Transition rhs_cp2t_t{
+                    label = "1"
+                }
+                Post_PetriNets_Runtime/P2T rhs_cp2t_p2t (rhs_cp2t_p, rhs_cp2t_t){
+                    label = "2"
+                }
+                Post_PetriNets/Place rhs_cp2t_p2 {
+                    label = "3"
+                }
+                Post_PetriNets/Transition rhs_cp2t_t2 {
+                    label = "4"
+                }
+                Post_R2D_PlaceLink (rhs_cp2t_p, rhs_cp2t_p2){
+                    label = "5"
+                }
+                Post_R2D_TransitionLink (rhs_cp2t_t, rhs_cp2t_t2){
+                    label = "6"
+                }
+                Post_PetriNets/P2T rhs_cp2t_p2t2(rhs_cp2t_p2, rhs_cp2t_t2) {
+                    label = "7"
+                    action = $
+                        include "primitives.alh"
+                        include "modelling.alh"
+                        Void function action(host_model : Element, name : String, mapping : Element):
+                            instantiate_attribute(host_model, name, "weight", read_attribute(host_model, mapping["2"], "weight"))
+                            return!
+                        $
+                }
+            }
+        }
+        {Contains} ForAll copy_T2P {
+            LHS {
+                Pre_PetriNets_Runtime/Place ct2p_p{
+                    label = "0"
+                }
+                Pre_PetriNets_Runtime/Transition ct2p_t{
+                    label = "1"
+                }
+                Pre_PetriNets_Runtime/T2P (ct2p_t, ct2p_p){
+                    label = "2"
+                }
+                Pre_PetriNets/Place ct2p_p2{
+                    label = "3"
+                }
+                Pre_PetriNets/Transition ct2p_t2{
+                    label = "4"
+                }
+                Pre_R2D_PlaceLink (ct2p_p, ct2p_p2){
+                    label = "5"
+                }
+                Pre_R2D_TransitionLink (ct2p_t, ct2p_t2){
+                    label = "6"
+                }
+            }
+            RHS {
+                Post_PetriNets_Runtime/Place rhs_ct2p_p{
+                    label = "0"
+                }
+                Post_PetriNets_Runtime/Transition rhs_ct2p_t{
+                    label = "1"
+                }
+                Post_PetriNets_Runtime/T2P (rhs_ct2p_t, rhs_ct2p_p){
+                    label = "2"
+                }
+                Post_PetriNets/Place rhs_ct2p_p2 {
+                    label = "3"
+                }
+                Post_PetriNets/Transition rhs_ct2p_t2 {
+                    label = "4"
+                }
+                Post_R2D_PlaceLink (rhs_ct2p_p, rhs_ct2p_p2){
+                    label = "5"
+                }
+                Post_R2D_TransitionLink (rhs_ct2p_t, rhs_ct2p_t2){
+                    label = "6"
+                }
+                Post_PetriNets/T2P (rhs_ct2p_t2, rhs_ct2p_p2) {
+                    label = "7"
+                    action = $
+                        include "primitives.alh"
+                        include "modelling.alh"
+                        Void function action(host_model : Element, name : String, mapping : Element):
+                            instantiate_attribute(host_model, name, "weight", read_attribute(host_model, mapping["2"], "weight"))
+                            return!
+                        $
+                }
+            }
+        }
+    }
+    OnSuccess (copy_places, copy_transitions) {}
+    OnSuccess (copy_transitions, copy_P2T) {}
+    OnSuccess (copy_P2T, copy_T2P) {}
+    OnSuccess (copy_T2P, success) {}
+    OnFailure (copy_places, copy_transitions) {}
+    OnFailure (copy_transitions, copy_P2T) {}
+    OnFailure (copy_P2T, copy_T2P) {}
+    OnFailure (copy_T2P, success) {}
+    Initial (schedule, copy_places) {}
+}
+
+export annotate to models/pn_annotate

+ 19 - 18
integration/code/pn_simulate.mvc

@@ -1,4 +1,4 @@
-import models/RAM_PetriNets_Runtime as RAM_PN_R
+import models/RAM_PetriNets_Runtime_Runtime as RAM_PN_R
 
 RAM_PN_R s {
     Composite schedule {
@@ -6,7 +6,7 @@ RAM_PN_R s {
         {Contains} Success success {}
         {Contains} Atomic mark {
             LHS {
-                Pre_Transition {
+                Pre_PetriNets_Runtime/Transition {
                     label = "1"
                     constraint = $
                         include "primitives.alh"
@@ -16,7 +16,8 @@ RAM_PN_R s {
                             Element links
                             String link
                             String place
-                            links = allIncomingAssociationInstances(host_model, name, "P2T")
+                            log("Types in metamodel: " + set_to_string(dict_keys(host_model["metamodel"]["model"])))
+                            links = allIncomingAssociationInstances(host_model, name, "PetriNets_Runtime/P2T")
                             while (read_nr_out(links) > 0):
                                 link = set_pop(links)
                                 place = readAssociationSource(host_model, link)
@@ -27,7 +28,7 @@ RAM_PN_R s {
                 }
             }
             RHS {
-                Post_Transition {
+                Post_PetriNets_Runtime/Transition {
                     label = "1"
                     action = $
                         include "primitives.alh"
@@ -42,7 +43,7 @@ RAM_PN_R s {
         }
         {Contains} ForAll consume {
             LHS {
-                Pre_Transition lhs_consume_t{
+                Pre_PetriNets_Runtime/Transition lhs_consume_t{
                     label = "0"
                     constraint = $
                         include "primitives.alh"
@@ -52,18 +53,18 @@ RAM_PN_R s {
                             return value_eq(read_attribute(host_model, name, "executing"), True)!
                         $
                 }
-                Pre_Place lhs_consume_p{
+                Pre_PetriNets_Runtime/Place lhs_consume_p{
                     label = "1"
                 }
-                Pre_P2T lhs_consume_p2t(lhs_consume_p, lhs_consume_t){
+                Pre_PetriNets_Runtime/P2T lhs_consume_p2t(lhs_consume_p, lhs_consume_t){
                     label = "2"
                 }
             }
             RHS {
-                Post_Transition rhs_consume_t {
+                Post_PetriNets_Runtime/Transition rhs_consume_t {
                     label = "0"
                 }
-                Post_Place rhs_consume_p {
+                Post_PetriNets_Runtime/Place rhs_consume_p {
                     label = "1"
                     action = $
                         include "primitives.alh"
@@ -81,14 +82,14 @@ RAM_PN_R s {
                             return!
                         $
                 }
-                Post_P2T (rhs_consume_p, rhs_consume_t){
+                Post_PetriNets_Runtime/P2T (rhs_consume_p, rhs_consume_t){
                     label = "2"
                 }
             }
         }
         {Contains} ForAll produce {
             LHS {
-                Pre_Transition lhs_produce_t{
+                Pre_PetriNets_Runtime/Transition lhs_produce_t{
                     label = "0"
                     constraint = $
                         include "primitives.alh"
@@ -98,18 +99,18 @@ RAM_PN_R s {
                             return value_eq(read_attribute(host_model, name, "executing"), True)!
                         $
                 }
-                Pre_Place lhs_produce_p{
+                Pre_PetriNets_Runtime/Place lhs_produce_p{
                     label = "1"
                 }
-                Pre_T2P (lhs_produce_t, lhs_produce_p){
+                Pre_PetriNets_Runtime/T2P (lhs_produce_t, lhs_produce_p){
                     label = "2"
                 }
             }
             RHS {
-                Post_Transition rhs_produce_t{
+                Post_PetriNets_Runtime/Transition rhs_produce_t{
                     label = "0"
                 }
-                Post_Place rhs_produce_p{
+                Post_PetriNets_Runtime/Place rhs_produce_p{
                     label = "1"
                     action = $
                         include "primitives.alh"
@@ -127,14 +128,14 @@ RAM_PN_R s {
                             return!
                         $
                 }
-                Post_T2P (rhs_produce_t, rhs_produce_p){
+                Post_PetriNets_Runtime/T2P (rhs_produce_t, rhs_produce_p){
                     label = "2"
                 }
             }
         }
         {Contains} Atomic unmark_transition {
             LHS {
-                Pre_Transition {
+                Pre_PetriNets_Runtime/Transition {
                     label = "0"
                     constraint = $
                         include "primitives.alh"
@@ -146,7 +147,7 @@ RAM_PN_R s {
                 }
             }
             RHS {
-                Post_Transition {
+                Post_PetriNets_Runtime/Transition {
                     label = "0"
                     action = $
                         include "primitives.alh"

+ 0 - 33
integration/my_petrinet_with_MM_and_constraints.mvc

@@ -1,33 +0,0 @@
-import models/SimpleClassDiagrams as SCD
-
-SCD PetriNets{
-    Class Natural {}
-    Class Place{
-        tokens : Natural
-    }
-    Class Transition{}
-    Association P2T (Place, Transition) {
-        weight : Natural
-    }
-    Association T2P (Transition, Place) {
-        weight : Natural
-    }
-}
-
-PetriNets my_petrinet {
-    Place p1 {
-        tokens = 1
-    }
-    Place p2 {
-        tokens = 3
-    }
-    Transition t1 {}
-    P2T (p1, t1) {
-        weight = 1
-    }
-    T2P (t1, p2) {
-        weight = 2
-    }
-}
-
-export my_petrinet to models/my_petrinet

+ 851 - 0
integration/test_mvc.py

@@ -0,0 +1,851 @@
+import unittest
+
+from utils import run_file, get_constructor, get_model_constructor
+
+all_files = [   "core/mini_modify.alc",
+                "core/core_formalism.mvc",
+                "core/core_algorithm.alc",
+                "primitives.alc",
+                "object_operations.alc",
+                "conformance_scd.alc",
+                "library.alc",
+                "ftg.alc",
+                "transform.alc",
+                "model_management.alc",
+                "ramify.alc",
+                "metamodels.alc",
+                "random.alc",
+                "constructors.alc",
+                "modelling.alc",
+                "compilation_manager.alc",
+            ]
+
+class TestModelverseCore(unittest.TestCase):
+    def test_po_list(self):
+        self.list("PO")
+
+    def list(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_list",
+            ],
+            [   "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  core : CoreFormalism"]),
+            ],
+            mode))
+
+    def test_po_list_full(self):
+        self.list_full("PO")
+
+    def list_full(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_list_full",
+            ],
+            [   "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root admin    45   core : CoreFormalism"]),
+            ],
+            mode))
+
+    def test_po_model_add_empty(self):
+        self.model_add_empty("PO")
+
+    def model_add_empty(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                "SimpleClassDiagrams",
+                "Empty",
+                "exit",
+                "model_list",
+                "model_list_full",
+            ],
+            [   "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  Empty : SimpleClassDiagrams",
+                     "  core : CoreFormalism"]),
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    0   Empty : SimpleClassDiagrams",
+                     "  200  root admin    55   core : CoreFormalism"]),
+            ],
+            mode))
+
+    def test_po_model_empty_modify(self):
+        self.model_empty_modify("PO")
+
+    def model_empty_modify(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                "SimpleClassDiagrams",
+                "Empty",
+                "exit",
+                "model_list",
+                "model_list_full",
+                "model_modify",
+                "Empty",
+                "instantiate",
+                "Class",
+                "A",
+                "exit",
+                "model_list_full",
+            ],
+            [   "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  Empty : SimpleClassDiagrams",
+                     "  core : CoreFormalism"]),
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    0   Empty : SimpleClassDiagrams",
+                     "  200  root admin    55   core : CoreFormalism"]),
+                "Ready for command...",
+                "Which model do you want to modify?",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                "Type to instantiate?",
+                "Name of new element?",
+                "Instantiation successful!",
+                "Please give your command.",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    1   Empty : SimpleClassDiagrams",
+                     "  200  root admin    55   core : CoreFormalism"]),
+                "Ready for command...",
+            ],
+            mode))
+
+    def test_po_model_overwrite(self):
+        self.model_overwrite("PO")
+
+    def model_overwrite(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                "SimpleClassDiagrams",
+                "Empty",
+                "exit",
+                "model_list_full",
+                "model_modify",
+                "Empty",
+                "instantiate",
+                "Class",
+                "A",
+                "exit",
+                "model_list_full",
+                "model_overwrite",
+                "Empty",
+                "instantiate_node",
+                "",
+                "Class",
+                "B",
+                "instantiate_node",
+                "",
+                "Class",
+                "C",
+                "exit",
+                "model_list_full",
+                "model_modify",
+                "Empty",
+                "list",
+                "exit",
+            ],
+            [   "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    0   Empty : SimpleClassDiagrams",
+                     "  200  root admin    55   core : CoreFormalism"]),
+                "Ready for command...",
+                "Which model do you want to modify?",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                "Type to instantiate?",
+                "Name of new element?",
+                "Instantiation successful!",
+                "Please give your command.",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    1   Empty : SimpleClassDiagrams",
+                     "  200  root admin    55   core : CoreFormalism"]),
+                "Ready for command...",
+                "Which model to overwrite?",
+                "Waiting for model constructors...",
+                "Model overwrite success!",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    2   Empty : SimpleClassDiagrams",
+                     "  200  root admin    55   core : CoreFormalism"]),
+                "Ready for command...",
+                "Which model do you want to modify?",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                "List of all elements:",
+                set(["  B : Class",
+                     "  C : Class"]),
+                "Please give your command.",
+                "Ready for command...",
+            ],
+            mode))
+
+    def test_po_transform_add_MT_language(self):
+        self.transform_add_MT_language("PO")
+
+    def transform_add_MT_language(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                "SimpleClassDiagrams",
+                "PetriNets",
+                ] + get_model_constructor(open("integration/code/petrinets.mvc", "r").read()) + [
+                "model_list_full",
+                "transformation_add_MT_language",
+                "PetriNets",
+                "",
+                "PetriNets_RAM",
+                "model_list_full",
+            ],
+            [   "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    14   PetriNets : SimpleClassDiagrams",
+                     "  200  root admin    55   core : CoreFormalism"]),
+                "Ready for command...",
+                "Formalisms to include (terminate with empty string)?",
+                "Name of the RAMified transformation metamodel?",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    14   PetriNets : SimpleClassDiagrams",
+                     "  200  root nobody    14   __merged_PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root nobody    328   PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root admin    81   core : CoreFormalism"]),
+                "Ready for command...",
+            ],
+            mode))
+
+    def test_po_transform_add_MT_instance(self):
+        self.transform_add_MT_instance("PO")
+
+    def transform_add_MT_instance(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                "SimpleClassDiagrams",
+                "PetriNets",
+                ] + get_model_constructor(open("integration/code/petrinets.mvc", "r").read()) + [
+                "model_list_full",
+                "transformation_add_MT_language",
+                "PetriNets",
+                "",
+                "PetriNets_RAM",
+                "model_list_full",
+                "transformation_add_MT",
+                "PetriNets_RAM",
+                "PetriNets",
+                "",
+                "",
+                "PetriNets_Print",
+                "exit",
+                "model_list_full",
+                "transformation_list",
+                "transformation_list_full",
+            ],
+            [   "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    14   PetriNets : SimpleClassDiagrams",
+                     "  200  root admin    55   core : CoreFormalism"]),
+                "Ready for command...",
+                "Formalisms to include (terminate with empty string)?",
+                "Name of the RAMified transformation metamodel?",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    14   PetriNets : SimpleClassDiagrams",
+                     "  200  root nobody    14   __merged_PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root nobody    328   PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root admin    81   core : CoreFormalism"]),
+                "Ready for command...",
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  PetriNets",
+                    ]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Model added as source",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    14   PetriNets : SimpleClassDiagrams",
+                     "  200  root nobody    14   __merged_PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root nobody    328   PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root nobody    0   PetriNets_Print : PetriNets_RAM",
+                     "  200  root admin    94   core : CoreFormalism"]),
+                "Ready for command...",
+                set(["[ModelTransformation] PetriNets_Print : PetriNets_RAM",
+                    ]),
+                "Ready for command...",
+                set(["  200  root nobody    0   [ModelTransformation] PetriNets_Print : PetriNets_RAM"
+                    ]),
+                "Ready for command...",
+            ],
+            mode))
+
+    def test_po_transform_add_MT_pn_print_upload(self):
+        self.transform_add_MT_pn_print_upload("PO")
+
+    def transform_add_MT_pn_print_upload(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                "SimpleClassDiagrams",
+                "PetriNets",
+                ] + get_model_constructor(open("integration/code/pn_runtime.mvc", "r").read()) + [
+                "model_list_full",
+                "transformation_add_MT_language",
+                "PetriNets",
+                "",
+                "PetriNets_RAM",
+                "model_list_full",
+                "transformation_add_MT",
+                "PetriNets_RAM",
+                "PetriNets",
+                "",
+                "",
+                "PetriNets_Print",
+                ] + get_model_constructor(open("integration/code/pn_print.mvc", "r").read()) + [
+                "transformation_list_full",
+            ],
+            [   "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    22   PetriNets : SimpleClassDiagrams",
+                     "  200  root admin    55   core : CoreFormalism"]),
+                "Ready for command...",
+                "Formalisms to include (terminate with empty string)?",
+                "Name of the RAMified transformation metamodel?",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    22   PetriNets : SimpleClassDiagrams",
+                     "  200  root nobody    22   __merged_PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root nobody    352   PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root admin    81   core : CoreFormalism"]),
+                "Ready for command...",
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  PetriNets",
+                    ]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Model added as source",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                set(["  200  root nobody    26   [ModelTransformation] PetriNets_Print : PetriNets_RAM"
+                    ]),
+                "Ready for command...",
+            ],
+            mode))
+
+    def test_po_transform_add_MT_pn_print_exec(self):
+        self.transform_add_MT_pn_print_exec("PO")
+
+    def transform_add_MT_pn_print_exec(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                "SimpleClassDiagrams",
+                "PetriNets",
+                ] + get_model_constructor(open("integration/code/pn_runtime.mvc", "r").read()) + [
+                "model_add",
+                "PetriNets",
+                "my_pn",
+                ] + get_model_constructor(open("integration/code/pn_runtime_model.mvc", "r").read()) + [
+                "model_list_full",
+                "transformation_add_MT_language",
+                "PetriNets",
+                "",
+                "PetriNets_RAM",
+                "model_list_full",
+                "transformation_add_MT",
+                "PetriNets_RAM",
+                "PetriNets",
+                "",
+                "",
+                "PetriNets_Print",
+                ] + get_model_constructor(open("integration/code/pn_print.mvc", "r").read()) + [
+                "transformation_list_full",
+                "transformation_execute",
+                "PetriNets_Print",
+                "my_pn",
+                "transformation_list_full",
+            ],
+            [   "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    22   PetriNets : SimpleClassDiagrams",
+                     "  200  root nobody    27   my_pn : PetriNets",
+                     "  200  root admin    65   core : CoreFormalism"]),
+                "Ready for command...",
+                "Formalisms to include (terminate with empty string)?",
+                "Name of the RAMified transformation metamodel?",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    90   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    22   PetriNets : SimpleClassDiagrams",
+                     "  200  root nobody    22   __merged_PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root nobody    352   PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root nobody    27   my_pn : PetriNets",
+                     "  200  root admin    91   core : CoreFormalism"]),
+                "Ready for command...",
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  PetriNets",
+                    ]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Model added as source",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                set(["  200  root nobody    26   [ModelTransformation] PetriNets_Print : PetriNets_RAM"
+                    ]),
+                "Ready for command...",
+                "Which transformation do you want to execute?",
+                "Which model to bind for source element PetriNets",
+                set(['"p1" --> 1',
+                     '"p2" --> 2',
+                     '"p3" --> 3',
+                    ]),
+                "Transformation executed with result: True",
+                "Ready for command...",
+            ],
+            mode))
+
+    def test_po_transform_add_MT_pn_simulate(self):
+        self.transform_add_MT_pn_simulate("PO")
+
+    def transform_add_MT_pn_simulate(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                    "SimpleClassDiagrams",
+                    "PetriNets",
+                    ] + get_model_constructor(open("integration/code/pn_design.mvc", "r").read()) + [
+                "model_add",
+                    "SimpleClassDiagrams",
+                    "PetriNets_Runtime",
+                    ] + get_model_constructor(open("integration/code/pn_runtime.mvc", "r").read()) + [
+                "model_add",
+                    "PetriNets",
+                    "my_pn",
+                    ] + get_model_constructor(open("integration/code/pn_design_model.mvc", "r").read()) + [
+                "model_list",
+                "transformation_add_MT_language",
+                    "PetriNets_Runtime",
+                    "PetriNets",
+                    "",
+                    "PetriNets_RAM",
+                "model_list",
+                "model_modify",
+                    "__merged_PetriNets_RAM",
+                        "instantiate",
+                            "Association",
+                            "D2R_PlaceLink",
+                            "PetriNets/Place",
+                            "PetriNets_Runtime/Place",
+                        "instantiate",
+                            "Association",
+                            "D2R_TransitionLink",
+                            "PetriNets/Transition",
+                            "PetriNets_Runtime/Transition",
+                        "instantiate",
+                            "Association",
+                            "R2D_PlaceLink",
+                            "PetriNets_Runtime/Place",
+                            "PetriNets/Place",
+                        "instantiate",
+                            "Association",
+                            "R2D_TransitionLink",
+                            "PetriNets_Runtime/Transition",
+                            "PetriNets/Transition",
+                        "exit",
+                "transformation_RAMify",
+                    "__merged_PetriNets_RAM",
+                    "PetriNets_RAM",
+                "transformation_add_MT",
+                    "PetriNets_RAM",
+                    "PetriNets",
+                    "",
+                    "PetriNets_Runtime",
+                    "",
+                    "pn_design_to_runtime",
+                    ] + get_model_constructor(open("integration/code/pn_design_to_runtime.mvc", "r").read()) + [
+                "transformation_add_MT",
+                    "PetriNets_RAM",
+                    "PetriNets_Runtime",
+                    "",
+                    "PetriNets",
+                    "",
+                    "pn_runtime_to_design",
+                    ] + get_model_constructor(open("integration/code/pn_runtime_to_design.mvc", "r").read()) + [
+                "transformation_add_MT",
+                    "PetriNets_RAM",
+                    "PetriNets_Runtime",
+                    "",
+                    "PetriNets_Runtime",
+                    "",
+                    "pn_step",
+                    ] + get_model_constructor(open("integration/code/pn_simulate.mvc", "r").read()) + [
+                "transformation_add_MT",
+                    "PetriNets_RAM",
+                    "PetriNets",
+                    "",
+                    "",
+                    "pn_print",
+                    ] + get_model_constructor(open("integration/code/pn_print.mvc", "r").read()) + [
+                "model_list",
+                "transformation_list",
+                "transformation_execute",
+                "pn_print",
+                "my_pn",
+                "transformation_execute",
+                "pn_design_to_runtime",
+                "my_pn",
+                "my_pn_runtime",
+                "transformation_execute",
+                "pn_step",
+                "my_pn_runtime",
+                "my_pn_runtime",
+                "transformation_execute",
+                "pn_runtime_to_design",
+                "my_pn_runtime",
+                "my_pn",
+                "transformation_execute",
+                "pn_print",
+                "my_pn",
+            ],
+            [   # bootup phase
+                "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_list
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  PetriNets : SimpleClassDiagrams",
+                     "  my_pn : PetriNets",
+                     "  PetriNets_Runtime : SimpleClassDiagrams",
+                     "  core : CoreFormalism"]),
+                "Ready for command...",
+                # transformation_add_MT_language
+                "Formalisms to include (terminate with empty string)?",
+                "Name of the RAMified transformation metamodel?",
+                "Ready for command...",
+                # model_list
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  PetriNets_Runtime : SimpleClassDiagrams",
+                     "  PetriNets : SimpleClassDiagrams",
+                     "  __merged_PetriNets_RAM : SimpleClassDiagrams",
+                     "  PetriNets_RAM : SimpleClassDiagrams",
+                     "  my_pn : PetriNets",
+                     "  core : CoreFormalism"]),
+                "Ready for command...",
+                # model_modify
+                "Which model do you want to modify?",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                # instantiate 1
+                "Type to instantiate?",
+                "Name of new element?",
+                "Source name?",
+                "Destination name?",
+                "Instantiation successful!",
+                "Please give your command.",
+                # instantiate 2
+                "Type to instantiate?",
+                "Name of new element?",
+                "Source name?",
+                "Destination name?",
+                "Instantiation successful!",
+                "Please give your command.",
+                # instantiate 3
+                "Type to instantiate?",
+                "Name of new element?",
+                "Source name?",
+                "Destination name?",
+                "Instantiation successful!",
+                "Please give your command.",
+                # instantiate 4
+                "Type to instantiate?",
+                "Name of new element?",
+                "Source name?",
+                "Destination name?",
+                "Instantiation successful!",
+                "Please give your command.",
+                "Ready for command...",
+                # transformation_RAMify
+                "Which metamodel do you want to RAMify?",
+                "Where do you want to store the RAMified metamodel?",
+                "Ready for command...",
+                # transformation_add_MT
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  PetriNets",
+                     "  PetriNets_Runtime",
+                    ]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Model added as source",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Model added as target",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                # transformation_add_MT
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  PetriNets",
+                     "  PetriNets_Runtime",
+                    ]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Model added as source",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Model added as target",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                # transformation_add_MT
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  PetriNets",
+                     "  PetriNets_Runtime",
+                    ]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Model added as source",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Model added as target",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                # transformation_add_MT
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  PetriNets",
+                     "  PetriNets_Runtime",
+                    ]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Model added as source",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                # model_list
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  PetriNets_Runtime : SimpleClassDiagrams",
+                     "  PetriNets : SimpleClassDiagrams",
+                     "  pn_print : PetriNets_RAM",
+                     "  pn_design_to_runtime : PetriNets_RAM",
+                     "  pn_runtime_to_design : PetriNets_RAM",
+                     "  pn_step : PetriNets_RAM",
+                     "  __merged_PetriNets_RAM : SimpleClassDiagrams",
+                     "  PetriNets_RAM : SimpleClassDiagrams",
+                     "  my_pn : PetriNets",
+                     "  core : CoreFormalism"]),
+                "Ready for command...",
+                # transformation_list
+                set(["[ModelTransformation] pn_print : PetriNets_RAM",
+                     "[ModelTransformation] pn_design_to_runtime : PetriNets_RAM",
+                     "[ModelTransformation] pn_runtime_to_design : PetriNets_RAM",
+                     "[ModelTransformation] pn_step : PetriNets_RAM"]),
+                "Ready for command...",
+                # transformation_execute (pn_print)
+                "Which transformation do you want to execute?",
+                "Which model to bind for source element PetriNets",
+                set(['"p1" --> 1',
+                     '"p2" --> 2',
+                     '"p3" --> 3',
+                    ]),
+                "Transformation executed with result: True",
+                "Ready for command...",
+                # transformation_execute (pn_design_to_runtime)
+                "Which transformation do you want to execute?",
+                "Which model to bind for source element PetriNets",
+                "Which model to create for target element PetriNets_Runtime",
+                "Transformation executed with result: True",
+                "Ready for command...",
+                # transformation_execute (pn_step)
+                "Which transformation do you want to execute?",
+                "Which model to bind for source element PetriNets_Runtime",
+                "Which model to create for target element PetriNets_Runtime",
+                "Transformation executed with result: True",
+                "Ready for command...",
+                # transformation_execute (pn_runtime_to_design)
+                "Which transformation do you want to execute?",
+                "Which model to bind for source element PetriNets_Runtime",
+                "Which model to create for target element PetriNets",
+                "Transformation executed with result: True",
+                "Ready for command...",
+                # transformation_execute (pn_print)
+                "Which transformation do you want to execute?",
+                "Which model to bind for source element PetriNets",
+                set(['"p1" --> 0',
+                     '"p2" --> 1',
+                     '"p3" --> 5',
+                    ]),
+                "Transformation executed with result: True",
+                "Ready for command...",
+            ],
+            mode))

+ 0 - 662
integration/test_pn_interface.py

@@ -1,662 +0,0 @@
-import unittest
-
-from utils import run_file, get_constructor, get_model_constructor
-
-set_inheritance = [
-        "Which link in the metamodel is the inheritance link?",
-        "Set inheritance link!",
-    ]
-
-join = ["Model name?",
-        "New metamodel?",
-       ]
-
-unify = ["Which language do you want to unify?",
-         "Name of this language in the unification",
-         "Second language to unify?",
-         "Name of this language in the unification",
-         ]
-
-ramify = ["Name of the RAMified metamodel to create",
-          "Source language?"]
-
-transform = ["Which model do you want to transform?",
-             "Which schedule do you want to execute?",
-            ]
-
-transform_result_true = ["Transformation result: True"]
-transform_result_false = ["Transformation result: False"]
-
-split = ["Name of the model to split up?",
-         "Name of new metamodel?",
-         "Typename to split?",
-        ]
-
-do_instantiate_simple = [
-            "new", "PetriNets", "abc",
-            "instantiate", "Transition", "t1",
-            "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
-            "instantiate", "Place", "p2", "attr_add", "p2", "tokens", 0,
-            "instantiate", "P2T", "p2t", "p1", "t1", "attr_add", "p2t", "weight", 2,
-            "instantiate", "T2P", "t2p", "t1", "p2", "attr_add", "t2p", "weight", 1]
-
-instantiate_node = ["Type to instantiate?",
-                    "Name of new element?",
-                    "Instantiation successful!"]
-
-instantiate_edge = ["Type to instantiate?",
-                    "Name of new element?",
-                    "Source name?",
-                    "Destination name?",
-                    "Instantiation successful!"]
-
-all_files = [   "pn_interface.alc",
-                "primitives.alc",
-                "object_operations.alc",
-                "conformance_scd.alc",
-                "library.alc",
-                "ftg.alc",
-                "transform.alc",
-                "model_management.alc",
-                "ramify.alc",
-                "metamodels.alc",
-                "random.alc",
-                "constructors.alc",
-                "modelling.alc",
-                "compilation_manager.alc",
-            ]
-
-greeting =          ["Welcome to the Model Management Interface, running live on the Modelverse!",
-                     "Use 'help' command for a list of possible commands"]
-new =               ["Metamodel to instantiate?",
-                     "Name of model?"]
-prompt =            ["Please give your command."]
-loaded =            ["Model loaded, ready for commands!",
-                     "Use 'help' command for a list of possible commands"] + prompt
-load =              ["Model to load?"]
-instantiate =       ["Type to instantiate?"]
-instantiate_name =  ["Name of new element?"]
-instantiate_ok =    ["Instantiation successful!"]
-instantiate_source= ["Source name?"]
-instantiate_destination = ["Destination name?"]
-
-def list_menu(defined):
-    defined.append(("PetriNets", "SimpleClassDiagrams"))
-    defined.append(("SimpleClassDiagrams", "SimpleClassDiagrams"))
-    defined.append(("LTM_bottom", "LTM_bottom"))
-    defined.append(("FTG", "SimpleClassDiagrams"))
-    return ["Found models:",
-            set(["  %s : %s" % (m, mm) for m, mm in defined])]
-
-def list_model(defined):
-    return ["List of all elements:",
-            set(["  %s : %s" % (m, mm) for m, mm in defined])]
-
-def read_node(name, t, defs, attrs):
-    return ["Element to read?",
-            "Name: %s" % name, 
-            "Type: %s" % t,
-            "Defines attributes:"] + \
-            ([set(["  %s : %s" % (m, mm) for m, mm in defs])] if defs else []) + \
-            ["Attributes:"] + \
-            ([set(['  "%s" : "%s" = %s' % (m, mm, v) for m, mm, v in attrs])] if attrs else [])
-
-def read_edge(name, t, src, dst, defs, attrs):
-    return ["Element to read?",
-            "Name: %s" % name, 
-            "Type: %s" % t,
-            "Source: %s" % src,
-            "Destination: %s" % dst,
-            "Defines attributes:"] + \
-            ([set(["  %s : %s" % (m, mm) for m, mm in defs])] if defs else []) + \
-            ["Attributes:"] + \
-            ([set(['  "%s" : "%s" = %s' % (m, mm, v) for m, mm, v in attrs])] if attrs else [])
-
-delete =            ["Model to delete?", "Deleted!"]
-rename =            ["Old name?", "New name?", "Rename complete!"]
-attr_add =          ["Which model do you want to assign an attribute to?",
-                     "Which attribute do you wish to assign?",
-                     "Value of attribute?",
-                     "Added attribute!"]
-attr_del =          ["Which model do you want to remove an attribute of?",
-                     "Which attribute do you want to delete?",
-                     "Attribute deleted!",
-                    ]
-
-help_root =         ["Currently no model is loaded, so your operations are limited to:",
-                     "  new    -- Create a new model and save it for future use"
-                     "  load   -- Load a previously made model",
-                     "  rename -- Rename a previously made model",
-                     "  delete -- Delete a previously made model",
-                     "  list   -- Show a list of all stored models",
-                     "  help   -- Show a list of possible commands"]
-verify_fail_weight= ["Natural number not larger than or equal to zero"]
-verify_fail_tokens= ["Natural number not larger than or equal to zero"]
-verify_fail_structure = ["Source of model edge not typed by source of type: p2t"]
-
-init = greeting + prompt
-
-did_instantiate_simple = init + \
-                         new + \
-                         loaded +\
-                         instantiate_node + \
-                         prompt + \
-                         instantiate_node + \
-                         prompt + \
-                         attr_add + \
-                         prompt + \
-                         instantiate_node + \
-                         prompt + \
-                         attr_add + \
-                         prompt + \
-                         instantiate_edge + \
-                         prompt + \
-                         attr_add + \
-                         prompt + \
-                         instantiate_edge + \
-                         prompt + \
-                         attr_add + \
-                         prompt
-
-def list_types(t):
-    return ["List of types:"] + \
-            [set(["  %s : %s" % (m, mm) for m, mm in t])]
-
-modify =            ["Element to modify?", 
-                     "Attribute to modify?",
-                     "New value?",
-                     "Modified!",]
-
-class TestPetrinetInterface(unittest.TestCase):
-    def test_po_pn_interface_manage(self):
-        self.pn_interface_manage("PO")
-
-    def test_co_pn_interface_manage(self):
-        self.pn_interface_manage("CO")
-
-    def pn_interface_manage(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["list",
-             "new", "PetriNets", "abc", "exit",
-             "list",
-             "new", "PetriNets", "def", "exit",
-             "list",
-             "delete", "def",
-             "list",
-             "rename", "abc", "a",
-             "list",
-             "delete", "a",
-             "list",
-             ],
-            init + \
-                list_menu([]) + prompt + \
-                new + loaded + prompt + list_menu([("abc", "PetriNets")]) + prompt + \
-                new + loaded + prompt + list_menu([("abc", "PetriNets"), ("def", "PetriNets")]) + prompt + \
-                delete + prompt + list_menu([("abc", "PetriNets")]) + prompt + \
-                rename + prompt + list_menu([("a", "PetriNets")]) + prompt + \
-                delete + prompt + list_menu([]) + prompt,
-            mode))
-
-    def test_po_pn_interface_new_reload(self):
-        self.pn_interface_new_reload("PO")
-
-    def test_co_pn_interface_new_reload(self):
-        self.pn_interface_new_reload("CO")
-
-    def pn_interface_new_reload(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "exit", "load", "abc"],
-            init + new + loaded + prompt + load + loaded,
-            mode))
-
-    def test_po_pn_interface_instantiate_place(self):
-        self.pn_interface_instantiate_place("PO")
-
-    def test_co_pn_interface_instantiate_place(self):
-        self.pn_interface_instantiate_place("CO")
-
-    def pn_interface_instantiate_place(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc",
-            "instantiate", "Place", "p1",
-            "attr_add", "p1", "tokens", 5,
-            "list",
-            "read", "p1",
-            "instantiate", "Transition", "t1",
-            "list",
-            "read", "t1"],
-            init + new + loaded + \
-                instantiate_node + prompt + \
-                attr_add + prompt + \
-                list_model([("p1", "Place"), ("p1.tokens", "Natural")]) + prompt + \
-                read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
-                instantiate_node + prompt + \
-                list_model([("p1", "Place"), ("t1", "Transition"), ("p1.tokens", "Natural")]) + prompt + \
-                read_node("t1", "Transition", [], []) + prompt,
-            mode))
-
-    def test_po_pn_interface_instantiate_arcs(self):
-        self.pn_interface_instantiate_arcs("PO")
-
-    def test_co_pn_interface_instantiate_arcs(self):
-        self.pn_interface_instantiate_arcs("CO")
-
-    def pn_interface_instantiate_arcs(self, mode):
-        self.assertTrue(run_file(all_files,
-            do_instantiate_simple + [
-                    "read", "p1",
-                    "read", "p2",
-                    "read", "t1",
-                    "read", "p2t",
-                    "read", "t2p",
-                ],
-            did_instantiate_simple + \
-                read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
-                read_node("p2", "Place", [], [("tokens", "Natural", 0)]) + prompt + \
-                read_node("t1", "Transition", [], []) + prompt + \
-                read_edge("p2t", "P2T", "p1", "t1", [], [("weight", "Natural", 2)]) + prompt + \
-                read_edge("t2p", "T2P", "t1", "p2", [], [("weight", "Natural", 1)]) + prompt,
-            mode))
-
-    def test_po_pn_interface_verify_OK(self):
-        self.pn_interface_verify_OK("PO")
-
-    def test_co_pn_interface_verify_OK(self):
-        self.pn_interface_verify_OK("CO")
-
-    def pn_interface_verify_OK(self, mode):
-        self.assertTrue(run_file(all_files,
-            do_instantiate_simple + ["verify"],
-            did_instantiate_simple + ["OK"], mode))
-
-    def test_po_pn_interface_verify_fail_tokens(self):
-        self.pn_interface_verify_fail_tokens("PO")
-
-    def test_co_pn_interface_verify_fail_tokens(self):
-        self.pn_interface_verify_fail_tokens("CO")
-
-    def pn_interface_verify_fail_tokens(self, mode):
-        self.assertTrue(run_file(all_files,
-            do_instantiate_simple + ["modify", "p1", "tokens", -5, "verify"],
-            did_instantiate_simple + modify + prompt + verify_fail_tokens + prompt, mode))
-
-    def test_po_pn_interface_verify_fail_weight(self):
-        self.pn_interface_verify_fail_weight("PO")
-
-    def test_co_pn_interface_verify_fail_weight(self):
-        self.pn_interface_verify_fail_weight("CO")
-
-    def pn_interface_verify_fail_weight(self, mode):
-        self.assertTrue(run_file(all_files,
-            do_instantiate_simple + ["modify", "p2t", "weight", -2, "verify"],
-            did_instantiate_simple + modify + prompt + verify_fail_weight + prompt, mode))
-
-    def test_po_pn_interface_verify_fail_structure(self):
-        self.pn_interface_verify_fail_structure("PO")
-
-    def test_co_pn_interface_verify_fail_structure(self):
-        self.pn_interface_verify_fail_structure("CO")
-
-    def pn_interface_verify_fail_structure(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc",
-            "instantiate", "Transition", "t1",
-            "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
-            "instantiate", "P2T", "p2t", "t1", "p1", "attr_add", "p2t", "weight", 2, "verify"],
-            init + new + loaded + \
-                instantiate_node + prompt + \
-                instantiate_node + prompt + attr_add + prompt + \
-                instantiate_edge + prompt + attr_add + prompt + \
-                verify_fail_structure,
-            mode))
-
-    def test_po_pn_interface_types(self):
-        self.pn_interface_types("PO")
-
-    def test_co_pn_interface_types(self):
-        self.pn_interface_types("CO")
-
-    def pn_interface_types(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "types"],
-            init + new + loaded + list_types([("Place", "Class"),
-                                              ("Transition", "Class"),
-                                              ("P2T", "Association"),
-                                              ("T2P", "Association"),
-                                              ("Natural", "Class"),
-                                              ("Place_tokens", "Association"),
-                                              ("Place_tokens.name", "String"),
-                                              ("Place_tokens.target_lower_cardinality", "Natural"),
-                                              ("Place_tokens.target_upper_cardinality", "Natural"),
-                                              ("P2T_weight", "Association"),
-                                              ("P2T_weight.name", "String"),
-                                              ("P2T_weight.target_lower_cardinality", "Natural"),
-                                              ("P2T_weight.target_upper_cardinality", "Natural"),
-                                              ("T2P_weight", "Association"),
-                                              ("T2P_weight.name", "String"),
-                                              ("T2P_weight.target_lower_cardinality", "Natural"),
-                                              ("T2P_weight.target_upper_cardinality", "Natural"),
-                    ]) + prompt,
-            mode))
-
-    def test_po_pn_interface_modify_place(self):
-        self.pn_interface_modify_place("PO")
-
-    def test_co_pn_interface_modify_place(self):
-        self.pn_interface_modify_place("CO")
-
-    def pn_interface_modify_place(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc",
-                "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
-                "read", "p1",
-                "modify", "p1", "tokens", 1, "read", "p1"],
-            init + new + loaded + \
-                instantiate_node + prompt + attr_add + prompt + \
-                read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
-                modify + prompt + \
-                read_node("p1", "Place", [], [("tokens", "Natural", 1)]) + prompt,
-            mode))
-
-    def test_po_pn_interface_verify_fail_attr_lower_cardinality(self):
-        self.pn_interface_verify_fail_attr_lower_cardinality("PO")
-
-    def test_co_pn_interface_verify_fail_attr_lower_cardinality(self):
-        self.pn_interface_verify_fail_attr_lower_cardinality("CO")
-
-    def pn_interface_verify_fail_attr_lower_cardinality(self, mode):
-        self.assertTrue(run_file(all_files,
-            do_instantiate_simple + ["instantiate", "Place", "p999", "verify"],
-            did_instantiate_simple + instantiate_node + prompt + ["Lower cardinality violation for outgoing edge of type Place_tokens at p999"] + prompt,
-            mode))
-
-    def test_po_pn_interface_verify_fail_attr_upper_cardinality(self):
-        self.pn_interface_verify_fail_attr_upper_cardinality("PO")
-
-    def test_co_pn_interface_verify_fail_attr_upper_cardinality(self):
-        self.pn_interface_verify_fail_attr_upper_cardinality("CO")
-
-    def pn_interface_verify_fail_attr_upper_cardinality(self, mode):
-        self.assertTrue(run_file(all_files,
-            do_instantiate_simple + ["attr_add", "p1", "tokens", 5, "verify"],
-            did_instantiate_simple + attr_add + prompt + ["Upper cardinality violation for outgoing edge of type Place_tokens at p1"] + prompt,
-            mode))
-
-    def test_po_pn_interface_verify_natural(self):
-        self.pn_interface_verify_natural("PO")
-
-    def test_co_pn_interface_verify_natural(self):
-        self.pn_interface_verify_natural("CO")
-
-    def pn_interface_verify_natural(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc",
-            "instantiate", "Place", "p1",
-            "attr_add", "p1", "tokens", -5,
-            "attr_del", "p1", "tokens",
-            "attr_add", "p1", "tokens", 4,
-            "verify"],
-            init + new + loaded + \
-            instantiate_node + prompt + \
-            attr_add + prompt + \
-            attr_del + prompt + \
-            attr_add + prompt + \
-            ["OK"] + prompt,
-            mode))
-
-    def test_po_pn_interface_verify_PN_OK(self):
-        self.pn_interface_verify_PN_OK("PO")
-
-    def test_co_pn_interface_verify_PN_OK(self):
-        self.pn_interface_verify_PN_OK("CO")
-
-    def pn_interface_verify_PN_OK(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["load", "PetriNets", "verify"],
-            init + load + loaded + ["OK"], mode))
-
-    def test_po_rpgame(self):
-        self.rpgame("PO")
-
-    def test_co_rpgame(self):
-        self.rpgame("CO")
-
-    def rpgame(self, mode):
-
-        constraint_code = \
-            """
-include "primitives.alh"
-include "object_operations.alh"
-
-Element function constraint(model : Element, name : String):
-	Element associations
-	Element back_associations
-	Element association
-	String destination
-	associations = allOutgoingAssociationInstances(model, name, "tile_left")
-	while (0 < list_len(associations)):
-		association = set_pop(associations)
-		destination = readAssociationDestination(model, association)
-		back_associations = allOutgoingAssociationInstances(model, destination, "tile_right")
-		if (list_len(back_associations) < 1):
-			return "Left link does not have a right link back"!
-		else:
-			association = set_pop(back_associations)
-			destination = readAssociationDestination(model, association)
-			if (destination != name):
-				return "Right link does not have a left link back to the same tile"!
-	associations = allOutgoingAssociationInstances(model, name, "tile_right")
-	while (0 < list_len(associations)):
-		association = set_pop(associations)
-		destination = readAssociationDestination(model, association)
-		back_associations = allOutgoingAssociationInstances(model, destination, "tile_left")
-		if (list_len(back_associations) < 1):
-			return "Right link does not have a left link back"!
-		else:
-			association = set_pop(back_associations)
-			destination = readAssociationDestination(model, association)
-			if (destination != name):
-				return "Right link does not have a left link back to the same tile"!
-	associations = allOutgoingAssociationInstances(model, name, "tile_top")
-	while (0 < list_len(associations)):
-		association = set_pop(associations)
-		destination = readAssociationDestination(model, association)
-		back_associations = allOutgoingAssociationInstances(model, destination, "tile_bottom")
-		if (list_len(back_associations) < 1):
-			return "Top link does not have a bottom link back"!
-		else:
-			association = set_pop(back_associations)
-			destination = readAssociationDestination(model, association)
-			if (destination != name):
-				return "Top link does not have a bottom link back to the same tile"!
-	associations = allOutgoingAssociationInstances(model, name, "tile_bottom")
-	while (0 < list_len(associations)):
-		association = set_pop(associations)
-		destination = readAssociationDestination(model, association)
-		back_associations = allOutgoingAssociationInstances(model, destination, "tile_top")
-		if (list_len(back_associations) < 1):
-			return "Bottom link does not have a top link back"!
-		else:
-			association = set_pop(back_associations)
-			destination = readAssociationDestination(model, association)
-			if (destination != name):
-				return "Bottom link does not have a top link back to the same tile"!
-	return "OK"!
-            """
-
-        constructors = get_constructor(constraint_code)
-
-        self.assertTrue(run_file(all_files,
-            ["new", "SimpleClassDiagrams", "RPGame",
-                "set_inheritance", "Inheritance",
-                "instantiate", "Class", "Scene",
-                "instantiate", "Class", "Tile",
-                "instantiate", "Class", "Item",
-                "instantiate", "Class", "Goal",
-                "instantiate", "Class", "Character",
-                "instantiate", "Class", "Hero",
-                "instantiate", "Association", "scene_has_tiles", "Scene", "Tile",
-                "instantiate", "Association", "tile_left", "Tile", "Tile",
-                "instantiate", "Association", "tile_right", "Tile", "Tile",
-                "instantiate", "Association", "tile_top", "Tile", "Tile",
-                "instantiate", "Association", "tile_bottom", "Tile", "Tile",
-                "instantiate", "Association", "character_on", "Character", "Tile",
-                "instantiate", "Association", "item_on", "Item", "Tile",
-                "instantiate", "Inheritance", "hero_is_character", "Hero", "Character",
-                "instantiate", "Inheritance", "goal_is_item", "Goal", "Item",
-                "attr_add", "Scene", "lower_cardinality", 1,
-                "attr_add", "Scene", "upper_cardinality", 1,
-                "attr_add", "Goal", "lower_cardinality", 1,
-                "attr_add", "scene_has_tiles", "source_lower_cardinality", 1,
-                "attr_add", "scene_has_tiles", "source_upper_cardinality", 1,
-                "attr_add", "scene_has_tiles", "target_lower_cardinality", 1,
-                "attr_add", "item_on", "target_lower_cardinality", 1,
-                "attr_add", "item_on", "target_upper_cardinality", 1,
-                "attr_add", "item_on", "source_upper_cardinality", 1,
-                "attr_add", "character_on", "target_lower_cardinality", 1,
-                "attr_add", "character_on", "target_upper_cardinality", 1,
-                "attr_add", "character_on", "source_upper_cardinality", 1,
-                "attr_add", "tile_left", "source_upper_cardinality", 1,
-                "attr_add", "tile_left", "target_upper_cardinality", 1,
-                "attr_add", "tile_right", "source_upper_cardinality", 1,
-                "attr_add", "tile_right", "target_upper_cardinality", 1,
-                "attr_add", "tile_top", "source_upper_cardinality", 1,
-                "attr_add", "tile_top", "target_upper_cardinality", 1,
-                "attr_add", "tile_bottom", "source_upper_cardinality", 1,
-                "attr_add", "tile_bottom", "target_upper_cardinality", 1,
-                "attr_add_code", "Tile", "constraint",
-            ] + constructors + ["verify"] + ["exit"] + [
-                "new", "RPGame", "my_game",
-                "instantiate", "Scene", "scene",
-                "instantiate", "Hero", "Link",
-                "instantiate", "Goal", "goal",
-                "instantiate", "Tile", "tile_00",
-                "instantiate", "Tile", "tile_01",
-                "instantiate", "Tile", "tile_10",
-                "instantiate", "Tile", "tile_11",
-                "instantiate", "scene_has_tiles", "", "scene", "tile_00",
-                "instantiate", "scene_has_tiles", "", "scene", "tile_01",
-                "instantiate", "scene_has_tiles", "", "scene", "tile_10",
-                "instantiate", "scene_has_tiles", "", "scene", "tile_11",
-                "instantiate", "character_on", "",  "Link", "tile_00",
-                "instantiate", "item_on", "", "goal", "tile_11",
-                "instantiate", "tile_left", "", "tile_01", "tile_00",
-                "instantiate", "tile_left", "", "tile_11", "tile_10",
-                "instantiate", "tile_right", "", "tile_00", "tile_01",
-                "instantiate", "tile_right", "", "tile_10", "tile_11",
-                "instantiate", "tile_top", "", "tile_10", "tile_00",
-                "instantiate", "tile_top", "", "tile_11", "tile_01",
-                "instantiate", "tile_bottom", "", "tile_00", "tile_10",
-                "instantiate", "tile_bottom", "", "tile_01", "tile_11",
-                "verify",
-            ],
-            init + new + loaded + \
-                set_inheritance + prompt + \
-                (instantiate_node + prompt) * 6 + \
-                (instantiate_edge + prompt) * 9 + \
-                (attr_add + prompt) * 20 + \
-                ["Which model do you want to assign a coded attribute to?",
-                 "Which attribute do you wish to assign?",
-                 "Constructors for code?",
-                 "Added code!"] + \
-                prompt + \
-                ["OK"] + \
-                prompt + prompt + new + loaded + \
-                (instantiate_node + prompt) * 7 + \
-                (instantiate_edge + prompt) * 14 + \
-                ["OK"],
-            mode))
-
-    def test_po_pn_interface_model_transform_pn(self):
-        PN_runtime = open("integration/code/pn_runtime.mvc", "r").read()
-        PN_model = open("integration/code/pn_runtime_model.mvc", "r").read()
-        schedule_model = open("integration/code/pn_simulate.mvc", "r").read()
-
-        self.assertTrue(run_file(all_files,
-            get_model_constructor(PN_runtime) + [
-                ] + get_model_constructor(PN_model) + [
-                "load", "pn", 
-                    "read", "t1",
-                    "read", "p1",
-                    "read", "p2",
-                    "read", "p3",
-                    "exit",
-                "ramify", "RAM_PetriNets_Runtime", "PetriNets_Runtime",
-                ] + get_model_constructor(schedule_model) + [
-                "transform", "pn", "pn_simulate",
-                "transform", "pn", "pn_simulate",
-                "load", "pn",
-                    "verify",
-                    "read", "t1",
-                    "read", "p1",
-                    "read", "p2",
-                    "read", "p3",
-                    "exit",
-            ],
-          greeting + prompt * 3 +
-            load + loaded +
-            read_node("t1", "Transition", [], [("executing", "Boolean", False)]) + prompt +
-            read_node("p1", "Place", [], [("tokens", "Natural", 1), ("name", "String", '"p1"')]) + prompt +
-            read_node("p2", "Place", [], [("tokens", "Natural", 2), ("name", "String", '"p2"')]) + prompt +
-            read_node("p3", "Place", [], [("tokens", "Natural", 3), ("name", "String", '"p3"')]) + prompt +
-            prompt +
-            ramify + prompt + 
-            prompt +
-            transform + transform_result_true + prompt +
-            transform + transform_result_false + prompt +
-            load + loaded +
-            ["OK"] + prompt +
-            read_node("t1", "Transition", [], [("executing", "Boolean", False)]) + prompt +
-            read_node("p1", "Place", [], [("tokens", "Natural", 0), ("name", "String", '"p1"')]) + prompt +
-            read_node("p2", "Place", [], [("tokens", "Natural", 1), ("name", "String", '"p2"')]) + prompt +
-            read_node("p3", "Place", [], [("tokens", "Natural", 5), ("name", "String", '"p3"')]) + prompt, 
-          "PO"))
-
-    def test_po_pn_interface_transform_pn_to_runtime(self):
-        PN_runtime = open("integration/code/pn_runtime.mvc", "r").read()
-        PN_design = open("integration/code/pn_design.mvc", "r").read()
-        PN_model = open("integration/code/pn_design_model.mvc", "r").read()
-        schedule_model_design_to_runtime = open("integration/code/pn_design_to_runtime.mvc", "r").read()
-        schedule_model_print = open("integration/code/pn_print.mvc", "r").read()
-        schedule_model_simulate = open("integration/code/pn_simulate.mvc", "r").read()
-
-        self.assertTrue(run_file(all_files,
-            get_model_constructor(PN_runtime) + \
-                get_model_constructor(PN_design) + \
-                get_model_constructor(PN_model) + [
-                "unify", "PetriNets_Design_to_Runtime", "PetriNets_Design", "SOURCE_", "PetriNets_Runtime", "TARGET_",
-                "join", "pn", "PetriNets_Design_to_Runtime", "SOURCE_",
-                "load", "PetriNets_Design_to_Runtime",
-                    "instantiate", "Association", "PlaceLink", "SOURCE_Place", "TARGET_Place",
-                    "instantiate", "Association", "TransitionLink", "SOURCE_Transition", "TARGET_Transition",
-                    "exit",
-                "ramify", "RAM_PetriNets_Design_Runtime", "PetriNets_Design_to_Runtime",
-                "ramify", "RAM_PetriNets_Runtime", "PetriNets_Runtime",
-                ] + get_model_constructor(schedule_model_design_to_runtime) + [
-                ] + get_model_constructor(schedule_model_print) + [
-                ] + get_model_constructor(schedule_model_simulate) + [
-                "transform", "pn", "pn_annotate",
-                "split", "pn", "PetriNets_Runtime", "TARGET_",
-                "transform", "pn", "pn_print",
-                "transform", "pn", "pn_simulate",
-                "transform", "pn", "pn_print",
-            ],
-          greeting + prompt * 4 +
-            unify + prompt +
-            join + prompt +
-            load + loaded +
-            instantiate_edge + prompt +
-            instantiate_edge + prompt +
-            prompt +
-            ramify + prompt +
-            ramify + prompt + 
-            prompt +
-            prompt +
-            prompt +
-            transform + transform_result_true + prompt +
-            split + prompt +
-            transform + [set(['"p1" --> 1', '"p2" --> 2', '"p3" --> 3'])] + transform_result_true + prompt +
-            transform + transform_result_true + prompt +
-            transform + [set(['"p1" --> 0', '"p2" --> 1', '"p3" --> 5'])] + transform_result_true + prompt
-            , 
-          "PO"))

+ 15 - 5
integration/utils.py

@@ -91,10 +91,13 @@ def compile_file(address, mod_filename, filename, mode, proc):
         except UnboundLocalError:
             pass
 
-def run_file(files, parameters, expected, mode):
+def run_file(files, parameters, expected, mode, wait=False):
     # Resolve file
     import os.path
 
+    if wait is True:
+        expected = None
+
     time.sleep(0.01)
     port = getFreePort()
     address = "http://127.0.0.1:%i" % port
@@ -105,7 +108,9 @@ def run_file(files, parameters, expected, mode):
         threads = []
         mod_files = []
         for filename in files:
-            if os.path.isfile("integration/code/%s" % filename):
+            if os.path.isfile(filename):
+                mod_filename = filename
+            elif os.path.isfile("integration/code/%s" % filename):
                 mod_filename = "integration/code/%s" % filename
             elif os.path.isfile("bootstrap/%s" % filename):
                 mod_filename = "bootstrap/%s" % filename
@@ -116,12 +121,17 @@ def run_file(files, parameters, expected, mode):
         to_compile = to_recompile(address, mod_files)
 
         for mod_filename in to_compile:
+            if mod_filename.endswith(".mvc"):
+                model_mode = "MO"
+                mod_files.remove(mod_filename)
+            else:
+                model_mode = mode
             if parallel_push:
                 import threading
-                threads.append(threading.Thread(target=compile_file, args=[address, mod_filename, mod_filename, mode, proc]))
+                threads.append(threading.Thread(target=compile_file, args=[address, mod_filename, mod_filename, model_mode, proc]))
                 threads[-1].start()
             else:
-                compile_file(address, mod_filename, mod_filename, mode, proc)
+                compile_file(address, mod_filename, mod_filename, model_mode, proc)
 
         if parallel_push:
             for t in threads:
@@ -283,6 +293,6 @@ def get_model_constructor(code):
         f.write(code)
         f.flush()
 
-    constructors = ["upload"] + do_compile("__model.mvc", "interface/HUTN/grammars/modelling.g", "M") + ["exit"]
+    constructors = do_compile("__model.mvc", "interface/HUTN/grammars/modelling.g", "M") + ["exit"]
 
     return constructors

+ 1 - 1
interface/HUTN/grammars/modelling.g

@@ -29,7 +29,7 @@ grammar{
     tokens{
         IMPORT: 'import';
         AS: 'as';
-        MODEL_ID: '[a-zA-Z_][a-zA-Z_0-9]*';
+        MODEL_ID: '[a-zA-Z_][a-zA-Z_0-9/]*';
         MV_URL: '[a-zA-Z_0-9/]*';
         LCURLY: '{';
         RCURLY: '}';

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

@@ -487,6 +487,7 @@ class SemanticsVisitor(Visitor):
     # there is no such rule in the grammar, we just avoid code duplicates
     def visit_id(self, tree):
         name = tree.get_text()
+        #TODO this is set to the function returnvalue, even if we use the function pointer...
         try:
             symbol = self.symbol_table.get(name)
         except KeyError:

+ 3 - 1
interface/HUTN/includes/model_management.alh

@@ -1,3 +1,5 @@
-Element function model_fuse(name1 : String, model1 : Element, name2 : String, model2 : Element)
+Element function model_fuse(models : Element)
 Element function model_copy(model : Element)
 Element function model_retype_on_name(model : Element, new_MM : Element, operation : String, name : String)
+Void function model_join(target_model : Element, source_model : Element, retyping_key : String)
+Element function model_split(source_model : Element, target_metamodel : Element, retyping_key : String)

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

@@ -21,3 +21,4 @@ Element function read_attribute(model : Element, elem : String, name : String)
 Void function model_delete_element(model : Element, name : String)
 Void function add_constraint(model : Element, name : String, constraint : Action)
 String function model_define_attribute(model : Element, elem : String, name : String, type : String)
+Element function construct_model_raw(metamodel : Element)

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

@@ -12,3 +12,4 @@ String function readAssociationDestination(model : Element, name : String)
 String function followAssociation(model : Element, element_name : String, association_name : String)
 Element function allAssociationDestinations(model : Element, name : String, association_type : String)
 Element function allowedAssociationsBetween(model : Element, src : String, dst : String)
+String function read_type(model : Element, name : String)

+ 2 - 0
interface/HUTN/includes/primitives.alh

@@ -91,6 +91,7 @@ Boolean function is_physical_action(a : Element)
 Boolean function is_physical_boolean(a : Element)
 Boolean function has_value(a : Element)
 Float function time()
+String function hash(a : String)
 
 Element function exec(a : Element)
 Element function resolve(var_name : String)
@@ -101,6 +102,7 @@ String function set_to_string(set : Element)
 String function list_to_string(set : Element)
 String function dict_to_string(dict : Element)
 Element function set_overlap(sa : Element, sb : Element)
+Element function set_equality(sa : Element, sb : Element)
 Element function dict_copy(dict : Element)
 Element function set_to_list(s : Element)
 Element function create_tuple(a : Element, b : Element)

+ 3 - 1
kernel/modelverse_kernel/compiled.py

@@ -327,6 +327,8 @@ def get_superclasses(a, b, **remainder):
                     src, dst = srcdst
                     # Find elem in elems
                     worklist.append(dst)
+                    if dst is None:
+                        print("Read edge gives error for edge: " + str(elem))
 
     raise PrimitiveFinished(result)
 
@@ -403,7 +405,7 @@ def check_symbols(a, b, c, **remainder):
             k = key
             v = value
             if v and symbols.get(k, False):
-                result = yield [("CNV", ["ERROR: multiple definition of symbol " + str(key)])]
+                result, = yield [("CNV", ["ERROR: multiple definition of symbol " + str(key)])]
                 raise PrimitiveFinished(result)
             elif v and not symbols.get(k, False):
                 symbols[k] = True

+ 13 - 9
kernel/modelverse_kernel/legacy.py

@@ -569,15 +569,19 @@ class ModelverseKernel(object):
             self.debug_info[self.username].pop()
         user_frame, =       yield [("RD", [user_root, "frame"])]
         prev_frame, =       yield [("RD", [user_frame, "prev"])]
-        returnvalue, old_returnvalue_link = \
-                            yield [("RD", [user_frame, "returnvalue"]),
-                                   ("RDE", [prev_frame, "returnvalue"]),
-                                  ]
-        _, _, _, _ =        yield [("CD", [user_root, "frame", prev_frame]),
-                                   ("CD", [prev_frame, "returnvalue", returnvalue]),
-                                   ("DE", [old_returnvalue_link]),
-                                   ("DN", [user_frame]),
-                                  ]
+        if prev_frame is None:
+            _, =            yield [("DN", [user_root])]
+            del self.debug_info[self.username]
+        else:
+            returnvalue, old_returnvalue_link = \
+                                yield [("RD", [user_frame, "returnvalue"]),
+                                       ("RDE", [prev_frame, "returnvalue"]),
+                                      ]
+            _, _, _, _ =        yield [("CD", [user_root, "frame", prev_frame]),
+                                       ("CD", [prev_frame, "returnvalue", returnvalue]),
+                                       ("DE", [old_returnvalue_link]),
+                                       ("DN", [user_frame]),
+                                      ]
 
     def constant_init(self, user_root):
         user_frame, =       yield [("RD", [user_root, "frame"])]

+ 31 - 22
kernel/modelverse_kernel/main.py

@@ -84,18 +84,22 @@ class ModelverseKernel(object):
         self.debug_info = defaultdict(list)
 
     def execute_yields(self, username, operation, params, reply):
-        self.success = True
-        self.username = username
-        if username not in self.request_handlers:
-            self.request_handlers[username] = {}
-        if operation not in self.request_handlers[username]:
-            # Create the generator for the function to execute
-            self.request_handlers[username][operation] = RequestHandler()
-        handler = self.request_handlers[username][operation]
-        if not handler.is_active():
-            handler.push_generator(getattr(self, operation)(username, *params))
-
-        return handler.handle_request(reply)
+        try:
+            self.success = True
+            self.username = username
+            if username not in self.request_handlers:
+                self.request_handlers[username] = {}
+            if operation not in self.request_handlers[username]:
+                # Create the generator for the function to execute
+                self.request_handlers[username][operation] = RequestHandler()
+            handler = self.request_handlers[username][operation]
+            if not handler.is_active():
+                handler.push_generator(getattr(self, operation)(username, *params))
+
+            return handler.handle_request(reply)
+        except:
+            print("Unknown error @ " + str(self.debug_info.get(username, "Username unknown")))
+            raise
 
     def execute_rule(self, username):
         user_root, =    yield [("RD", [self.root, username])]
@@ -138,15 +142,15 @@ class ModelverseKernel(object):
             else:
                 raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info[username], inst_v, self.phase_v))
 
-        def handle_jit_failed(exception):
-            # Try again, but this time without the JIT.
-            gen = self.get_inst_phase_generator(inst_v, self.phase_v, user_root)
-            yield [("TAIL_CALL", [gen])]
+            def handle_jit_failed(exception):
+                # Try again, but this time without the JIT.
+                gen = self.get_inst_phase_generator(inst_v, self.phase_v, user_root)
+                yield [("TAIL_CALL", [gen])]
 
-        yield [("TRY", [])]
-        yield [("CATCH", [jit.JitCompilationFailedException, handle_jit_failed])]
-        yield [("CALL", [gen])]
-        yield [("END_TRY", [])]
+            yield [("TRY", [])]
+            yield [("CATCH", [jit.JitCompilationFailedException, handle_jit_failed])]
+            yield [("CALL", [gen])]
+            yield [("END_TRY", [])]
 
     def get_inst_phase_generator(self, inst_v, phase_v, user_root):
         """Gets a generator for the given instruction in the given phase,
@@ -633,9 +637,11 @@ class ModelverseKernel(object):
             # gives us O(1) state reads per jit-interpreter transition.
             exception_return, = yield [("RD", [user_frame, primitive_functions.EXCEPTION_RETURN_KEY])]
             if prev_frame is None:
+                print("Frame empty; delete user " + str(self.username))
                 _, =            yield [("DN", [user_root])]
                 del self.debug_info[self.username]
             else:
+                print("Previous frame found")
                 if self.debug_info[self.username]:
                     self.debug_info[self.username].pop()
                 _, _ =          yield [("CD", [user_root, "frame", prev_frame]),
@@ -667,8 +673,11 @@ class ModelverseKernel(object):
             self.debug_info[self.username].pop()
 
         user_frame, = yield [("RD", [user_root, "frame"])]
-        prev_frame, exception_return, returnvalue = yield [
-            ("RD", [user_frame, "prev"]),
+        prev_frame, = yield [("RD", [user_frame, "prev"])]
+        if prev_frame is None:
+            _, =            yield [("DN", [user_root])]
+            del self.debug_info[self.username]
+        exception_return, returnvalue = yield [
             ("RD", [user_frame, primitive_functions.EXCEPTION_RETURN_KEY]),
             ("RD", [user_frame, "returnvalue"])]
 

+ 7 - 0
kernel/modelverse_kernel/primitives.py

@@ -566,3 +566,10 @@ def time(**remainder):
     import time
     a, = yield [("CNV", [time.time()])]
     raise PrimitiveFinished(a)
+
+def hash(a, **remainder):
+    a_value, = yield [("RV", [a])]
+    import hashlib
+    b_value = hashlib.sha512(a_value).hexdigest()
+    b, = yield [("CNV", [b_value])]
+    raise PrimitiveFinished(b)

+ 16 - 10
scripts/compile.py

@@ -4,17 +4,23 @@ import urllib2
 import urllib
 import subprocess
 
-def do_compile(address, filename, username, modulename, mode, optionals=['--debug'], grammar="grammars/actionlanguage.g"):
+def do_compile(address, filename, username, modulename, mode, optionals=['--debug'], grammar=""):
     filename = os.path.realpath(filename)
-    try:
-        urllib2.urlopen(urllib2.Request(address, 'op=set_input&username=user_manager&value="%s"' % username)).read()
-        subprocess.check_call([sys.executable, "hutn_compiler/compiler.py", filename, grammar, mode, username, modulename, filename, address] + optionals, cwd="interface/HUTN")
-    except urllib2.URLError:
-        return 2
-    except:
-        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '-1', "username": username}))).read()
-        return 1
-    urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '-1', "username": username}))).read()
+    if grammar == "":
+        if mode[0] == "M":
+            # Load model grammar
+            grammar = "grammars/modelling.g"
+        else:
+            # Load AL grammar
+            grammar = "grammars/actionlanguage.g"
+    while 1:
+        try:
+            # Create new user
+            urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % username, "username": "user_manager"}))).read()
+            subprocess.check_call([sys.executable, "hutn_compiler/compiler.py", filename, grammar, mode, username, modulename, filename, address] + optionals, cwd="interface/HUTN")
+            break
+        except:
+            time.sleep(0.01)
     return 0
 
 if __name__ == "__main__":

+ 12 - 2
scripts/execute_model.py

@@ -1,6 +1,8 @@
 import random
 import sys
 import multiprocessing
+import glob
+import time
 
 from compile import do_compile
 from link_and_load import link_and_load
@@ -11,8 +13,9 @@ code = []
 
 address = sys.argv[1]
 username = sys.argv[2]
+files = [a.replace("\\", "/") for a in sum([glob.glob(f) for f in sys.argv[3:]], [])]
 
-for f in sys.argv[3:]:
+for f in files:
     if f.endswith(".mvc"):
         models.append(f)
     elif f.endswith(".alc"):
@@ -26,7 +29,14 @@ def initialize_SCD():
     import urllib
     import json
     username = random.random()
-    urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % username, "username": "user_manager"}))).read()
+
+    while 1:
+        try:
+            # Create new user
+            urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % username, "username": "user_manager"}))).read()
+            break
+        except:
+            time.sleep(0.01)
 
     data = []
     data.append(4)

+ 9 - 12
scripts/prompt.py

@@ -28,18 +28,15 @@ def remote_print(string):
     print(string)
 
 local_print("Welcome to the local shell!")
-local_print("Please specify Modelverse location (default: 127.0.0.1:8001)")
-
-location = raw_input()
-if location == "":
-    address = "http://127.0.0.1:8001/"
-
-local_print("Username (default: test)")
-username = raw_input()
-if username == "":
-    username = "test"
-else:
-    username = username.strip()
+try:
+    address = sys.argv[1]
+except IndexError:
+    address = "http://127.0.0.1:8001"
+try:
+    username = sys.argv[2]
+except IndexError:
+    import random
+    username = str(random.random())
 
 # If user doesn't exist yet, we create it
 urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % username, "username": "user_manager"}))).read()

+ 42 - 0
scripts/run_MvC_server.py

@@ -0,0 +1,42 @@
+import subprocess
+import sys
+import threading
+import time
+import random
+import urllib
+import urllib2
+
+MVK_PORT = 8001
+MVK_ADDRESS = "http://localhost"
+ADMIN_USER = "admin"
+ADMIN_PASSWORD = "admin"
+SETUP_USER = "setup_user"
+
+address = "%s:%s" % (MVK_ADDRESS, MVK_PORT)
+
+# Compile the Statechart first
+subprocess.check_call([sys.executable, "-m", "sccd.compiler.sccdc", "-p", "threads", "server.xml"], cwd="hybrid_server")
+
+# 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")
+
+    # Compile all MvC code
+    subprocess.call([sys.executable, "scripts/execute_model.py", address, SETUP_USER, "bootstrap/*.alc", "core/*.alc", "core/*.mvc"])
+
+    # Set the admin username and password
+    urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % ADMIN_USER, "username": SETUP_USER}))).read()
+    urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % ADMIN_PASSWORD, "username": SETUP_USER}))).read()
+    urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % ADMIN_PASSWORD, "username": SETUP_USER}))).read()
+    urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"exit"', "username": SETUP_USER}))).read()
+
+    while 1:
+        time.sleep(1)
+finally:
+    try:
+        obj.terminate()
+        time.sleep(1)
+        if not obj.poll():
+            obj.kill()
+    except:
+        pass

+ 4 - 0
scripts/test_compile.py

@@ -0,0 +1,4 @@
+import sys
+sys.path.append("interface/HUTN/")
+from hutn_compiler.compiler import main as compile_code
+compile_code(sys.argv[1], "interface/HUTN/grammars/actionlanguage.g", "PS", ["--debug"])

+ 0 - 5
state/modelverse_state/main.py

@@ -162,11 +162,6 @@ class ModelverseState(object):
             return (None, status.FAIL_CDICT_TARGET)
         if not self.is_valid_datavalue(data):
             return (None, status.FAIL_CDICT_OOB)
-        if (type(data) == float and data == 0.0):
-            print("Got dictionary with value 0.0")
-            print(locals())
-            print(self.values.get(destination, destination))
-            raise Exception()
         n = self.create_nodevalue(data)[0]
         e = self.create_edge(source, destination)[0]
         self.create_edge(e, n)