Browse Source

Support __primitive_return in ModelverseKernel.execute_jit

jonathanvdc 8 years ago
parent
commit
773589a0d3
1 changed files with 19 additions and 7 deletions
  1. 19 7
      kernel/modelverse_kernel/main.py

+ 19 - 7
kernel/modelverse_kernel/main.py

@@ -189,16 +189,28 @@ class ModelverseKernel(object):
             #    raise Exception("Primitive raised exception: value of None for operation %s with parameters %s" % (compiled_func, str(parameters)))
 
         # Clean up the current stack, as if a return happened
-        old_frame, =    yield [("RD", [user_frame, "prev"])]
-        lnk, =          yield [("RDE", [old_frame, "returnvalue"])]
-        _, _, _, _ =    yield [("CD", [old_frame, "returnvalue", result]),
-                               ("CD", [user_root, "frame", old_frame]),
-                               ("DE", [lnk]),
-                               ("DN", [user_frame]),
-                              ]
+        old_frame, exception_return = yield [
+            ("RD", [user_frame, "prev"]),
+            ("RD", [user_frame, primitive_functions.PRIMITIVE_RETURN_KEY])]
+
         if self.debug_info[self.username]:
             self.debug_info[self.username].pop()
 
+        if exception_return is not None:
+            # The caller has requested that we throw an exception instead of injecting
+            # the return value into the caller's frame. Read the comment at
+            # primitive_functions.PRIMITIVE_RETURN_KEY for the rationale behind this design.
+            yield [("CD", [user_root, "frame", old_frame]),
+                   ("DN", [user_frame])]
+            raise primitive_functions.PrimitiveFinished(result)
+        else:
+            lnk, =          yield [("RDE", [old_frame, "returnvalue"])]
+            _, _, _, _ =    yield [("CD", [old_frame, "returnvalue", result]),
+                                   ("CD", [user_root, "frame", old_frame]),
+                                   ("DE", [lnk]),
+                                   ("DN", [user_frame]),
+                                  ]
+
     ########################################
     ### Execute input and output methods ###
     ########################################