Project

General

Profile

Feature #12093 » 0001-RubyVM-InstructionSequence-eval_with.patch

dalehamel (Dale Hamel), 07/23/2019 04:35 AM

View differences:

iseq.c
return rb_iseq_eval(iseqw_check(self));
}
/*
* call-seq:
* iseq.eval_with(binding) -> obj
*
* Evaluates the instruction sequence and returns the result.
*
* obj = Struct.new(:a, :b).new(1, 2)
* bind = obj.instance_eval {binding}
* RubyVM::InstructionSequence.compile("a + b").eval_with(bind) #=> 3
*/
static VALUE
iseq_eval_with(VALUE self, VALUE scope)
{
rb_secure(1);
return rb_iseq_eval_in_scope(iseqw_check(self), scope);
}
/*
* Returns a human-readable string representation of this instruction
* sequence, including the #label and #path.
......
rb_define_method(rb_cISeq, "disassemble", iseqw_disasm, 0);
rb_define_method(rb_cISeq, "to_a", iseqw_to_a, 0);
rb_define_method(rb_cISeq, "eval", iseqw_eval, 0);
rb_define_method(rb_cISeq, "eval_with", iseq_eval_with, 1);
rb_define_method(rb_cISeq, "to_binary", iseqw_to_binary, -1);
rb_define_singleton_method(rb_cISeq, "load_from_binary", iseqw_s_load_from_binary, 1);
vm.c
return val;
}
VALUE
rb_iseq_eval_in_scope(const rb_iseq_t *iseq, VALUE scope)
{
rb_thread_t *th = GET_THREAD();
rb_binding_t *bind = rb_check_typeddata(scope, &ruby_binding_data_type);
struct rb_block *base_block = &bind->block;
if (iseq->body->local_table_size > 0) {
vm_bind_update_env(bind, vm_make_env_object(th, th->cfp));
}
#if 0
iseq_set_parent_block(iseq, base_block);
iseq_set_local_table(iseq, rb_vm_cref()->nd_tbl);
#endif
vm_set_eval_stack(th, iseq, 0, base_block);
return vm_exec(th);
}
VALUE
rb_iseq_eval_main(const rb_iseq_t *iseq)
{
vm_core.h
/* functions about thread/vm execution */
RUBY_SYMBOL_EXPORT_BEGIN
VALUE rb_iseq_eval(const rb_iseq_t *iseq);
VALUE rb_iseq_eval_in_scope(const rb_iseq_t *iseq, VALUE scope);
VALUE rb_iseq_eval_main(const rb_iseq_t *iseq);
VALUE rb_iseq_path(const rb_iseq_t *iseq);
VALUE rb_iseq_realpath(const rb_iseq_t *iseq);
(2-2/2)