Browse Source

Semi-working JIT

Yentl Van Tendeloo 7 years ago
parent
commit
2ba3034684
2 changed files with 32 additions and 2 deletions
  1. 31 1
      kernel/modelverse_kernel/main.py
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 31 - 1
kernel/modelverse_kernel/main.py

@@ -227,7 +227,7 @@ class ModelverseKernel(object):
             if node_value is not None:
             if node_value is not None:
                 # There is a value to the node, so replicate the value
                 # There is a value to the node, so replicate the value
                 if isinstance(node_value, str):
                 if isinstance(node_value, str):
-                    value = '"%s"' % node_value
+                    value = '"%s"' % node_value.replace('"', '\\"').replace('\t', '\\t').replace('\n', '\\n')
                 else:
                 else:
                     value = str(node_value)
                     value = str(node_value)
                 instruction = "constant_" + str(ModelverseKernel.counter)
                 instruction = "constant_" + str(ModelverseKernel.counter)
@@ -254,6 +254,36 @@ class ModelverseKernel(object):
         elif inst_type["value"] == "continue":
         elif inst_type["value"] == "continue":
             instruction = "  " * indent + "continue\n"
             instruction = "  " * indent + "continue\n"
 
 
+        elif inst_type["value"] == "input":
+            prev = "  " * nested_indent + "_inputs, = yield [('RD', [kwargs['task_root'], 'input'])]\n" + \
+                   "  " * nested_indent + "while 1:\n" + \
+                   "  " * (nested_indent + 1) + "val, = yield [('RD', [_inputs, 'value'])]\n" + \
+                   "  " * (nested_indent + 1) + "if val is not None:\n" + \
+                   "  " * (nested_indent + 2) + "val_e, = yield [('RDE', [_inputs, 'value'])]\n" + \
+                   "  " * (nested_indent + 2) + "yield [('DE', [val_e])]\n" + \
+                   "  " * (nested_indent + 2) + "val_e, = yield [('RDE', [kwargs['task_root'], 'input'])]\n" + \
+                   "  " * (nested_indent + 2) + "yield [('DE', [val_e])]\n" + \
+                   "  " * (nested_indent + 2) + "nxt, = yield [('RD', [_inputs, 'next'])]\n" + \
+                   "  " * (nested_indent + 2) + "yield [('CD', [kwargs['task_root'], 'input', nxt])]\n" + \
+                   "  " * (nested_indent + 2) + "_result = val\n" + \
+                   "  " * (nested_indent + 2) + "break\n" + \
+                   "  " * (nested_indent + 1)+ "else:\n" + \
+                   "  " * (nested_indent + 2) + "yield None\n"
+            instruction = "_result"
+
+        elif inst_type["value"] == "output":
+            value, = yield [("RD", [inst, "value"])]
+            (prev, inst), = yield [("CALL_ARGS", [self.print_instruction, (value, 0, indent)])]
+            instruction = prev + \
+                          "  " * indent + "_outputs, = yield [('RD', [kwargs['task_root'], 'last_output'])]\n" + \
+                          "  " * indent + "_outputs_e, = yield [('RDE', [kwargs['task_root'], 'last_output'])]\n" + \
+                          "  " * indent + "yield [('CD', [_outputs, 'value', %s])]\n" % inst + \
+                          "  " * indent + "_new, = yield [('CN', [])]\n" + \
+                          "  " * indent + "yield [('CD', [_outputs, 'next', _new])]\n" + \
+                          "  " * indent + "yield [('DE', [_outputs_e])]\n" + \
+                          "  " * indent + "yield [('CD', [kwargs['task_root'], 'last_output', _new])]\n"
+
+
         elif inst_type["value"] == "resolve":
         elif inst_type["value"] == "resolve":
             value, = yield [("RD", [inst, "var"])]
             value, = yield [("RD", [inst, "var"])]
             str_value, = yield [("RV", [value])]
             str_value, = yield [("RV", [value])]

+ 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:   Tue Apr 10 11:56:19 2018
+Date:   Tue Apr 10 12:42:12 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server