static void PDB_run_code(PARROT_INTERP, int argc, const char *argv[]) { new_runloop_jump_point(interp); if (setjmp(interp->current_runloop->resume)) { free_runloop_jump_point(interp); fprintf(stderr, "Caught exception\n"); return; } /* Loop to avoid exiting at program end */ do { Parrot_runcode(interp, argc, argv); interp->pdb->state |= PDB_STOPPED; } while (! (interp->pdb->state & PDB_EXIT)); free_runloop_jump_point(interp); }
void runops(PARROT_INTERP, size_t offs) { ASSERT_ARGS(runops) volatile size_t offset = offs; const int old_runloop_id = interp->current_runloop_id; int our_runloop_level = interp->current_runloop_level; int our_runloop_id = old_runloop_id; /* It is OK if the runloop ID overflows; we only ever test it for equality, so the chance of collision is slight. */ interp->current_runloop_id = our_runloop_id; #if RUNLOOP_TRACE fprintf(stderr, "[entering loop %d, level %d]\n", interp->current_runloop_id, our_runloop_level); #endif /* * STACKED_EXCEPTIONS are necessary to catch exceptions in reentered * run loops, e.g. if a delegate method throws an exception */ #if ! STACKED_EXCEPTIONS if (!interp->current_runloop) #endif { new_runloop_jump_point(interp); our_runloop_id = interp->current_runloop_id; our_runloop_level = interp->current_runloop_level; reenter: interp->current_runloop->handler_start = NULL; switch (setjmp(interp->current_runloop->resume)) { case 1: /* an exception was handled */ if (STACKED_EXCEPTIONS) free_runloop_jump_point(interp); interp->current_runloop_level = our_runloop_level - 1; interp->current_runloop_id = old_runloop_id; #if RUNLOOP_TRACE fprintf(stderr, "[handled exception; back to loop %d, level %d]\n", interp->current_runloop_id, interp->current_runloop_level); #endif return; case 2: /* Reenter the runloop from a exception thrown from C * with a pir handler */ free_runloops_until(interp, our_runloop_id); PARROT_ASSERT(interp->current_runloop->handler_start); offset = interp->current_runloop->handler_start - interp->code->base.data; /* Prevent incorrect reuse */ goto reenter; case 3: /* Reenter the runloop when finished the handling of a * exception */ free_runloops_until(interp, our_runloop_id); offset = interp->current_runloop->handler_start - interp->code->base.data; goto reenter; default: break; } } runops_int(interp, offset); interp->current_runloop->handler_start = NULL; /* Remove the current runloop marker (put it on the free list). */ if (STACKED_EXCEPTIONS || interp->current_runloop) free_runloop_jump_point(interp); #if RUNLOOP_TRACE fprintf(stderr, "[exiting loop %d, level %d]\n", our_runloop_id, our_runloop_level); #endif }