remove origin member to implement prepend from struct RClass; ref #2885

instead origin is saved in ICLASS with MRB_FLAG_IS_ORIGIN set.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2015-09-05 02:01:02 +09:00
parent 8bb7962eb8
commit 2550edd570
4 changed files with 49 additions and 36 deletions
+9 -1
View File
@@ -16,7 +16,6 @@ struct RClass {
struct iv_tbl *iv;
struct kh_mt *mt;
struct RClass *super;
struct RClass *origin;
};
#define mrb_class_ptr(v) ((struct RClass*)(mrb_ptr(v)))
@@ -50,7 +49,16 @@ mrb_class(mrb_state *mrb, mrb_value v)
}
// TODO: figure out where to put user flags
#define MRB_FLAG_IS_PREPENDED (1 << 19)
#define MRB_FLAG_IS_ORIGIN (1 << 20)
#define MRB_CLASS_ORIGIN(c) do {\
if (c->flags & MRB_FLAG_IS_PREPENDED) {\
c = c->super;\
while (!(c->flags & MRB_FLAG_IS_ORIGIN)) {\
c = c->super;\
}\
}\
} while (0)
#define MRB_INSTANCE_TT_MASK (0xFF)
#define MRB_SET_INSTANCE_TT(c, tt) c->flags = ((c->flags & ~MRB_INSTANCE_TT_MASK) | (char)tt)
#define MRB_INSTANCE_TT(c) (enum mrb_vtype)(c->flags & MRB_INSTANCE_TT_MASK)