diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | eval.c | 69 | ||||
-rw-r--r-- | gc.c | 1 | ||||
-rw-r--r-- | intern.h | 1 | ||||
-rw-r--r-- | parse.y | 3 | ||||
-rw-r--r-- | re.c | 1 | ||||
-rw-r--r-- | variable.c | 18 |
7 files changed, 35 insertions, 63 deletions
@@ -1,3 +1,8 @@ +Tue Feb 12 01:21:34 2002 Yukihiro Matsumoto <matz@ruby-lang.org> + + * parse.y (assignable): should emit CVASGN within the method + body. + Sun Feb 10 16:52:53 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp> * ruby.c (load_file): avoid SEGV on '#' only input. @@ -1835,24 +1835,19 @@ is_defined(self, node, buf) break; case NODE_CVAR: - if (!ruby_frame || !ruby_frame->last_class || - !FL_TEST(ruby_frame->last_class, FL_SINGLETON)) { - if (NIL_P(ruby_cbase)) { - if (rb_cvar_defined(CLASS_OF(self), node->nd_vid)) { - return "class variable"; - } - break; + if (NIL_P(ruby_cbase)) { + if (rb_cvar_defined(CLASS_OF(self), node->nd_vid)) { + return "class variable"; } - if (!FL_TEST(ruby_cbase, FL_SINGLETON)) { - if (rb_cvar_defined(ruby_cbase, node->nd_vid)) { - return "class variable"; - } - break; + break; + } + if (!FL_TEST(ruby_cbase, FL_SINGLETON)) { + if (rb_cvar_defined(ruby_cbase, node->nd_vid)) { + return "class variable"; } + break; } - /* fall through */ - case NODE_CVAR2: - if (rb_cvar_defined(rb_cvar_singleton(self), node->nd_vid)) { + if (rb_cvar_defined(rb_iv_get(ruby_cbase, "__attached__"), node->nd_vid)) { return "class variable"; } break; @@ -2727,17 +2722,16 @@ rb_eval(self, n) rb_raise(rb_eTypeError, "no class/module to define class variable"); } result = rb_eval(self, node->nd_value); - if (FL_TEST(ruby_cbase, FL_SINGLETON)) { - rb_cvar_declare(rb_cvar_singleton(rb_iv_get(ruby_cbase, "__attached__")), - node->nd_vid, result); - break; + result = rb_eval(self, node->nd_value); + if (ruby_verbose && FL_TEST(ruby_cbase, FL_SINGLETON)) { + rb_warn("declaring singleton class variable"); } rb_cvar_declare(ruby_cbase, node->nd_vid, result); break; case NODE_CVASGN: result = rb_eval(self, node->nd_value); - rb_cvar_set(rb_cvar_singleton(self), node->nd_vid, result); + rb_cvar_set(ruby_cbase, node->nd_vid, result); break; case NODE_LVAR: @@ -2763,21 +2757,16 @@ rb_eval(self, n) result = ev_const_get(RNODE(ruby_frame->cbase), node->nd_vid, self); break; - case NODE_CVAR: /* normal method */ - if (!ruby_frame || !ruby_frame->last_class || - !FL_TEST(ruby_frame->last_class, FL_SINGLETON)) { - if (NIL_P(ruby_cbase)) { - result = rb_cvar_get(CLASS_OF(self), node->nd_vid); - break; - } - if (!FL_TEST(ruby_cbase, FL_SINGLETON)) { - result = rb_cvar_get(ruby_cbase, node->nd_vid); - break; - } + case NODE_CVAR: + if (NIL_P(ruby_cbase)) { + result = rb_cvar_get(CLASS_OF(self), node->nd_vid); + break; } - /* fall through */ - case NODE_CVAR2: /* singleton method */ - result = rb_cvar_get(rb_cvar_singleton(self), node->nd_vid); + if (!FL_TEST(ruby_cbase, FL_SINGLETON)) { + result = rb_cvar_get(ruby_cbase, node->nd_vid); + break; + } + result = rb_cvar_get(rb_iv_get(ruby_cbase, "__attached__"), node->nd_vid); break; case NODE_BLOCK_ARG: @@ -3818,14 +3807,14 @@ assign(self, lhs, val, check) break; case NODE_CVDECL: - if (!FL_TEST(ruby_cbase, FL_SINGLETON)) { - rb_cvar_declare(ruby_cbase, lhs->nd_vid, val); - break; + if (ruby_verbose && FL_TEST(ruby_cbase, FL_SINGLETON)) { + rb_warn("declaring singleton class variable"); } - self = rb_iv_get(ruby_cbase, "__attached__"); - /* fall through */ + rb_cvar_declare(ruby_cbase, lhs->nd_vid, val); + break; + case NODE_CVASGN: - rb_cvar_set(rb_cvar_singleton(self), lhs->nd_vid, val); + rb_cvar_set(ruby_cbase, lhs->nd_vid, val); break; case NODE_MASGN: @@ -560,7 +560,6 @@ rb_gc_mark(ptr) case NODE_DVAR: case NODE_IVAR: case NODE_CVAR: - case NODE_CVAR2: case NODE_NTH_REF: case NODE_BACK_REF: case NODE_ALIAS: @@ -388,7 +388,6 @@ void rb_cvar_declare _((VALUE, ID, VALUE)); VALUE rb_cvar_defined _((VALUE, ID)); void rb_cvar_set _((VALUE, ID, VALUE)); VALUE rb_cvar_get _((VALUE, ID)); -VALUE rb_cvar_singleton _((VALUE)); void rb_cv_set _((VALUE, const char *, VALUE)); VALUE rb_cv_get _((VALUE, const char *)); void rb_define_class_variable _((VALUE, const char *, VALUE)); @@ -4129,7 +4129,6 @@ gettable(id) return NEW_CONST(id); } else if (is_class_id(id)) { - if (in_single) return NEW_CVAR2(id); return NEW_CVAR(id); } rb_bug("invalid id for gettable"); @@ -4187,7 +4186,7 @@ assignable(id, val) return NEW_CDECL(id, val); } else if (is_class_id(id)) { - if (in_single) return NEW_CVASGN(id, val); + if (in_def || in_single) return NEW_CVASGN(id, val); return NEW_CVDECL(id, val); } else { @@ -611,7 +611,6 @@ rb_reg_search(re, str, pos, reverse) else { range = RSTRING(str)->len - pos; } - regs.allocated = 0; result = re_search(RREGEXP(re)->ptr,RSTRING(str)->ptr,RSTRING(str)->len, pos, range, ®s); diff --git a/variable.c b/variable.c index 76bc8311a8..44ce2a29e1 100644 --- a/variable.c +++ b/variable.c @@ -1357,20 +1357,6 @@ rb_define_global_const(name, val) rb_define_const(rb_cObject, name, val); } -VALUE -rb_cvar_singleton(obj) - VALUE obj; -{ - switch (TYPE(obj)) { - case T_MODULE: - case T_CLASS: - return obj; - default: - break; - } - return CLASS_OF(obj); -} - void rb_cvar_set(klass, id, val) VALUE klass; @@ -1509,10 +1495,6 @@ rb_mod_class_variables(obj) { VALUE ary = rb_ary_new(); - if (FL_TEST(obj, FL_SINGLETON)) { - obj = rb_cvar_singleton(rb_iv_get(obj, "__attached__")); - } - for (;;) { if (RCLASS(obj)->iv_tbl) { st_foreach(RCLASS(obj)->iv_tbl, cv_i, ary); |