Browse Source

Fixed bug in some constructs

Yentl Van Tendeloo 7 years ago
parent
commit
6e3a11b5bf
2 changed files with 18 additions and 11 deletions
  1. 17 10
      kernel/modelverse_kernel/main.py
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 17 - 10
kernel/modelverse_kernel/main.py

@@ -210,25 +210,33 @@ class ModelverseKernel(object):
             (prev_true, instruction_true), = yield [("CALL_ARGS", [self.print_instruction, (true, indent+1)])]
             if false:
                 (prev_false, instruction_false), = yield [("CALL_ARGS", [self.print_instruction, (false, indent+1)])]
-                false = ("  " * indent + "else:\n%s%s\n") % (prev_false, instruction_false)
+                false = ("  " * indent + "else:\n%s%s") % (prev_false, instruction_false)
             else:
                 false = ""
 
-            instruction = prev_cond + "  " * indent + "if (" + instruction_cond + "):\n" + prev_true + instruction_true + "\n" + false
+            instruction = prev_cond + "  " * indent + "if (" + instruction_cond + "):\n" + prev_true + instruction_true + false
 
         elif inst_type["value"] == "constant":
             node, = yield [("RD", [inst, "node"])]
-            node, = yield [("RV", [node])]
-            if isinstance(node, str):
-                instruction = "  " * indent + '"%s"' % node
+            node_value, = yield [("RV", [node])]
+            if node_value is not None:
+                # There is a value to the node, so replicate the value
+                if isinstance(node_value, str):
+                    value = '"%s"' % node_value
+                else:
+                    value = str(node_value)
+                instruction = "constant_" + str(ModelverseKernel.counter)
+                ModelverseKernel.counter += 1
+                prev = "  " * nested_indent + instruction + ", = yield [('CNV', [" + value + "])]\n"
             else:
-                instruction = "  " * indent + str(node)
+                # Node is None, meaning that it was not about the value, but the node itself...
+                instruction = str(node)
 
         elif inst_type["value"] == "return":
             value, = yield [("RD", [inst, "value"])]
             if value:
                 (prev_value, instruction_value), = yield [("CALL_ARGS", [self.print_instruction, (value, 0, indent)])]
-                instruction = prev_value + "  " * indent + "return %s\n" % value
+                instruction = prev_value + "  " * indent + "return %s\n" % instruction_value
             else:
                 instruction = "  " * indent + "return\n"
 
@@ -254,7 +262,6 @@ class ModelverseKernel(object):
         elif inst_type["value"] == "call":
             func_name, = yield [("RD", [inst, "func"])]
             (prev_func_name, func_name), = yield [("CALL_ARGS", [self.print_instruction, (func_name, 0, nested_indent)])]
-            print("Visit call to " + str(func_name) + " with indents: (%s,%s)" % (indent, nested_indent))
             param_list = []
 
             param, = yield [("RD", [inst, "params"])]
@@ -296,7 +303,7 @@ class ModelverseKernel(object):
             cond, body = yield [("RD", [inst, "cond"]),
                                 ("RD", [inst, "body"])]
             (prev_cond, instruction_cond), (prev_body, instruction_body) = \
-                        yield [("CALL_ARGS", [self.print_instruction, (cond, indent+1)]),
+                        yield [("CALL_ARGS", [self.print_instruction, (cond, 0, indent+1)]),
                                ("CALL_ARGS", [self.print_instruction, (body, indent+1)])]
             instruction = "  " * indent + "while 1:\n" + prev_cond + \
                           "  " * (indent + 1) + "if not (" + instruction_cond + "):\n" + \
@@ -324,7 +331,7 @@ class ModelverseKernel(object):
         print("Reading function: %s" % suggested_name)
         (_, printed), = yield [("CALL_ARGS", [self.print_instruction, (inst, 1)])]
         print("Total printed function: ")
-        func = "def " + suggested_name + "(" + ",".join(["var_%s" % param for param in params]) + "):\n" + printed
+        func = "def " + suggested_name + "(" + ", ".join(["var_%s" % param for param in params]) + "):\n" + printed
         print(func)
 
     def jit_compile(self, task_root, inst):

+ 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:   Thu Apr  5 11:49:23 2018
+Date:   Thu Apr  5 14:25:38 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server