void mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v) { struct RClass * cls = c; while (c) { if (c->iv) { iv_tbl *t = c->iv; if (iv_get(mrb, t, sym, NULL)) { mrb_write_barrier(mrb, (struct RBasic*)c); iv_put(mrb, t, sym, v); return; } } c = c->super; } if (!cls->iv) { cls->iv = iv_new(mrb); } mrb_write_barrier(mrb, (struct RBasic*)cls); iv_put(mrb, cls->iv, sym, v); }
void mrb_vm_cv_set(mrb_state *mrb, mrb_sym sym, mrb_value v) { struct RClass *c = mrb->ci->proc->target_class; if (!c) c = mrb->ci->target_class; while (c) { if (c->iv) { iv_tbl *t = c->iv; if (iv_get(mrb, t, sym, NULL)) { mrb_write_barrier(mrb, (struct RBasic*)c); iv_put(mrb, t, sym, v); return; } } c = c->super; } c = mrb->ci->target_class; if (!c->iv) { c->iv = iv_new(mrb); } mrb_write_barrier(mrb, (struct RBasic*)c); iv_put(mrb, c->iv, sym, v); }
mrb_value mrb_class_find_path(mrb_state *mrb, struct RClass *c) { mrb_value outer, path; mrb_sym name; const char *str; mrb_int len; mrb_sym osym = mrb_intern_lit(mrb, "__outer__"); outer = mrb_obj_iv_get(mrb, (struct RObject*)c, osym); if (mrb_nil_p(outer)) return outer; name = find_class_sym(mrb, mrb_class_ptr(outer), c); if (name == 0) return mrb_nil_value(); str = mrb_class_name(mrb, mrb_class_ptr(outer)); path = mrb_str_new_capa(mrb, 40); mrb_str_cat_cstr(mrb, path, str); mrb_str_cat_cstr(mrb, path, "::"); str = mrb_sym2name_len(mrb, name, &len); mrb_str_cat(mrb, path, str, len); iv_del(mrb, c->iv, osym, NULL); iv_put(mrb, c->iv, mrb_intern_lit(mrb, "__classname__"), path); mrb_field_write_barrier_value(mrb, (struct RBasic*)c, path); return path; }
static iv_tbl* iv_copy(mrb_state *mrb, iv_tbl *t) { segment *seg; iv_tbl *t2; size_t i; seg = t->rootseg; t2 = iv_new(mrb); while (seg != NULL) { for (i=0; i<MRB_SEGMENT_SIZE; i++) { mrb_sym key = seg->key[i]; mrb_value val = seg->val[i]; if ((seg->next == NULL) && (i >= t->last_len)) { return t2; } iv_put(mrb, t2, key, val); } seg = seg->next; } return t2; }
mrb_value mrb_class_find_path(mrb_state *mrb, struct RClass *c) { struct RClass *outer; mrb_value path; mrb_sym name; const char *str; mrb_int len; if (detect_outer_loop(mrb, c)) return mrb_nil_value(); outer = outer_class(mrb, c); if (outer == NULL) return mrb_nil_value(); name = find_class_sym(mrb, outer, c); if (name == 0) return mrb_nil_value(); str = mrb_class_name(mrb, outer); path = mrb_str_new_capa(mrb, 40); mrb_str_cat_cstr(mrb, path, str); mrb_str_cat_cstr(mrb, path, "::"); str = mrb_sym2name_len(mrb, name, &len); mrb_str_cat(mrb, path, str, len); if (RSTRING_PTR(path)[0] != '#') { iv_del(mrb, c->iv, mrb_intern_lit(mrb, "__outer__"), NULL); iv_put(mrb, c->iv, mrb_intern_lit(mrb, "__classname__"), path); mrb_field_write_barrier_value(mrb, (struct RBasic*)c, path); } return path; }
MRB_API void mrb_mod_cv_set(mrb_state *mrb, struct RClass *c, mrb_sym sym, mrb_value v) { struct RClass * cls = c; while (c) { if (c->iv) { iv_tbl *t = c->iv; if (iv_get(mrb, t, sym, NULL)) { mrb_write_barrier(mrb, (struct RBasic*)c); iv_put(mrb, t, sym, v); return; } } c = c->super; } if (cls && cls->tt == MRB_TT_SCLASS) { mrb_value klass; klass = mrb_obj_iv_get(mrb, (struct RObject*)cls, mrb_intern_lit(mrb, "__attached__")); switch (mrb_type(klass)) { case MRB_TT_CLASS: case MRB_TT_MODULE: case MRB_TT_SCLASS: c = mrb_class_ptr(klass); break; default: c = cls; break; } } else{ c = cls; } if (!c->iv) { c->iv = iv_new(mrb); } mrb_write_barrier(mrb, (struct RBasic*)c); iv_put(mrb, c->iv, sym, v); }
void mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v) { iv_tbl *t = obj->iv; if (!t) { t = obj->iv = iv_new(mrb); } mrb_write_barrier(mrb, (struct RBasic*)obj); iv_put(mrb, t, sym, v); }
MRB_API void mrb_gv_set(mrb_state *mrb, mrb_sym sym, mrb_value v) { iv_tbl *t; if (!mrb->globals) { mrb->globals = iv_new(mrb); } t = mrb->globals; iv_put(mrb, t, sym, v); }
void mrb_gv_set(mrb_state *mrb, mrb_sym sym, mrb_value v) { iv_tbl *t; if (!mrb->globals) { t = mrb->globals = iv_new(mrb); } else { t = mrb->globals; } iv_put(mrb, t, sym, v); }
void mrb_obj_iv_ifnone(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v) { iv_tbl *t = obj->iv; if (!t) { t = obj->iv = iv_new(mrb); } else if (iv_get(mrb, t, sym, &v)) { return; } mrb_write_barrier(mrb, (struct RBasic*)obj); iv_put(mrb, t, sym, v); }
MRB_API void mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v) { iv_tbl *t = obj->iv; if (MRB_FROZEN_P(obj)) { mrb_raisef(mrb, E_RUNTIME_ERROR, "can't modify frozen %S", mrb_obj_value(obj)); } if (!t) { t = obj->iv = iv_new(mrb); } mrb_write_barrier(mrb, (struct RBasic*)obj); iv_put(mrb, t, sym, v); }
MRB_API void mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v) { iv_tbl *t; if (MRB_FROZEN_P(obj)) { mrb_raisef(mrb, E_FROZEN_ERROR, "can't modify frozen %S", mrb_obj_value(obj)); } assign_class_name(mrb, obj, sym, v); if (!obj->iv) { obj->iv = iv_new(mrb); } t = obj->iv; iv_put(mrb, t, sym, v); mrb_write_barrier(mrb, (struct RBasic*)obj); }