mruby-binding: use C implementation of Kernel#eval directly

This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-03-19 23:55:26 +09:00
parent 1c765dc37a
commit 0c8404a3e2
2 changed files with 7 additions and 19 deletions
+4 -17
View File
@@ -8,10 +8,12 @@
#include <mruby/internal.h>
#include <mruby/presym.h>
/* provided by mruby-eval */
mrb_value mrb_f_eval(mrb_state *mrb, mrb_value self);
/* provided by mruby-binding-core */
const struct RProc *mrb_binding_extract_proc(mrb_state *mrb, mrb_value binding);
struct REnv *mrb_binding_extract_env(mrb_state *mrb, mrb_value binding);
/* provided by mruby-compiler vid mruby-eval */
/* provided by mruby-compiler */
typedef mrb_bool mrb_parser_foreach_top_variable_func(mrb_state *mrb, mrb_sym sym, void *user);
void mrb_parser_foreach_top_variable(mrb_state *mrb, struct mrb_parser_state *p, mrb_parser_foreach_top_variable_func *func, void *user);
@@ -129,32 +131,17 @@ mrb_binding_eval(mrb_state *mrb, mrb_value binding)
{
binding_eval_prepare(mrb, binding);
struct RClass *c = mrb->kernel_module;
mrb_method_t m = mrb_method_search_vm(mrb, &c, MRB_SYM(eval));
mrb_callinfo *ci = mrb->c->ci;
int argc = ci->n;
mrb_value *argv = ci->stack + 1;
struct RProc *proc;
if (argc < 15) {
argv[0] = mrb_ary_new_from_values(mrb, argc, argv);
argv[1] = argv[argc]; /* copy block */
ci->n = 15;
}
if (MRB_METHOD_UNDEF_P(m)) {
mrb_method_missing(mrb, MRB_SYM(eval), binding, argv[0]);
}
mrb_ary_splice(mrb, argv[0], 1, 0, binding); /* insert binding as 2nd argument */
if (MRB_METHOD_FUNC_P(m)) {
proc = mrb_proc_new_cfunc(mrb, MRB_METHOD_FUNC(m));
MRB_PROC_SET_TARGET_CLASS(proc, c);
}
else {
proc = MRB_METHOD_PROC(m);
}
ci->u.target_class = c;
return mrb_exec_irep(mrb, binding, proc);
return mrb_f_eval(mrb, binding);
}
void
+3 -2
View File
@@ -146,8 +146,8 @@ exec_irep(mrb_state *mrb, mrb_value self, struct RProc *proc)
return mrb_exec_irep(mrb, self, proc);
}
static mrb_value
f_eval(mrb_state *mrb, mrb_value self)
mrb_value
mrb_f_eval(mrb_state *mrb, mrb_value self)
{
const char *s;
mrb_int len;
@@ -165,6 +165,7 @@ f_eval(mrb_state *mrb, mrb_value self)
mrb_assert(!MRB_PROC_CFUNC_P(proc));
return exec_irep(mrb, self, proc);
}
#define f_eval mrb_f_eval
static mrb_value
f_instance_eval(mrb_state *mrb, mrb_value self)