Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created August 4, 2009 17:54
Show Gist options
  • Select an option

  • Save methodmissing/161379 to your computer and use it in GitHub Desktop.

Select an option

Save methodmissing/161379 to your computer and use it in GitHub Desktop.
static void
return_jump(retval)
VALUE retval;
{
struct tag *tt = prot_tag;
int yield = Qfalse;
if (retval == Qundef) retval = Qnil;
while (tt) {
if (tt->tag == PROT_YIELD) {
yield = Qtrue;
tt = tt->prev;
}
if (tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) {
tt->dst = (VALUE)ruby_frame->uniq;
tt->retval = retval;
JUMP_TAG(TAG_RETURN);
}
if (tt->tag == PROT_LAMBDA && !yield) {
tt->dst = (VALUE)tt->frame->uniq;
tt->retval = retval;
JUMP_TAG(TAG_RETURN);
}
if (tt->tag == PROT_THREAD) {
rb_raise(rb_eThreadError, "return can't jump across threads");
}
tt = tt->prev;
}
localjump_error("unexpected return", retval, TAG_RETURN);
}
struct tag {
rb_jmpbuf_t buf;
struct FRAME *frame;
struct iter *iter;
VALUE tag;
VALUE retval;
struct SCOPE *scope;
VALUE dst;
struct tag *prev;
int blkid;
};
static struct tag *prot_tag;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment