зеркало из https://github.com/github/ruby.git
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
d4d5f27077
Коммит
42ce75cdff
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Tue Feb 6 14:15:34 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* 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 <shugo@ruby-lang.org>
|
Tue Feb 6 11:18:41 2007 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* lib/net/ftp.rb: check the control connection on EPIPE.
|
* lib/net/ftp.rb: check the control connection on EPIPE.
|
||||||
|
|
30
compile.c
30
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));
|
(((long)node->nd_entry) | 1));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NODE_IASGN:{
|
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_IASGN2:{
|
case NODE_IASGN2:{
|
||||||
|
int is_local = (nd_type(node) == NODE_IVAR2) ? 1 : 0;
|
||||||
COMPILE(ret, "lvalue", node->nd_value);
|
COMPILE(ret, "lvalue", node->nd_value);
|
||||||
if (!poped) {
|
if (!poped) {
|
||||||
ADD_INSN(ret, nd_line(node), dup);
|
ADD_INSN(ret, nd_line(node), dup);
|
||||||
}
|
}
|
||||||
ADD_INSN1(ret, nd_line(node), setinstancevariable2,
|
ADD_INSN2(ret, nd_line(node), setinstancevariable,
|
||||||
ID2SYM(node->nd_vid));
|
ID2SYM(node->nd_vid), INT2FIX(is_local));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NODE_CDECL:{
|
case NODE_CDECL:{
|
||||||
|
@ -3909,19 +3902,14 @@ iseq_compile_each(yarv_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NODE_IVAR:{
|
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_IVAR2:{
|
case NODE_IVAR2:{
|
||||||
|
int is_local = (nd_type(node) == NODE_IVAR2) ? 1 : 0;
|
||||||
|
|
||||||
debugi("nd_vid", node->nd_vid);
|
debugi("nd_vid", node->nd_vid);
|
||||||
if (!poped) {
|
if (!poped) {
|
||||||
ADD_INSN1(ret, nd_line(node), getinstancevariable2,
|
ADD_INSN2(ret, nd_line(node), getinstancevariable,
|
||||||
ID2SYM(node->nd_vid));
|
ID2SYM(node->nd_vid), INT2FIX(is_local));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
46
insns.def
46
insns.def
|
@ -175,60 +175,38 @@ setdynamic
|
||||||
/**
|
/**
|
||||||
@c variable
|
@c variable
|
||||||
@e get instance variable id of obj.
|
@e get instance variable id of obj.
|
||||||
|
if is_local is not 0, search as class local variable.
|
||||||
@j obj のインスタンス変数 id を得る。
|
@j obj のインスタンス変数 id を得る。
|
||||||
|
もし is_local が !0 ならクラスローカル変数を得る
|
||||||
*/
|
*/
|
||||||
DEFINE_INSN
|
DEFINE_INSN
|
||||||
getinstancevariable
|
getinstancevariable
|
||||||
(ID id)
|
(ID id, num_t is_local)
|
||||||
()
|
()
|
||||||
(VALUE val)
|
(VALUE val)
|
||||||
{
|
{
|
||||||
val = rb_ivar_get(GET_SELF(), id);
|
if (is_local) {
|
||||||
}
|
id = rb_compose_ivar2(id, eval_get_cvar_base(th, GET_ISEQ()));
|
||||||
|
}
|
||||||
/**
|
|
||||||
@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);
|
val = rb_ivar_get(GET_SELF(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@c variable
|
@c variable
|
||||||
@e set instance variable id of obj as val.
|
@e set instance variable id of obj as val.
|
||||||
|
if is_local is not 0, search as class local variable.
|
||||||
@j obj のインスタンス変数を val にする。
|
@j obj のインスタンス変数を val にする。
|
||||||
|
もし is_local が !0 ならクラスローカル変数を得る
|
||||||
*/
|
*/
|
||||||
DEFINE_INSN
|
DEFINE_INSN
|
||||||
setinstancevariable
|
setinstancevariable
|
||||||
(ID id)
|
(ID id, num_t is_local)
|
||||||
(VALUE val)
|
(VALUE val)
|
||||||
()
|
()
|
||||||
{
|
{
|
||||||
rb_ivar_set(GET_SELF(), id, val);
|
if (is_local) {
|
||||||
}
|
id = rb_compose_ivar2(id, eval_get_cvar_base(th, GET_ISEQ()));
|
||||||
|
}
|
||||||
/**
|
|
||||||
@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);
|
rb_ivar_set(GET_SELF(), id, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
parse.y
1
parse.y
|
@ -8592,7 +8592,6 @@ ID
|
||||||
rb_decompose_ivar2(ID id, VALUE *klassp)
|
rb_decompose_ivar2(ID id, VALUE *klassp)
|
||||||
{
|
{
|
||||||
struct ivar2_key *kp;
|
struct ivar2_key *kp;
|
||||||
ID oid;
|
|
||||||
|
|
||||||
if (!st_lookup(global_symbols.id_ivar2, (st_data_t)id, (st_data_t *)&kp)) {
|
if (!st_lookup(global_symbols.id_ivar2, (st_data_t)id, (st_data_t *)&kp)) {
|
||||||
return id;
|
return id;
|
||||||
|
|
|
@ -1116,8 +1116,6 @@ class InsnsDef
|
||||||
insns.each{|insn|
|
insns.each{|insn|
|
||||||
size = insn.unifs.size
|
size = insn.unifs.size
|
||||||
if size > 0
|
if size > 0
|
||||||
require 'pp'
|
|
||||||
|
|
||||||
insn.unifs.sort_by{|unif| -unif[1].size}.each_with_index{|unif, i|
|
insn.unifs.sort_by{|unif| -unif[1].size}.each_with_index{|unif, i|
|
||||||
|
|
||||||
uni_insn, uni_insns = *unif
|
uni_insn, uni_insns = *unif
|
||||||
|
|
|
@ -749,5 +749,24 @@ class TestClass < YarvTestBase
|
||||||
:ok
|
:ok
|
||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче