فهرست منبع

Switch to use of CALL_KWARGS instead of usual CALL_ARGS to take into account the additional parameters required by primitive operations

Yentl Van Tendeloo 7 سال پیش
والد
کامیت
686538111c
2فایلهای تغییر یافته به همراه15 افزوده شده و 8 حذف شده
  1. 14 7
      kernel/modelverse_kernel/main.py
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 14 - 7
kernel/modelverse_kernel/main.py

@@ -262,17 +262,19 @@ 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)])]
-            param_list = []
+            param_list = {}
 
             param, = yield [("RD", [inst, "params"])]
             computation = ""
             while param:
                 value, = yield [("RD", [param, "value"])]
+                name, = yield [("RD", [param, "name"])]
+                name, = yield [("RV", [name])]
                 (prev_res, instruction_res), param = \
                         yield [("CALL_ARGS", [self.print_instruction, (value, 0, nested_indent)]),
                                ("RD", [param, "next_param"])]
                 computation += prev_res
-                param_list.append(instruction_res)
+                param_list[name] = instruction_res
 
             if func_name in intrinsics:
                 #instruction = "  " * indent + intrinsics[func_name](*param_list)
@@ -281,10 +283,8 @@ class ModelverseKernel(object):
             else:
                 value = "func_result_" + str(ModelverseKernel.counter)
                 ModelverseKernel.counter += 1
-                if len(param_list) == 1:
-                    actual_computation = "%s, = yield [('CALL_ARGS', [%s, (%s,)])]\n" % (value, func_name, param_list[0])
-                else:
-                    actual_computation = "%s, = yield [('CALL_ARGS', [%s, (%s)])]\n" % (value, func_name, ", ".join(param_list))
+                param_list = "{" + ", ".join(["'%s': %s" % (k, v) for k, v in param_list.items()]) + "}"
+                actual_computation = "%s, = yield [('CALL_KWARGS', [%s, %s])]\n" % (value, func_name, param_list)
 
                 if indent == 0:
                     # No indent, meaning that we use it inline
@@ -331,7 +331,10 @@ 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
+        if params:
+            func = "def " + suggested_name + "(" + ", ".join(["var_%s" % param for param in params]) + ", **kwargs):\n" + printed
+        else:
+            func = "def " + suggested_name + "(**kwargs):\n" + printed
         print(func)
         raise primitive_functions.PrimitiveFinished(func)
 
@@ -357,11 +360,15 @@ class ModelverseKernel(object):
 
         #raise jit.JitCompilationFailedException("FAIL")
 
+        raise primitive_functions.PrimitiveFinished(compiled_func)
+
+        """
         try:
             raise primitive_functions.PrimitiveFinished(compiled_func)
         except Exception as e:
             print("Exception: " + str(e))
             raise jit.JitCompilationFailedException("FAIL")
+        """
 
     def execute_jit(self, task_root, inst, taskname):
         # execute_jit

+ 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 Apr  6 07:12:11 2018
+Date:   Fri Apr  6 07:23:07 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server