浏览代码

Fixed problem with loading in the core model only, and not its typing
and MM

Yentl Van Tendeloo 8 年之前
父节点
当前提交
82e1f73418
共有 3 个文件被更改,包括 109 次插入103 次删除
  1. 98 98
      bootstrap/ramify.alc
  2. 9 3
      core/core_algorithm.alc
  3. 2 2
      scripts/run_MvC_server.py

+ 98 - 98
bootstrap/ramify.alc

@@ -24,27 +24,24 @@ Element function ramify(model : Element):
 	mm = new_model["metamodel"]["model"]
 
 	// Add in some primitives
-	instantiate_node(new_model, "Class", "Natural")
-	instantiate_node(new_model, "Class", "String")
-	instantiate_node(new_model, "Class", "Any")
+	instantiate_node(new_model, "AttributeValue", "Natural")
+	instantiate_node(new_model, "AttributeValue", "String")
+	instantiate_node(new_model, "AttributeValue", "Boolean")
+	instantiate_node(new_model, "AttributeValue", "Element")
 
 	// Add in the complete AL metamodel
 	add_AL_to_MM(new_model)
 
 	// Add some default elements
 	//	Class LHS_Root {
-	//		constraint : funcdef {
-	//			target_upper_cardinality = 1
-	//		}
+	//		constraint? : funcdef
 	//		upper_cardinality = 1
 	//		lower_cardinality = 1
 	//	}
 	instantiate_node(new_model, "Class", "LHS_Root")
 	instantiate_attribute(new_model, "LHS_Root", "lower_cardinality", 1)
 	instantiate_attribute(new_model, "LHS_Root", "upper_cardinality", 1)
-	instantiate_link(new_model, "Association", "LHS_constraint", "LHS_Root", "funcdef")
-	instantiate_attribute(new_model, "LHS_constraint", "name", "constraint")
-	instantiate_attribute(new_model, "LHS_constraint", "target_upper_cardinality", 1)
+	model_define_attribute(new_model, "LHS_Root", "LHS_constraint", True, "funcdef")
 
 	//  Class LHS : LHS_Root {}
 	instantiate_node(new_model, "Class", "LHS")
@@ -54,69 +51,37 @@ Element function ramify(model : Element):
 	instantiate_node(new_model, "Class", "NAC")
 	instantiate_link(new_model, "Inheritance", "", "NAC", "LHS_Root")
 
-	//	Class Pre_Element {
-	//		label : String {
-	//			target_lower_cardinality = 1
-	//			target_upper_cardinality = 1
-	//		}
-	//		constraint : funcdef {
-	//			target_upper_cardinality = 1
-	//		}
+	//	Class PreElement {
+	//		label : String
+	//		constraint? : funcdef
 	//	}
-	instantiate_node(new_model, "Class", "Pre_Element")
-	instantiate_link(new_model, "Association", "Pre_Element_label", "Pre_Element", "String")
-	instantiate_attribute(new_model, "Pre_Element_label", "name", "label")
-	instantiate_attribute(new_model, "Pre_Element_label", "target_lower_cardinality", 1)
-	instantiate_attribute(new_model, "Pre_Element_label", "target_upper_cardinality", 1)
-	instantiate_link(new_model, "Association", "Pre_Element_constraint", "Pre_Element", "funcdef")
-	instantiate_attribute(new_model, "Pre_Element_constraint", "name", "constraint")
-	instantiate_attribute(new_model, "Pre_Element_constraint", "target_upper_cardinality", 1)
-
-	// Association LHS_contains (LHS_Root, Pre_Element) {}
-	instantiate_link(new_model, "Association", "LHS_contains", "LHS_Root", "Pre_Element")
-	instantiate_attribute(new_model, "LHS_contains", "name", "contains")
+	instantiate_node(new_model, "Class", "PreElement")
+	model_define_attribute(new_model, "PreElement", "label", False, "String")
+	model_define_attribute(new_model, "PreElement", "matching_constraint", True, "funcdef")
+
+	// Association LHS_contains (LHS_Root, PreElement) {}
+	instantiate_link(new_model, "Association", "LHS_contains", "LHS_Root", "PreElement")
 
 	//	Class RHS {
