From 58e94427377952b0953bcdf2d544c62b0fefd4a6 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 10 Jan 2021 10:20:01 +0900 Subject: Unified `target_class` and `env` of `mrb_callinfo` If there is `env`, `env->c` means `target_class`. --- include/mruby.h | 6 ++++-- include/mruby/proc.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/mruby.h b/include/mruby.h index 79eb5e26f..9f6dde746 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -152,12 +152,14 @@ typedef struct { mrb_sym mid; const struct RProc *proc; mrb_value *stackent; - struct REnv *env; const mrb_code *pc; /* return address */ const mrb_code *err; /* error position */ int16_t argc; int16_t acc; - struct RClass *target_class; + union { + struct REnv *env; + struct RClass *target_class; + } u; } mrb_callinfo; enum mrb_fiber_state { diff --git a/include/mruby/proc.h b/include/mruby/proc.h index f8681b40b..b4d0927a9 100644 --- a/include/mruby/proc.h +++ b/include/mruby/proc.h @@ -136,6 +136,67 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx); MRB_API mrb_value mrb_load_proc(mrb_state *mrb, const struct RProc *proc); +static inline struct RClass * +mrb_vm_ci_target_class(const mrb_callinfo *ci) +{ + if (ci->u.env && ci->u.env->tt == MRB_TT_ENV) { + return ci->u.env->c; + } + else { + return ci->u.target_class; + } +} + +static inline void +mrb_vm_ci_target_class_set(mrb_callinfo *ci, struct RClass *tc) +{ + struct REnv *e = ci->u.env; + if (e) { + if (e->tt == MRB_TT_ENV) { + e->c = tc; + } + else { + ci->u.target_class = tc; + } + } +} + +static inline struct REnv * +mrb_vm_ci_env(const mrb_callinfo *ci) +{ + if (ci->u.env && ci->u.env->tt == MRB_TT_ENV) { + return ci->u.env; + } + else { + return NULL; + } +} + +static inline void +mrb_vm_ci_env_set(mrb_callinfo *ci, struct REnv *e) +{ + if (ci->u.env) { + if (ci->u.env->tt == MRB_TT_ENV) { + if (e) { + e->c = ci->u.env->c; + ci->u.env = e; + } + else { + ci->u.target_class = ci->u.env->c; + } + } + else { + if (e) { + e->c = ci->u.target_class; + ci->u.env = e; + } + } + } + else { + ci->u.env = e; + } +} + MRB_END_DECL #endif /* MRUBY_PROC_H */ -- cgit v1.2.3