[前][次][番号順一覧][スレッド一覧]

ruby-changes:52060

From: mame <ko1@a...>
Date: Fri, 10 Aug 2018 16:45:23 +0900 (JST)
Subject: [ruby-changes:52060] mame:r64268 (trunk): insns.def (invokesuper): remove a dummy receiever flag hack for ZSUPER

mame	2018-08-10 16:45:16 +0900 (Fri, 10 Aug 2018)

  New Revision: 64268

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64268

  Log:
    insns.def (invokesuper): remove a dummy receiever flag hack for ZSUPER
    
    This is just a refactoring.
    
    The receiver of "invokesuper" was a boolean to represent if it is ZSUPER
    or not.  This was used in vm_search_super_method to prohibit ZSUPER call
    in define_method. (It is currently prohibited because of the limitation
    of the implementation.)
    
    This change removes the hack by introducing an explicit flag,
    VM_CALL_SUPER, to signal the information.  Now, the implementation of
    "invokesuper" is consistent with "send" instruction.

  Modified files:
    trunk/compile.c
    trunk/insns.def
    trunk/iseq.c
    trunk/vm_core.h
    trunk/vm_insnhelper.c
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 64267)
+++ vm_insnhelper.c	(revision 64268)
@@ -2473,7 +2473,6 @@ vm_search_super_method(const rb_executio https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2473
 		       struct rb_calling_info *calling, struct rb_call_info *ci, struct rb_call_cache *cc)
 {
     VALUE current_defined_class, klass;
-    VALUE sigval = TOPN(calling->argc);
     const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(reg_cfp);
 
     if (!me) {
@@ -2499,7 +2498,7 @@ vm_search_super_method(const rb_executio https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2498
 		 rb_obj_class(calling->recv), m);
     }
 
-    if (me->def->type == VM_METHOD_TYPE_BMETHOD && !sigval) {
+    if (me->def->type == VM_METHOD_TYPE_BMETHOD && (ci->flag & VM_CALL_ZSUPER)) {
 	rb_raise(rb_eRuntimeError,
 		 "implicit argument passing of super from method defined"
 		 " by define_method() is not supported."
Index: insns.def
===================================================================
--- insns.def	(revision 64267)
+++ insns.def	(revision 64268)
@@ -716,7 +716,8 @@ send https://github.com/ruby/ruby/blob/trunk/insns.def#L716
     struct rb_calling_info calling;
 
     vm_caller_setup_arg_block(ec, reg_cfp, &calling, ci, blockiseq, FALSE);
-    vm_search_method(ci, cc, calling.recv = TOPN(calling.argc = ci->orig_argc));
+    calling.recv = TOPN(calling.argc = ci->orig_argc);
+    vm_search_method(ci, cc, calling.recv);
     CALL_METHOD(&calling, ci, cc);
 }
 
@@ -783,10 +784,9 @@ invokesuper https://github.com/ruby/ruby/blob/trunk/insns.def#L784
 // attr rb_snum_t sp_inc = - (int)(ci->orig_argc + ((ci->flag & VM_CALL_ARGS_BLOCKARG) ? 1 : 0));
 {
     struct rb_calling_info calling;
-    calling.argc = ci->orig_argc;
 
     vm_caller_setup_arg_block(ec, reg_cfp, &calling, ci, blockiseq, TRUE);
-    calling.recv = GET_SELF();
+    calling.recv = TOPN(calling.argc = ci->orig_argc);
     vm_search_super_method(ec, GET_CFP(), &calling, ci, cc);
     CALL_METHOD(&calling, ci, cc);
 }
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 64267)
+++ vm_core.h	(revision 64268)
@@ -1018,6 +1018,7 @@ enum vm_call_flag_bits { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L1018
     VM_CALL_KW_SPLAT_bit,       /* m(**opts) */
     VM_CALL_TAILCALL_bit,       /* located at tail position */
     VM_CALL_SUPER_bit,          /* super */
+    VM_CALL_ZSUPER_bit,         /* zsuper */
     VM_CALL_OPT_SEND_bit,       /* internal flag */
     VM_CALL__END
 };
@@ -1032,6 +1033,7 @@ enum vm_call_flag_bits { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L1033
 #define VM_CALL_KW_SPLAT        (0x01 << VM_CALL_KW_SPLAT_bit)
 #define VM_CALL_TAILCALL        (0x01 << VM_CALL_TAILCALL_bit)
 #define VM_CALL_SUPER           (0x01 << VM_CALL_SUPER_bit)
+#define VM_CALL_ZSUPER          (0x01 << VM_CALL_ZSUPER_bit)
 #define VM_CALL_OPT_SEND        (0x01 << VM_CALL_OPT_SEND_bit)
 
 enum vm_special_object_type {
Index: iseq.c
===================================================================
--- iseq.c	(revision 64267)
+++ iseq.c	(revision 64268)
@@ -1775,6 +1775,7 @@ rb_insn_operand_intern(const rb_iseq_t * https://github.com/ruby/ruby/blob/trunk/iseq.c#L1775
 		CALL_FLAG(BLOCKISEQ);
 		CALL_FLAG(TAILCALL);
 		CALL_FLAG(SUPER);
+		CALL_FLAG(ZSUPER);
 		CALL_FLAG(KWARG);
 		CALL_FLAG(KW_SPLAT);
 		CALL_FLAG(OPT_SEND); /* maybe not reachable */
Index: compile.c
===================================================================
--- compile.c	(revision 64267)
+++ compile.c	(revision 64268)
@@ -6624,11 +6624,10 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L6624
 	    }
 	}
 
-	/* dummy receiver */
-	ADD_INSN1(ret, line, putobject, type == NODE_ZSUPER ? Qfalse : Qtrue);
+	ADD_INSN(ret, line, putself);
 	ADD_SEQ(ret, args);
 	ADD_INSN3(ret, line, invokesuper,
-		  new_callinfo(iseq, 0, argc, flag | VM_CALL_SUPER | VM_CALL_FCALL, keywords, parent_block != NULL),
+		  new_callinfo(iseq, 0, argc, flag | VM_CALL_SUPER | (type == NODE_ZSUPER ? VM_CALL_ZSUPER : 0) | VM_CALL_FCALL, keywords, parent_block != NULL),
 		  Qnil, /* CALL_CACHE */
 		  parent_block);
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]