-	//		action : FuncDef {
-	//			target_upper_cardinality = 1
-	//		}
+	//		action? : FuncDef
 	//		upper_cardinality = 1
 	//		lower_cardinality = 1
 	//	}
 	instantiate_node(new_model, "Class", "RHS")
 	instantiate_attribute(new_model, "RHS", "lower_cardinality", 1)
 	instantiate_attribute(new_model, "RHS", "upper_cardinality", 1)
-	instantiate_link(new_model, "Association", "RHS_action", "RHS", "funcdef")
-	instantiate_attribute(new_model, "RHS_action", "name", "action")
-	instantiate_attribute(new_model, "RHS_action", "target_upper_cardinality", 1)
-
-	//	Class Post_Element {
-	//		label : String {
-	//			target_lower_cardinality = 1
-	//			target_upper_cardinality = 1
-	//		}
-	//		value : funcdef {
-	//			target_upper_cardinality = 1
-	//		}
-	//		action : funcdef {
-	//			target_upper_cardinality = 1
-	//		}
+	model_define_attribute(new_model, "RHS", "action", True, "funcdef")
+
+	//	Class PostElement {
+	//		label : String
+	//		action? : funcdef
 	//	}
-	instantiate_node(new_model, "Class", "Post_Element")
-	instantiate_link(new_model, "Association", "Post_Element_label", "Post_Element", "String")
-	instantiate_attribute(new_model, "Post_Element_label", "name", "label")
-	instantiate_attribute(new_model, "Post_Element_label", "target_lower_cardinality", 1)
-	instantiate_attribute(new_model, "Post_Element_label", "target_upper_cardinality", 1)
-	instantiate_link(new_model, "Association", "Post_Element_value", "Post_Element", "funcdef")
-	instantiate_attribute(new_model, "Post_Element_value", "name", "value")
-	instantiate_attribute(new_model, "Post_Element_value", "target_upper_cardinality", 1)
-	instantiate_link(new_model, "Association", "Post_Element_action", "Post_Element", "funcdef")
-	instantiate_attribute(new_model, "Post_Element_action", "name", "action")
-	instantiate_attribute(new_model, "Post_Element_action", "target_upper_cardinality", 1)
-
-	// Association RHS_contains (RHS, Post_Element) {}
-	instantiate_link(new_model, "Association", "RHS_contains", "RHS", "Post_Element")
-	instantiate_attribute(new_model, "RHS_contains", "name", "contains")
+	instantiate_node(new_model, "Class", "PostElement")
+	model_define_attribute(new_model, "PostElement", "label", False, "String")
+	model_define_attribute(new_model, "PostElement", "action", True, "funcdef")
+
+	// Association RHS_contains (RHS, PostElement) {}
+	instantiate_link(new_model, "Association", "RHS_contains", "RHS", "PostElement")
 
 	// Basics are added, now we need to add each node and transition, but slightly modified
 	Element keys
@@ -124,15 +89,27 @@ Element function ramify(model : Element):
 	Element new_entry
 	Element entry
 
-	keys = dict_keys(old_m)
+	keys = set_to_list(dict_keys(old_m))
 	String type_name
 	String old_source
 	String old_target
-	Element to_link
-	to_link = create_node()
+	String attr_name
+	Element masked_attributes
+	Element copied_attributes
+
+	masked_attributes = create_node()
+	set_add(masked_attributes, "constraint")
+	set_add(masked_attributes, "lower_cardinality")
+	set_add(masked_attributes, "source_lower_cardinality")
+	set_add(masked_attributes, "target_lower_cardinality")
+
+	copied_attributes = create_node()
+	set_add(copied_attributes, "upper_cardinality")
+	set_add(copied_attributes, "source_upper_cardinality")
+	set_add(copied_attributes, "target_upper_cardinality")
 
 	while (read_nr_out(keys) > 0):
-		key = set_pop(keys)
+		key = list_pop(keys, read_nr_out(keys) - 1)
 		entry = old_m[key]
 
 		type_name = read_type(model, key)
@@ -141,48 +118,71 @@ Element function ramify(model : Element):
 			instantiate_node(new_model, type_name, "Post_" + key)
 
 			// Also make it inherit from the "root element"
-			instantiate_link(new_model, "Inheritance", "", "Pre_" + key, "Pre_Element")
-			instantiate_link(new_model, "Inheritance", "", "Post_" + key, "Post_Element")
+			instantiate_link(new_model, "Inheritance", "", "Pre_" + key, "PreElement")
+			instantiate_link(new_model, "Inheritance", "", "Post_" + key, "PostElement")
+
+		elif (type_name == "Attribute"):
+			// Got an attribute, so find out the source and name
+			old_source = reverseKeyLookup(model["model"], read_edge_src(entry))
+			attr_name = read_attribute(model, key, "name")
+
+			if (set_in(new_model["model"], "Pre_" + old_source)):
+				// Only if it is a class that it originates from is a class, should we add this
+				if (read_type(model, old_source) == "Class"):
+					// If the attribute is one used in the conformance check, we should mask it
+					// Add the attribute in the new model, altering its name and making it optional
+					log("Adding attribute " + attr_name)
+					log("  to " + old_source)
+					model_define_attribute(new_model, "Pre_" + old_source, attr_name + "_constraint", True, "funcdef")
+					model_define_attribute(new_model, "Post_" + old_source, attr_name + "_value", True, "funcdef")
+				else:
+					log("Non-class origin for attribute link " + key)
+			else:
+				// Queue for later
+				list_append(keys, key)
 
 		elif (type_name == "Association"):
 			old_source = reverseKeyLookup(model["model"], read_edge_src(entry))
 			old_target = reverseKeyLookup(model["model"], read_edge_dst(entry))
-			instantiate_link(new_model, type_name, "Pre_" + key, "Pre_" + old_source, "Pre_" + old_target)
-			instantiate_link(new_model, type_name, "Post_" + key, "Post_" + old_source, "Post_" + old_target)
 
-			// 1) Make it inherit from the Root Element (Pre_Element or Post_Element)
-			instantiate_link(new_model, "Inheritance", "", "Pre_" + key, "Pre_Element")
-			instantiate_link(new_model, "Inheritance", "", "Post_" + key, "Post_Element")
-			
+			if (bool_and(set_in(new_model["model"], old_source), set_in(new_model["model"], old_target))):
+				instantiate_link(new_model, type_name, "Pre_" + key, "Pre_" + old_source, "Pre_" + old_target)
+				instantiate_link(new_model, type_name, "Post_" + key, "Post_" + old_source, "Post_" + old_target)
+
+				// Make it inherit from the Root Element (PreElement or PostElement)
+				instantiate_link(new_model, "Inheritance", "", "Pre_" + key, "PreElement")
+				instantiate_link(new_model, "Inheritance", "", "Post_" + key, "PostElement")
+			else:
+				// Queue for later
+				list_append(keys, key)
+				
 		elif (type_name == "Inheritance"):
 			old_source = reverseKeyLookup(model["model"], read_edge_src(entry))
 			old_target = reverseKeyLookup(model["model"], read_edge_dst(entry))
-			instantiate_link(new_model, type_name, "Pre_" + key, "Pre_" + old_source, "Pre_" + old_target)
-			instantiate_link(new_model, type_name, "Post_" + key, "Post_" + old_source, "Post_" + old_target)
 
-		elif (bool_not(has_value(entry))):
-			create_edge(to_link, entry)
-
-	while (read_nr_out(to_link) > 0):
-		entry = set_pop(to_link)
-		type_name = read_type(model, reverseKeyLookup(model["model"], entry))
-		// Primitive values themselves are not copied, so skip that here
-
-		// An instance link, so just copy over (don't make element of Root Element), and don't even copy if it is lower cardinality
-		// It is probably an attribute at the meta-language level, so check which one it is
-		String name
-		name = read_attribute(model["metamodel"], type_name, "name")
-		if (bool_not(bool_or(bool_or(name == "lower_cardinality", name == "source_lower_cardinality"), bool_or(name == "constraint", name == "target_lower_cardinality")))):
-			// Not a lower cardinality or constraint, so copy
-			old_source = reverseKeyLookup(model["model"], read_edge_src(entry))
-			if (bool_or(bool_or(name == "name", name == "upper_cardinality"), bool_or(name == "source_upper_cardinality", name == "target_upper_cardinality"))):
-				// Keep the old name for the physical attributes!
-				instantiate_attribute(new_model, "Pre_" + old_source, name, read_edge_dst(entry))
-				instantiate_attribute(new_model, "Post_" + old_source, name, read_edge_dst(entry))
+			if (bool_and(set_in(new_model["model"], old_source), set_in(new_model["model"], old_target))):
+				instantiate_link(new_model, type_name, "Pre_" + key, "Pre_" + old_source, "Pre_" + old_target)
+				instantiate_link(new_model, type_name, "Post_" + key, "Post_" + old_source, "Post_" + old_target)
 			else:
