From ea01ffa56951724708858b982d7aa64504cc412c Mon Sep 17 00:00:00 2001 From: shugo Date: Thu, 20 Dec 2012 08:13:53 +0000 Subject: * 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 --- compile.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index 09e966d0f2..3daa6077fc 100644 --- a/compile.c +++ b/compile.c @@ -4848,9 +4848,12 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) rb_sprintf("", 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); -- cgit v1.2.3