Exemple #1
0
void
rb_vm_jump_tag_but_local_jump(int state, VALUE val)
{
    if (val != Qnil) {
	VALUE exc = rb_vm_make_jump_tag_but_local_jump(state, val);
	rb_exc_raise(exc);
    }
    JUMP_TAG(state);
}
Exemple #2
0
void
rb_fiber_start(void)
{
    rb_thread_t *th = GET_THREAD();
    rb_fiber_t *fib;
    rb_context_t *cont;
    rb_proc_t *proc;
    int state;

    GetFiberPtr(th->fiber, fib);
    cont = &fib->cont;

    TH_PUSH_TAG(th);
    if ((state = EXEC_TAG()) == 0) {
	int argc;
	VALUE *argv, args;
	GetProcPtr(cont->saved_thread.first_proc, proc);
	args = cont->value;
	argv = (argc = cont->argc) > 1 ? RARRAY_PTR(args) : &args;
	cont->value = Qnil;
	th->errinfo = Qnil;
	th->local_lfp = proc->block.lfp;
	th->local_svar = Qnil;

	fib->status = RUNNING;
	cont->value = rb_vm_invoke_proc(th, proc, proc->block.self, argc, argv, 0);
    }
    TH_POP_TAG();

    if (state) {
	if (TAG_RAISE) {
	    th->thrown_errinfo = th->errinfo;
	}
	else {
	    th->thrown_errinfo =
	      rb_vm_make_jump_tag_but_local_jump(state, th->errinfo);
	}
	RUBY_VM_SET_INTERRUPT(th);
    }

    rb_fiber_terminate(fib);
    rb_bug("rb_fiber_start: unreachable");
}
Exemple #3
0
static int
rb_load_internal0(rb_thread_t *th, VALUE fname, int wrap)
{
    int state;
    volatile VALUE wrapper = th->top_wrapper;
    volatile VALUE self = th->top_self;
    volatile int loaded = FALSE;
    volatile int mild_compile_error;
#if !defined __GNUC__
    rb_thread_t *volatile th0 = th;
#endif

    th->errinfo = Qnil; /* ensure */

    if (!wrap) {
	th->top_wrapper = 0;
    }
    else {
	/* load in anonymous module as toplevel */
	th->top_self = rb_obj_clone(rb_vm_top_self());
	th->top_wrapper = rb_module_new();
	rb_extend_object(th->top_self, th->top_wrapper);
    }

    mild_compile_error = th->mild_compile_error;
    TH_PUSH_TAG(th);
    state = EXEC_TAG();
    if (state == 0) {
	NODE *node;
	rb_iseq_t *iseq;

	th->mild_compile_error++;
	node = (NODE *)rb_load_file_str(fname);
	loaded = TRUE;
	iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), NULL);
	th->mild_compile_error--;
	rb_iseq_eval(iseq);
    }
    TH_POP_TAG();

#if !defined __GNUC__
    th = th0;
    fname = RB_GC_GUARD(fname);
#endif
    th->mild_compile_error = mild_compile_error;
    th->top_self = self;
    th->top_wrapper = wrapper;

    if (!loaded && !FIXNUM_P(th->errinfo)) {
	/* an error on loading don't include INT2FIX(TAG_FATAL) see r35625 */
	return TAG_RAISE;
    }
    if (state) {
	VALUE exc = rb_vm_make_jump_tag_but_local_jump(state, Qundef);
	if (NIL_P(exc)) return state;
	th->errinfo = exc;
	return TAG_RAISE;
    }

    if (!NIL_P(th->errinfo)) {
	/* exception during load */
	return TAG_RAISE;
    }
    return state;
}
Exemple #4
0
static int
rb_load_internal0(rb_execution_context_t *ec, VALUE fname, int wrap)
{
    enum ruby_tag_type state;
    rb_thread_t *th = rb_ec_thread_ptr(ec);
    volatile VALUE wrapper = th->top_wrapper;
    volatile VALUE self = th->top_self;
#if !defined __GNUC__
    rb_thread_t *volatile th0 = th;
#endif

    th->ec->errinfo = Qnil; /* ensure */

    if (!wrap) {
	th->top_wrapper = 0;
    }
    else {
	/* load in anonymous module as toplevel */
	th->top_self = rb_obj_clone(rb_vm_top_self());
	th->top_wrapper = rb_module_new();
	rb_extend_object(th->top_self, th->top_wrapper);
    }

    EC_PUSH_TAG(th->ec);
    state = EC_EXEC_TAG();
    if (state == TAG_NONE) {
	rb_ast_t *ast;
	const rb_iseq_t *iseq;

	if ((iseq = rb_iseq_load_iseq(fname)) != NULL) {
	    /* OK */
	}
	else {
	    VALUE parser = rb_parser_new();
	    rb_parser_set_context(parser, NULL, FALSE);
	    ast = (rb_ast_t *)rb_parser_load_file(parser, fname);
	    iseq = rb_iseq_new_top(&ast->body, rb_fstring_lit("<top (required)>"),
			    fname, rb_realpath_internal(Qnil, fname, 1), NULL);
	    rb_ast_dispose(ast);
	}
        rb_exec_event_hook_script_compiled(ec, iseq, Qnil);
        rb_iseq_eval(iseq);
    }
    EC_POP_TAG();

#if !defined __GNUC__
    th = th0;
    fname = RB_GC_GUARD(fname);
#endif
    th->top_self = self;
    th->top_wrapper = wrapper;

    if (state) {
	/* usually state == TAG_RAISE only, except for
	 * rb_iseq_load_iseq case */
	VALUE exc = rb_vm_make_jump_tag_but_local_jump(state, Qundef);
	if (NIL_P(exc)) return state;
	th->ec->errinfo = exc;
	return TAG_RAISE;
    }

    if (!NIL_P(th->ec->errinfo)) {
	/* exception during load */
	return TAG_RAISE;
    }
    return state;
}