Browse Source

Printing out more and more functions

Yentl Van Tendeloo 7 years ago
parent
commit
8897bce6d6
2 changed files with 44 additions and 12 deletions
  1. 43 11
      kernel/modelverse_kernel/main.py
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 43 - 11
kernel/modelverse_kernel/main.py

@@ -182,7 +182,8 @@ class ModelverseKernel(object):
 
 
     def print_instruction(self, inst, indent=0):
     def print_instruction(self, inst, indent=0):
         inst_type, = yield [("RV", [inst])]
         inst_type, = yield [("RV", [inst])]
-        #print("  %s (%s)" % (inst, inst_type["value"]))
+        instruction = "(no_printer_for_%s)" % inst_type["value"]
+
         if inst_type["value"] == "if":
         if inst_type["value"] == "if":
             cond, true, false = yield [("RD", [inst, "cond"]),
             cond, true, false = yield [("RD", [inst, "cond"]),
                                        ("RD", [inst, "then"]),
                                        ("RD", [inst, "then"]),
@@ -196,17 +197,48 @@ class ModelverseKernel(object):
             else:
             else:
                 false = ""
                 false = ""
 
 
-            next_inst, = yield[("RD", [inst, "next"])]
-            if next_inst:
-                next_inst, = yield [("CALL_ARGS", [self.print_instruction, (next_inst, indent)])]
-            else:
-                next_inst = ""
-            raise primitive_functions.PrimitiveFinished("  " * indent + "if(" + cond + "):\n" + true + "\n" + false + next_inst)
-        elif inst_type["value"] == "const":
+            instruction = "  " * indent + "if(" + cond + "):\n" + true + "\n" + false
+        elif inst_type["value"] == "constant":
             node, = yield [("RD", [inst, "node"])]
             node, = yield [("RD", [inst, "node"])]
-            #print("Node: %s" % (node))
+            node, = yield [("RV", [node])]
+            instruction = "  " * indent + str(node)
+        elif inst_type["value"] == "return":
+            value, = yield [("RD", [inst, "value"])]
+            if value:
+                value, = yield [("CALL_ARGS", [self.print_instruction, (value, 0)])]
+                instruction = "  " * indent + "return %s\n" % value
+            else:
+                instruction = "  " * indent + "return\n"
+        elif inst_type["value"] == "declare":
+            instruction = ""
+        elif inst_type["value"] == "resolve":
+            value, = yield [("RD", [inst, "var"])]
+            #instruction, = yield [("CALL_ARGS", [self.print_instruction, (value, 0)])]
+            instruction = "var_%s" % value
+        elif inst_type["value"] == "assign":
+            var, val = yield [("RD", [inst, "var"]),
+                              ("RD", [inst, "value"])]
+            var, val = yield [("CALL_ARGS", [self.print_instruction, (var, 0)]),
+                              ("CALL_ARGS", [self.print_instruction, (val, 0)])]
+            instruction = "  " * indent + var + " = " + val + "\n"
+        elif inst_type["value"] == "call":
+            instruction = "  " * indent + "call(X)"
+            if indent:
+                instruction += "\n"
+        elif inst_type["value"] == "while":
+            cond, body = yield [("RD", [inst, "cond"]),
+                                ("RD", [inst, "body"])]
+            cond, body = yield [("CALL_ARGS", [self.print_instruction, (cond, 0)]),
+                                ("CALL_ARGS", [self.print_instruction, (body, indent+1)])]
+            instruction = "  " * indent + "while (%s):\n" % cond + body
+
+        next_inst, = yield [("RD", [inst, "next"])]
+        if next_inst:
+            next_inst, = yield [("CALL_ARGS", [self.print_instruction, (next_inst, indent)])]
+        else:
+            next_inst = ""
 
 
-        raise primitive_functions.PrimitiveFinished("(no_printer_for_%s)" % inst_type["value"])
+        raise primitive_functions.PrimitiveFinished(instruction + next_inst)
 
 
     def read_function(self, inst):
     def read_function(self, inst):
         initial_instruction = inst
         initial_instruction = inst
@@ -218,7 +250,7 @@ class ModelverseKernel(object):
             raise jit.JitCompilationFailedException("FAIL")
             raise jit.JitCompilationFailedException("FAIL")
 
 
         print("Reading function: %s" % suggested_name)
         print("Reading function: %s" % suggested_name)
-        printed, = yield [("CALL_ARGS", [self.print_instruction, (inst, 0)])]
+        printed, = yield [("CALL_ARGS", [self.print_instruction, (inst, 1)])]
         print("Total printed function: ")
         print("Total printed function: ")
         print(printed)
         print(printed)
 
 

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Fri Mar 23 07:59:37 2018
+Date:   Fri Mar 23 08:56:39 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server