瀏覽代碼

Even more workarounds for the compiler/parser

Yentl Van Tendeloo 8 年之前
父節點
當前提交
e2faf99fb0

+ 24 - 2
bootstrap/modelling.alc

@@ -191,6 +191,22 @@ Void function instantiate_attribute(model : Element, element : String, attribute
 
 	return!
 
+Void function instantiate_attribute_ref(model : Element, element : String, attribute_name : String, ref : String):
+	// Instantiate an attribute of something that needs to be instantiated
+	// Actually a bit more difficult than all the rest, as we need to find the attribute to instantiate
+	String attr_type
+	String attr_name
+
+	attr_type = find_attribute_type(model, element, attribute_name)
+
+	if (attr_type == ""):
+		log("Could not find attribute " + cast_v2s(attribute_name))
+		return!
+		
+	instantiate_link(model, attr_type, "", element, ref)
+
+	return!
+
 Void function instantiate_attribute_code(model : Element, element : String, attribute_name : String, code : Element):
 	String ref
 	ref = add_AL(model, code)
@@ -458,6 +474,8 @@ Void function construct_model():
 			instantiate_node(global_models[input()], input(), input())
 		elif (command == "instantiate_attribute"):
 			instantiate_attribute(global_models[input()], input(), input(), input())
+		elif (command == "instantiate_attribute_ref"):
+			instantiate_attribute_ref(global_models[input()], input(), input(), input())
 		elif (command == "instantiate_link"):
 			instantiate_link(global_models[input()], input(), input(), input(), input())
 		elif (command == "define_inheritance"):
@@ -473,12 +491,16 @@ Void function construct_model():
 			String location
 			local_name = input()
 			location = input()
+			log("Exporting to location " + location)
+			log("  name: " + local_name)
+			log("Export element: " + cast_e2s(global_models[local_name]))
 			export_node(location, global_models[local_name])
 		elif (command == "import_node"):
 			Element m
-			m = import_node(input())
+			command = input()
+			m = import_node(command)
 			if (element_eq(m, read_root())):
-				log("Error: import not found")
+				log("Error: import not found for " + command)
 			else:
 				dict_add(global_models, input(), m)
 		else:

+ 13 - 14
integration/test_pn_interface.py

@@ -1126,7 +1126,7 @@ Void function action(host_model : Element, name : String, mapping : Element):
                     OnFailure (unmark_transition, failure) {}
                     OnSuccess (unmark_place, unmark_place) {}
                     OnFailure (unmark_place, success) {}
-                    initial = mark
+                    initial = !mark
                 }
             }
 
@@ -1134,18 +1134,17 @@ Void function action(host_model : Element, name : String, mapping : Element):
             """
 
         self.assertTrue(run_file(all_files,
-            ["upload", 
-            ] + get_model_constructor(PN_runtime) + [
-            ] + get_model_constructor(PN_model) + [
-             "ramify", "PetriNets_runtime",
-            ] + get_model_constructor(schedule_model) + [
-             "transform", "pn", "pn_simulate",
-             "load", "pn",
-                "list",
-                "verify",
-                "read", "t1",
-                "read", "p1",
-                "read", "p2",
-                "exit",
+            get_model_constructor(PN_runtime) + \
+                get_model_constructor(PN_model) + [
+                "ramify", "PetriNets_runtime",
+                ] + get_model_constructor(schedule_model) + [
+                "transform", "pn", "pn_simulate",
+                "load", "pn",
+                    "list",
+                    "verify",
+                    "read", "t1",
+                    "read", "p1",
+                    "read", "p2",
+                    "exit",
             ],
           None, "PO"))

+ 2 - 1
integration/utils.py

@@ -292,6 +292,7 @@ def get_model_constructor(code):
         f.write(code)
         f.flush()
 
-    constructors = do_compile("__model.mvc", "interface/HUTN/grammars/modelling.g", "M")
+    constructors = ["upload"] + do_compile("__model.mvc", "interface/HUTN/grammars/modelling.g", "M") + ["exit"]
+    print(constructors)
 
     return constructors

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

@@ -18,7 +18,7 @@ grammar{
 
     model_attr_instance: (MODEL_ID ASSIGN value NEWLINE?)
                        | (MODEL_ID ASSIGN NEWLINE? DOLLAR ANYTHING_EXCEPT_DOLLAR DOLLAR NEWLINE?)
-                       | (MODEL_ID ASSIGN MODEL_ID NEWLINE?);
+                       | (MODEL_ID ASSIGN EXCLAMATION MODEL_ID NEWLINE?);
 
     value
         : DEC_NUMBER
@@ -52,5 +52,6 @@ grammar{
         TO: 'to';
         ANYTHING_EXCEPT_DOLLAR: '[^$]*';
         INCLUDE: 'include';
+        EXCLAMATION: '!';
     }
 }

+ 4 - 2
interface/HUTN/hutn_compiler/model_visitor.py

@@ -44,7 +44,7 @@ class ModelVisitor(Visitor):
     def visit_model(self, tree):
         children = tree.get_children("MODEL_ID")
         model_type = children[0].get_text()
-        model_name = children[1].get_text()
+        model_name = children[-1].get_text()
         self.constructors.extend(["instantiate_model", model_type, model_name])
         if "LPAR" in tree.get_tail():
             self.constructors.extend(["define_inheritance", model_name, tree.get_children("MODEL_ID")[1].get_text()])
@@ -144,6 +144,7 @@ class ModelVisitor(Visitor):
                 f.flush()
             directory = os.path.realpath(__file__).rsplit(os.sep, 1)[0]
             compiled = do_compile(".code.alc", directory + "/../grammars/actionlanguage.g", "CS")
+            return compiled
 
         children = tree.get_children("MODEL_ID")
         attr_name = children[0].get_text()
@@ -165,7 +166,8 @@ class ModelVisitor(Visitor):
             self.constructors.extend(["instantiate_attribute", self.current_model, self.current_element, attr_name, attr_value])
         elif tree.get_children("DOLLAR"):
             # Coded attribute
-            self.constructors.extend(["instantiate_attribute_code", self.current_model, self.current_element, attr_name, constructors_compile(tree.get_children("ANYTHING_EXCEPT_DOLLAR")[0].get_text())])
+            self.constructors.extend(["instantiate_attribute_code", self.current_model, self.current_element, attr_name])
+            self.constructors.extend(constructors_compile(tree.get_children("ANYTHING_EXCEPT_DOLLAR")[0].get_text()))
         else:
             # Assign direct reference
             self.constructors.extend(["instantiate_attribute_ref", self.current_model, self.current_element, attr_name, tree.get_children("MODEL_ID")[1].get_text()])