summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authordearblue <[email protected]>2021-01-10 10:20:01 +0900
committerdearblue <[email protected]>2021-01-10 13:23:28 +0900
commit58e94427377952b0953bcdf2d544c62b0fefd4a6 (patch)
treeca0092df0d3e983166b0753a463663b583a6d414 /include
parentb210cfa34ea9e0d288d35b3c9b78c98d33f25dae (diff)
downloadmruby-58e94427377952b0953bcdf2d544c62b0fefd4a6.tar.gz
mruby-58e94427377952b0953bcdf2d544c62b0fefd4a6.zip
Unified `target_class` and `env` of `mrb_callinfo`
If there is `env`, `env->c` means `target_class`.
Diffstat (limited to 'include')
-rw-r--r--include/mruby.h6
-rw-r--r--include/mruby/proc.h61
2 files changed, 65 insertions, 2 deletions
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 */