Selaa lähdekoodia

Minimalistic infrastructure to allow for intrinsics

Yentl Van Tendeloo 7 vuotta sitten
vanhempi
commit
62673bf753
2 muutettua tiedostoa jossa 15 lisäystä ja 5 poistoa
  1. 14 4
      kernel/modelverse_kernel/main.py
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 14 - 4
kernel/modelverse_kernel/main.py

@@ -181,6 +181,14 @@ class ModelverseKernel(object):
                 function_names[i])
 
     def print_instruction(self, inst, indent=0):
+        intrinsics = {"integer_addition": (lambda x, y: "(%s + %s)" % (x, y)),
+                      #"string_join": (lambda x, y: "(str(%s) + str(%s))" % (x, y)),
+                      #"dict_read": (lambda x, y: "(%s[%s])" % (x, y)),
+                      #"dict_overwrite": (lambda x, y, z: "(%s[%s] = %s)" % (x, y, z)),
+                      #"dict_add_fast": (lambda x, y, z: "(%s[%s] = %s)" % (x, y, z)),
+                      #"dict_add_fast": (lambda x, y, z: "(%s[%s] = %s)" % (x, y, z)),
+                      }
+
         inst_type, = yield [("RV", [inst])]
         instruction = "(no_printer_for_%s)" % inst_type["value"]
 
@@ -238,7 +246,10 @@ class ModelverseKernel(object):
                                     ("RD", [param, "next_param"])]
                 param_list.append(res)
 
-            instruction = "  " * indent + func_name + "(" + ", ".join(param_list) + ")"
+            if func_name in intrinsics:
+                instruction = "  " * indent + intrinsics[func_name](*param_list)
+            else:
+                instruction = "  " * indent + func_name + "(" + ", ".join(param_list) + ")"
             if indent:
                 instruction += "\n"
         elif inst_type["value"] == "access":
@@ -271,9 +282,8 @@ class ModelverseKernel(object):
         print("Reading function: %s" % suggested_name)
         printed, = yield [("CALL_ARGS", [self.print_instruction, (inst, 1)])]
         print("Total printed function: ")
-        signature = "def " + suggested_name + "(" + ",".join(["var_%s" % param for param in params]) + "):\n"
-        print(signature)
-        print(printed)
+        func = "def " + suggested_name + "(" + ",".join(["var_%s" % param for param in params]) + "):\n" + printed
+        print(func)
 
     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:   Sat Mar 24 11:04:45 2018
+Date:   Sat Mar 24 11:14:56 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server