Browse Source

Working AL compilation

Yentl Van Tendeloo 8 years ago
parent
commit
8f1ee523d7

+ 4 - 0
bootstrap/compiler.alc

@@ -8,6 +8,7 @@ Element function generic_compile(code : String, port : String):
 	
 	String response
 	response = comm_get(port)
+	log("Got response: " + response)
 	if (response == "OK"):
 		Integer count
 		Element lst
@@ -16,6 +17,7 @@ Element function generic_compile(code : String, port : String):
 		count = comm_get(port)
 		while (count > 0):
 			list_append(lst, comm_get(port))
+			count = count - 1
 
 		comm_close(port)
 		return lst!
@@ -36,6 +38,7 @@ Element function compile_code(code : String):
 		return read_root()!
 
 	else:
+		log("Compiling: " + list_to_string(list))
 		return construct_function_list(list)!
 
 Element function compile_model(code : String, metamodel : Element):
@@ -50,4 +53,5 @@ Element function compile_model(code : String, metamodel : Element):
 		return read_root()!
 
 	else:
+		log("Compiling: " + list_to_string(list))
 		return construct_model_list(metamodel, list)!

+ 3 - 1
bootstrap/constructors.alc

@@ -18,7 +18,7 @@ Element function construct_function():
 	while (list_len(list) < len):
 		list_append(list, input())
 
-	return construct_function_list(list_reverse(list))!
+	return construct_function_list(list)!
 
 Element function construct_function_list(list : Element):
 	String command
@@ -28,6 +28,8 @@ Element function construct_function_list(list : Element):
 	Element prev_element
 	Element first_element
 
+	list = list_reverse(list)
+
 	// Initialize variables
 	prev_element = read_root()
 	main_function = read_root()

+ 1 - 1
hybrid_server/classes/service.xml

@@ -75,7 +75,7 @@
                     </state>
 
                     <state id="yielded">
-                        <transition after="self.sccd_yield() + 0.1" target="../executing"/>
+                        <transition after="self.sccd_yield() + 0.2" target="../executing"/>
                         <transition event="processed_input" target="../executing"/>
                         <transition event="waiting_output" target="../executing"/>
                     </state>

+ 0 - 7
interface/HUTN/hutn_compiler/primitives_visitor.py

@@ -174,13 +174,6 @@ class PrimitivesVisitor(Visitor):
             v = tree.get_text()[1:]
         else:
             v = tree.get_text()
-
-            if isinstance(v, (str, unicode)):
-                # Rewrite \n
-                print("Rewriting!")
-                v = v.replace("\\n", "\n")
-                v = v.replace("\\t", "\t")
-                v = v.replace("\\\"", "\"")
         #NOTE Wrap this in an Action, even though it might not be an action: this has to be seen directly in the Mv without additional wrapping
         n = self.value(Action(v))
         self.dict(c, "node", n)

+ 21 - 6
scripts/HUTN_service.py

@@ -5,11 +5,13 @@ sys.path.append(COMPILER_PATH)
 sys.path.append("wrappers")
 from hutn_compiler.compiler import main as do_compile
 from modelverse import *
+import os
 
 init()
 login("HUTN", "HUTN")
 
 def compile_service(port):
+    temp_file = ".tmp_%s" % port
     def compile_AL(code):
         code_fragments = code.split("\n")
         code_fragments = [i for i in code_fragments if i.strip() != ""]
@@ -19,11 +21,13 @@ def compile_service(port):
         code_fragments.append("")
         code = "\n".join(code_fragments)
 
-        with open(".code.alc", "w") as f:
+        with open(temp_file, "w") as f:
             f.write(code)
             f.flush()
 
-        compiled = do_compile(".code_%s.alc" % port, COMPILER_PATH + "/grammars/actionlanguage.g", "CS")
+        compiled = do_compile(temp_file, COMPILER_PATH + "/grammars/actionlanguage.g", "CS")
+        os.remove(temp_file)
+        print("Compiled AL to " + str(compiled))
         return compiled
 
     def compile_model(code):
@@ -35,27 +39,38 @@ def compile_service(port):
         code_fragments.append("")
         code = "\n".join(code_fragments)
 
-        with open(".model.mvc", "w") as f:
+        with open(temp_file, "w") as f:
             f.write(code)
             f.flush()
 
-        return do_compile(".model.mvc", COMPILER_PATH + "/grammars/modelling.g", "M")
+        compiled = do_compile(temp_file, COMPILER_PATH + "/grammars/modelling.g", "M")
+        os.remove(temp_file)
+        return compiled
 
     mode = service_get(port)
     code = service_get(port)
+
+    print("Compiling code: ")
+    print(code)
     try:
         if mode == "code":
-            service_set(port, "OK")
+            print("Compiling...")
             compiled = compile_AL(code)
+            service_set(port, "OK")
             [service_set(port, i) for i in compiled]
+            print("DONE!")
         elif mode == "model":
-            service_set(port, "OK")
+            print("Compiling...")
             compiled = compile_model(code)
+            service_set(port, "OK")
             [service_set(port, i) for i in compiled]
+            print("DONE!")
         else:
             raise Exception("No such mode: " + mode)
     except Exception as e:
+        print("EXCEPTION!")
         service_set(port, str(e))
+        raise
 
 service_register("compiler", compile_service)
 try: