mrb_value mrb_yield(mrb_state *mrb, mrb_value b, mrb_value v) { struct RProc *p = mrb_proc_ptr(b); return mrb_yield_internal(mrb, b, 1, &v, mrb->stack[0], p->target_class); }
mrb_value mrb_yield_argv(mrb_state *mrb, mrb_value b, int argc, mrb_value *argv) { struct RProc *p = mrb_proc_ptr(b); return mrb_yield_internal(mrb, b, argc, argv, mrb->stack[0], p->target_class); }
static mrb_value mrb_obj_instance_exec(mrb_state *mrb, mrb_value self) { mrb_value *argv; int argc; mrb_value blk; struct RClass *c; mrb_get_args(mrb, "*&", &argv, &argc, &blk); if (mrb_nil_p(blk)) { mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given"); } switch (mrb_type(self)) { case MRB_TT_SYMBOL: case MRB_TT_FIXNUM: case MRB_TT_FLOAT: c = 0; break; default: c = mrb_class_ptr(mrb_singleton_class(mrb, self)); break; } return mrb_yield_internal(mrb, blk, argc, argv, self, c); }
mrb_value mrb_mod_module_eval(mrb_state *mrb, mrb_value mod) { mrb_value a, b; struct RClass *c; if (mrb_get_args(mrb, "|S&", &a, &b) == 1) { mrb_raise(mrb, E_NOTIMP_ERROR, "module_eval/class_eval with string not implemented"); } c = mrb_class_ptr(mod); return mrb_yield_internal(mrb, b, 0, 0, mod, c); }
static void eval_load_irep(mrb_state *mrb, mrb_irep *irep) { int ai; struct RProc *proc; replace_stop_with_return(mrb, irep); proc = mrb_proc_new(mrb, irep); proc->target_class = mrb->object_class; ai = mrb_gc_arena_save(mrb); mrb_yield_internal(mrb, mrb_obj_value(proc), 0, NULL, mrb_top_self(mrb), mrb->object_class); mrb_gc_arena_restore(mrb, ai); }
/* * call-seq: * obj.instance_eval {| | block } -> obj * * Evaluates the given block,within the context of the receiver (_obj_). * In order to set the context, the variable +self+ is set to _obj_ while * the code is executing, giving the code access to _obj_'s * instance variables. In the version of <code>instance_eval</code> * that takes a +String+, the optional second and third * parameters supply a filename and starting line number that are used * when reporting compilation errors. * * class KlassWithSecret * def initialize * @secret = 99 * end * end * k = KlassWithSecret.new * k.instance_eval { @secret } #=> 99 */ mrb_value mrb_obj_instance_eval(mrb_state *mrb, mrb_value self) { mrb_value a, b; mrb_value cv; struct RClass *c; if (mrb_get_args(mrb, "|S&", &a, &b) == 1) { mrb_raise(mrb, E_NOTIMP_ERROR, "instance_eval with string not implemented"); } switch (mrb_type(self)) { case MRB_TT_SYMBOL: case MRB_TT_FIXNUM: case MRB_TT_FLOAT: c = 0; break; default: cv = mrb_singleton_class(mrb, self); c = mrb_class_ptr(cv); } return mrb_yield_internal(mrb, b, 0, 0, self, c); }