From 72f2d2a00d8ae3861a15ca92bf9322951a22b6cf Mon Sep 17 00:00:00 2001 From: matz Date: Sun, 4 Feb 2007 19:17:33 +0000 Subject: * parse.y (rb_compose_ivar2): function to create a new ivar2 symbol from a symbol and a class. back-ported from matzruby. * parse.y (rb_decompose_ivar2): reverse function of rb_compose_ivar2(). * marshal.c (w_symbol): support class local instance variables. * marshal.c (r_object0): ditto. * compile.c (defined_expr): ditto. * compile.c (iseq_compile_each): ditto. * insns.def: add two new instructions: getinstancevariable2 and setinstancevariable2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- insns.def | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'insns.def') diff --git a/insns.def b/insns.def index 99401cc395..b84d07f290 100644 --- a/insns.def +++ b/insns.def @@ -186,6 +186,22 @@ getinstancevariable 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())); + val = rb_ivar_get(GET_SELF(), id); +} + /** @c variable @e set instance variable id of obj as val. @@ -200,6 +216,22 @@ setinstancevariable 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())); + rb_ivar_set(GET_SELF(), id, val); +} + /** @c variable @e get class variable id of klass as val. @@ -901,6 +933,12 @@ defined expr_type = "instance-variable"; } break; + case DEFINED_IVAR2: + klass = get_cref(GET_ISEQ(), GET_LFP())->nd_clss; + if (rb_ivar_defined(GET_SELF(), rb_compose_ivar2(SYM2ID(obj), klass))) { + expr_type = "class local instance-variable"; + } + break; case DEFINED_GVAR: if (rb_gvar_defined((struct global_entry *)(obj & ~1))) { expr_type = "global-variable"; -- cgit v1.2.3