Explorar o código

Minimalistic infrastructure to allow for intrinsics

Yentl Van Tendeloo %!s(int64=7) %!d(string=hai) anos
pai
achega
62673bf753
Modificáronse 2 ficheiros con 15 adicións e 5 borrados
  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])
                 function_names[i])
 
 
     def print_instruction(self, inst, indent=0):
     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])]
         inst_type, = yield [("RV", [inst])]
         instruction = "(no_printer_for_%s)" % inst_type["value"]
         instruction = "(no_printer_for_%s)" % inst_type["value"]
 
 
@@ -238,7 +246,10 @@ class ModelverseKernel(object):
                                     ("RD", [param, "next_param"])]
                                     ("RD", [param, "next_param"])]
                 param_list.append(res)
                 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:
             if indent:
                 instruction += "\n"
                 instruction += "\n"
         elif inst_type["value"] == "access":
         elif inst_type["value"] == "access":
@@ -271,9 +282,8 @@ class ModelverseKernel(object):
         print("Reading function: %s" % suggested_name)
         print("Reading function: %s" % suggested_name)
         printed, = yield [("CALL_ARGS", [self.print_instruction, (inst, 1)])]
         printed, = yield [("CALL_ARGS", [self.print_instruction, (inst, 1)])]
         print("Total printed function: ")
         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):
     def jit_compile(self, task_root, inst):
         # Try to retrieve the suggested name.
         # 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)
 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 author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server