diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-20 08:13:53 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-20 08:13:53 +0000 |
commit | ea01ffa56951724708858b982d7aa64504cc412c (patch) | |
tree | 8196c9203f6fe953f5bba9ccc81be26e179b5ab5 /compile.c | |
parent | a1580347899f1fb6fd85d82828db3f372e5ec86d (diff) | |
download | ruby-ea01ffa56951724708858b982d7aa64504cc412c.tar.gz |
* vm_core.h (rb_vm_defineclass_type_t),
compile.c (iseq_compile_each), insns.def (defineclass): change the
meaning of the third operand of defineclass as follows:
lower 3bits: the type of the defineclass
0 = class, 1 = singleton class, 2 = module
4th bit: a flag represents whether the defineclass is scoped
0 = not scoped (e.g., class Foo)
1 = scoped (e.g., class Bar::Baz)
5th bit: a flag represents whether the superclass is specified
0 = not specified (e.g., class Foo)
1 = specified (e.g., class Bar < Foo)
If the superclass is specified and is not a class, a TypeError
should be raised. [ruby-dev:46747] [Bug #7572]
* test/ruby/test_class.rb: related test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -4848,9 +4848,12 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) rb_sprintf("<class:%s>", rb_id2name(node->nd_cpath->nd_mid)), ISEQ_TYPE_CLASS, nd_line(node)); VALUE noscope = compile_cpath(ret, iseq, node->nd_cpath); + int flags = VM_DEFINECLASS_TYPE_CLASS; + if (!noscope) flags |= VM_DEFINECLASS_FLAG_SCOPED; + if (node->nd_super) flags |= VM_DEFINECLASS_FLAG_HAS_SUPERCLASS; COMPILE(ret, "super", node->nd_super); ADD_INSN3(ret, nd_line(node), defineclass, - ID2SYM(node->nd_cpath->nd_mid), iseqval, INT2FIX(noscope ? 3 : 0)); + ID2SYM(node->nd_cpath->nd_mid), iseqval, INT2FIX(flags)); if (poped) { ADD_INSN(ret, nd_line(node), pop); @@ -4864,9 +4867,11 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ISEQ_TYPE_CLASS, nd_line(node)); VALUE noscope = compile_cpath(ret, iseq, node->nd_cpath); + int flags = VM_DEFINECLASS_TYPE_MODULE; + if (!noscope) flags |= VM_DEFINECLASS_FLAG_SCOPED; ADD_INSN (ret, nd_line(node), putnil); /* dummy */ ADD_INSN3(ret, nd_line(node), defineclass, - ID2SYM(node->nd_cpath->nd_mid), iseqval, INT2FIX(noscope ? 5 : 2)); + ID2SYM(node->nd_cpath->nd_mid), iseqval, INT2FIX(flags)); if (poped) { ADD_INSN(ret, nd_line(node), pop); } @@ -4882,7 +4887,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ADD_INSN (ret, nd_line(node), putnil); CONST_ID(singletonclass, "singletonclass"); ADD_INSN3(ret, nd_line(node), defineclass, - ID2SYM(singletonclass), iseqval, INT2FIX(1)); + ID2SYM(singletonclass), iseqval, + INT2FIX(VM_DEFINECLASS_TYPE_SINGLETON_CLASS)); if (poped) { ADD_INSN(ret, nd_line(node), pop); |