-				// Rename the attributes as well
-				instantiate_attribute(new_model, "Pre_" + old_source, "Pre_" + name, read_edge_dst(entry))
-				instantiate_attribute(new_model, "Post_" + old_source, "Post_" + name, read_edge_dst(entry))
+				// Queue for later
+				list_append(keys, key)
+
+		elif (bool_not(has_value(entry))):
+			type_name = read_type(model, key)
+			// Primitive values themselves are not copied, so skip that here
+
+			attr_name = read_attribute(model, type_name, "name")
+			if (read_type(model["metamodel"], type_name) == "Attribute"):
+				old_source = reverseKeyLookup(model["model"], read_edge_src(entry))
+
+				if (set_in(copied_attributes, attr_name)):
+					log("Copy attribute " + attr_name)
+					log("  to " + old_source)
+					instantiate_attribute(new_model, "Pre_" + old_source, attr_name, read_attribute(model, old_source, attr_name))
+					instantiate_attribute(new_model, "Post_" + old_source, attr_name, read_attribute(model, old_source, attr_name))
+				else:
+					log("Masked attribute: " + attr_name)
+					log("  for " + old_source)
 
 	// Define schedule over these elements
 

+ 9 - 3
core/core_algorithm.alc

@@ -13,7 +13,8 @@ include "metamodels.alh"
 Element core = ?
 
 String core_location = "models/CoreFormalism"
-String core_model_location = "models/core"
+String core_model_location = "core"
+String coreM_model_location = "models/core"
 
 Void function main():
 	// Initialize the Core Formalism
@@ -34,7 +35,8 @@ Void function main():
 	// Create the Model itself and make public
 	core_formalism = import_node(core_location)
 	core = instantiate_model(core_formalism)
-	export_node(core_model_location, core["model"])
+	export_node(core_model_location, core)
+	export_node(coreM_model_location, core["model"])
 
 	// Switch all new users to the user_function
 	// This accesses the bootstrap level, so do not change this unless you know what you are doing
@@ -107,7 +109,7 @@ Void function main():
 	// Add the core model
 	core_model = instantiate_node(core, "Model", "")
 	instantiate_attribute(core, core_model, "name", "core")
-	instantiate_attribute(core, core_model, "location", core_model_location)
+	instantiate_attribute(core, core_model, "location", coreM_model_location)
 	instantiate_attribute(core, core_model, "permissions", "200")
 	instance_of = instantiate_link(core, "instanceOf", "", core_model, core_formalism_model)
 	instantiate_attribute(core, instance_of, "type_mapping", core["type_mapping"])
@@ -321,7 +323,11 @@ String function get_user_id(name : String):
 	Element users
 	String user
 
+	log("Searching user " + name)
+	log("In " + cast_e2s(core))
+	log("Has entries: " + set_to_string(dict_keys(core)))
 	users = allInstances(core, "User")
+
 	while (read_nr_out(users) > 0):
 		user = set_pop(users)
 		if (value_eq(read_attribute(core, user, "name"), name)):

+ 2 - 2
scripts/run_MvC_server.py

@@ -19,8 +19,8 @@ subprocess.check_call([sys.executable, "-m", "sccd.compiler.sccdc", "-p", "threa
 
 # Start up the MvK as a subprocess
 try:
-    #obj = subprocess.Popen([sys.executable, "run_mvk_server.py", str(MVK_PORT), "--kernel=baseline-jit"], cwd="hybrid_server")
-    obj = subprocess.Popen([sys.executable, "run_mvk_server.py", str(MVK_PORT), "--kernel=legacy-interpreter"], cwd="hybrid_server")
+    obj = subprocess.Popen([sys.executable, "run_mvk_server.py", str(MVK_PORT), "--kernel=baseline-jit"], cwd="hybrid_server")
+    #obj = subprocess.Popen([sys.executable, "run_mvk_server.py", str(MVK_PORT), "--kernel=legacy-interpreter"], cwd="hybrid_server")
 
     # Compile all MvC code
     subprocess.call([sys.executable, "scripts/execute_model.py", address, SETUP_USER, "bootstrap/*.alc", "core/*.alc", "core/*.mvc"])