diff --git a/ChangeLog b/ChangeLog index ebb68e18da..bcc4770838 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Tue Feb 6 14:15:34 2007 Koichi Sasada + + * compile.c, insns.def: remove (get|set)instancevariable2 and add a + operand is_local to (get|set)instancevariable. + + * yarvtest/test_class.rb: add a test for class local instance variable. + + * parse.y (rb_decompose_ivar2): remove unused variable oid. + + * tool/insns2vm.rb: remove needless require. + Tue Feb 6 11:18:41 2007 Shugo Maeda * lib/net/ftp.rb: check the control connection on EPIPE. diff --git a/compile.c b/compile.c index 54a806ed99..0329a0ef1d 100644 --- a/compile.c +++ b/compile.c @@ -3323,22 +3323,15 @@ iseq_compile_each(yarv_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) (((long)node->nd_entry) | 1)); break; } - case NODE_IASGN:{ - COMPILE(ret, "lvalue", node->nd_value); - if (!poped) { - ADD_INSN(ret, nd_line(node), dup); - } - ADD_INSN1(ret, nd_line(node), setinstancevariable, - ID2SYM(node->nd_vid)); - break; - } + case NODE_IASGN: case NODE_IASGN2:{ + int is_local = (nd_type(node) == NODE_IVAR2) ? 1 : 0; COMPILE(ret, "lvalue", node->nd_value); if (!poped) { ADD_INSN(ret, nd_line(node), dup); } - ADD_INSN1(ret, nd_line(node), setinstancevariable2, - ID2SYM(node->nd_vid)); + ADD_INSN2(ret, nd_line(node), setinstancevariable, + ID2SYM(node->nd_vid), INT2FIX(is_local)); break; } case NODE_CDECL:{ @@ -3909,19 +3902,14 @@ iseq_compile_each(yarv_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) } break; } - case NODE_IVAR:{ - debugi("nd_vid", node->nd_vid); - if (!poped) { - ADD_INSN1(ret, nd_line(node), getinstancevariable, - ID2SYM(node->nd_vid)); - } - break; - } + case NODE_IVAR: case NODE_IVAR2:{ + int is_local = (nd_type(node) == NODE_IVAR2) ? 1 : 0; + debugi("nd_vid", node->nd_vid); if (!poped) { - ADD_INSN1(ret, nd_line(node), getinstancevariable2, - ID2SYM(node->nd_vid)); + ADD_INSN2(ret, nd_line(node), getinstancevariable, + ID2SYM(node->nd_vid), INT2FIX(is_local)); } break; } diff --git a/insns.def b/insns.def index b84d07f290..dab579d4fc 100644 --- a/insns.def +++ b/insns.def @@ -175,60 +175,38 @@ setdynamic /** @c variable @e get instance variable id of obj. + if is_local is not 0, search as class local variable. @j obj のインスタンス変数 id を得る。 + もし is_local が !0 ならクラスローカル変数を得る */ DEFINE_INSN getinstancevariable -(ID id) +(ID id, num_t is_local) () (VALUE val) { - val = rb_ivar_get(GET_SELF(), id); -} - -/** - @c variable - @e get class local instance variable id of obj. - @j obj のクラスローカルインスタンス変数 id を得る。 - */ -DEFINE_INSN -getinstancevariable2 -(ID id) -() -(VALUE val) -{ - /* need to cache composed id */ - id = rb_compose_ivar2(id, eval_get_cvar_base(th, GET_ISEQ())); + if (is_local) { + id = rb_compose_ivar2(id, eval_get_cvar_base(th, GET_ISEQ())); + } val = rb_ivar_get(GET_SELF(), id); } /** @c variable @e set instance variable id of obj as val. + if is_local is not 0, search as class local variable. @j obj のインスタンス変数を val にする。 + もし is_local が !0 ならクラスローカル変数を得る */ DEFINE_INSN setinstancevariable -(ID id) +(ID id, num_t is_local) (VALUE val) () { - rb_ivar_set(GET_SELF(), id, val); -} - -/** - @c variable - @e set class local instance variable id of obj as val. - @j obj のクラスローカルインスタンス変数を val にする。 - */ -DEFINE_INSN -setinstancevariable2 -(ID id) -(VALUE val) -() -{ - /* need to cache composed id */ - id = rb_compose_ivar2(id, eval_get_cvar_base(th, GET_ISEQ())); + if (is_local) { + id = rb_compose_ivar2(id, eval_get_cvar_base(th, GET_ISEQ())); + } rb_ivar_set(GET_SELF(), id, val); } diff --git a/parse.y b/parse.y index 3f783af352..5894cea463 100644 --- a/parse.y +++ b/parse.y @@ -8592,7 +8592,6 @@ ID rb_decompose_ivar2(ID id, VALUE *klassp) { struct ivar2_key *kp; - ID oid; if (!st_lookup(global_symbols.id_ivar2, (st_data_t)id, (st_data_t *)&kp)) { return id; diff --git a/tool/insns2vm.rb b/tool/insns2vm.rb index 5ed10b62e5..4fecf0a701 100644 --- a/tool/insns2vm.rb +++ b/tool/insns2vm.rb @@ -1116,8 +1116,6 @@ class InsnsDef insns.each{|insn| size = insn.unifs.size if size > 0 - require 'pp' - insn.unifs.sort_by{|unif| -unif[1].size}.each_with_index{|unif, i| uni_insn, uni_insns = *unif diff --git a/yarvtest/test_class.rb b/yarvtest/test_class.rb index 1eab39f0d5..488b3ccfd9 100644 --- a/yarvtest/test_class.rb +++ b/yarvtest/test_class.rb @@ -749,5 +749,24 @@ class TestClass < YarvTestBase :ok } end + + def test_ivar2 + ae %q{ + class C + def initialize + @_c = 1 + end + end + + class D < C + def initialize + super + @_d = 2 + end + end + + D.new.instance_variables + } + end end