Explorar o código

Switch in new JIT compiler, which is still severely broken

Yentl Van Tendeloo %!s(int64=7) %!d(string=hai) anos
pai
achega
863cf59dc6
Modificáronse 2 ficheiros con 15 adicións e 13 borrados
  1. 14 12
      kernel/modelverse_kernel/main.py
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 14 - 12
kernel/modelverse_kernel/main.py

@@ -333,6 +333,7 @@ class ModelverseKernel(object):
         print("Total printed function: ")
         func = "def " + suggested_name + "(" + ", ".join(["var_%s" % param for param in params]) + "):\n" + printed
         print(func)
+        raise primitive_functions.PrimitiveFinished(func)
 
     def jit_compile(self, task_root, inst):
         # Try to retrieve the suggested name.
@@ -347,20 +348,21 @@ class ModelverseKernel(object):
                 self.jit.jit_globals[self.jit.jitted_entry_points[inst]])
 
         compiled_func = self.jit.lookup_compiled_body(inst)
-        if compiled_func is not None:
-            raise primitive_functions.PrimitiveFinished(compiled_func)
-
-        """
-        def func(**kwargs):
-            print("KWARGS: " + str(kwargs))
-            #raise primitive_functions.PrimitiveFinished(None)
-        """
+        if compiled_func is None:
+            name = self.jit.get_global_name(inst)
+            compiled_func, = yield [("CALL_ARGS", [self.read_function, (inst,)])]
+            exec(str(compiled_func), self.jit.jit_globals)
+            print(self.jit.jit_globals)
+            compiled_func = self.jit.jit_globals[name]
+            self.jit.register_compiled(inst, compiled_func, name)
 
-        yield [("CALL_ARGS", [self.read_function, (inst,)])]
+        #raise jit.JitCompilationFailedException("FAIL")
 
-        raise jit.JitCompilationFailedException("FAIL")
-
-        raise primitive_functions.PrimitiveFinished(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:   Thu Apr  5 14:25:38 2018
+Date:   Thu Apr  5 14:36:50 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server