From 8f2c62407c0659d84126545e19505a851059e750 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 20 Nov 2017 06:21:22 +0900 Subject: Add `MRB_METHOD_TABLE_INLINE` option. Now the method tables (in classes/modules and caches) keeps C function pointers without wrapping in `struct RProc` objects. For the sake of portability, `mrb_method_t` is represented by the struct and union, but if the most significant bit of the pointer is not used by the platform, `mrb_method_t` should be packed in `uintptr_t` to reduce memory usage. `MRB_METHOD_TABLE_INLINE` is turned on by default for linux. --- src/proc.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/proc.c') diff --git a/src/proc.c b/src/proc.c index 69a9c0299..bd93de618 100644 --- a/src/proc.c +++ b/src/proc.c @@ -99,7 +99,7 @@ mrb_proc_new_cfunc(mrb_state *mrb, mrb_func_t func) p = (struct RProc*)mrb_obj_alloc(mrb, MRB_TT_PROC, mrb->proc_class); p->body.func = func; - p->flags |= MRB_PROC_CFUNC; + p->flags |= MRB_PROC_CFUNC_FL; p->upper = 0; p->e.target_class = 0; @@ -141,11 +141,12 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx) { struct RProc *p = mrb->c->ci->proc; - struct REnv *e = MRB_PROC_ENV(p); + struct REnv *e; - if (!MRB_PROC_CFUNC_P(p)) { + if (!p || !MRB_PROC_CFUNC_P(p)) { mrb_raise(mrb, E_TYPE_ERROR, "Can't get cfunc env from non-cfunc proc."); } + e = MRB_PROC_ENV(p); if (!e) { mrb_raise(mrb, E_TYPE_ERROR, "Can't get cfunc env from cfunc Proc without REnv."); } @@ -216,12 +217,6 @@ mrb_proc_cfunc_p(struct RProc *p) return MRB_PROC_CFUNC_P(p); } -mrb_value -mrb_proc_call_cfunc(mrb_state *mrb, struct RProc *p, mrb_value self) -{ - return (p->body.func)(mrb, self); -} - /* 15.2.17.4.2 */ static mrb_value mrb_proc_arity(mrb_state *mrb, mrb_value self) @@ -293,7 +288,8 @@ proc_lambda(mrb_state *mrb, mrb_value self) void mrb_init_proc(mrb_state *mrb) { - struct RProc *m; + struct RProc *p; + mrb_method_t m; mrb_irep *call_irep = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep)); static const mrb_irep mrb_irep_zero = { 0 }; @@ -307,7 +303,8 @@ mrb_init_proc(mrb_state *mrb) mrb_define_method(mrb, mrb->proc_class, "initialize_copy", mrb_proc_init_copy, MRB_ARGS_REQ(1)); mrb_define_method(mrb, mrb->proc_class, "arity", mrb_proc_arity, MRB_ARGS_NONE()); - m = mrb_proc_new(mrb, call_irep); + p = mrb_proc_new(mrb, call_irep); + MRB_METHOD_FROM_PROC(m, p); mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern_lit(mrb, "call"), m); mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern_lit(mrb, "[]"), m); -- cgit v1.2.3