Procházet zdrojové kódy

Beginning of nice printer

Yentl Van Tendeloo před 7 roky
rodič
revize
a144377967
2 změnil soubory, kde provedl 32 přidání a 3 odebrání
  1. 31 2
      kernel/modelverse_kernel/main.py
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 31 - 2
kernel/modelverse_kernel/main.py

@@ -180,6 +180,34 @@ class ModelverseKernel(object):
                 getattr(source, function_names[i]),
                 function_names[i])
 
+    def print_instruction(self, inst, indent=0):
+        inst_type, = yield [("RV", [inst])]
+        #print("  %s (%s)" % (inst, inst_type["value"]))
+        if inst_type["value"] == "if":
+            cond, true, false = yield [("RD", [inst, "cond"]),
+                                       ("RD", [inst, "then"]),
+                                       ("RD", [inst, "else"])]
+            #print("Cond: %s; True: %s; False: %s" % (cond, true, false))
+            cond, = yield [("CALL_ARGS", [self.print_instruction, (cond, 0)])]
+            true, = yield [("CALL_ARGS", [self.print_instruction, (true, indent+1)])]
+            if false:
+                false, = yield [("CALL_ARGS", [self.print_instruction, (false, indent+1)])]
+                false = ("  " * indent + "else:\n%s\n") % false
+            else:
+                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":
+            node, = yield [("RD", [inst, "node"])]
+            #print("Node: %s" % (node))
+
+        raise primitive_functions.PrimitiveFinished("(no_printer_for_%s)" % inst_type["value"])
+
     def read_function(self, inst):
         initial_instruction = inst
         suggested_name = self.jit.get_global_name(inst)
@@ -190,8 +218,9 @@ class ModelverseKernel(object):
             raise jit.JitCompilationFailedException("FAIL")
 
         print("Reading function: %s" % suggested_name)
-        inst_type, = yield [("RV", [inst])]
-        print("  %s (%s)" % (inst, inst_type["value"]))
+        printed, = yield [("CALL_ARGS", [self.print_instruction, (inst, 0)])]
+        print("Total printed function: ")
+        print(printed)
 
     def jit_compile(self, task_root, inst):
         # Try to retrieve the suggested name.

+ 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)
 
-Date:   Fri Mar 23 07:36:08 2018
+Date:   Fri Mar 23 07:59:37 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server