1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* insns.def : support direct method dispatch with "send" or "funcall".

This means that "obj.send :m" skips "BasicObject#send" invocation
(method frame creation, etc) and "obj.m" invokes directly.
If you make backtrace, there are no enties of "send" method.
* compile.c (iseq_specialized_instruction) : fix to support above
* eval.c : ditto (remove "static" from rb_f_send and rb_f_funcall
* yarvcore.c : ditto (add a external IDs for compiler)
* yarvcore.h : ditto (add a VM_CALL_SEND_BIT macro)
* yarvtest/test_method.rb : add tests for above changes
* eval.c : remove unused "Kernel#send" declaration



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2007-01-06 00:24:59 +00:00
parent a782fa1268
commit ce55b4c0e0
7 changed files with 138 additions and 12 deletions

View file

@ -1,3 +1,22 @@
Sat Jan 6 09:10:52 2007 Koichi Sasada <ko1@atdot.net>
* insns.def : support direct method dispatch with "send" or "funcall".
This means that "obj.send :m" skips "BasicObject#send" invocation
(method frame creation, etc) and "obj.m" invokes directly.
If you make backtrace, there are no enties of "send" method.
* compile.c (iseq_specialized_instruction) : fix to support above
* eval.c : ditto (remove "static" from rb_f_send and rb_f_funcall
* yarvcore.c : ditto (add a external IDs for compiler)
* yarvcore.h : ditto (add a VM_CALL_SEND_BIT macro)
* yarvtest/test_method.rb : add tests for above changes
* eval.c : remove unused "Kernel#send" declaration
Sat Jan 6 08:29:17 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (Init_win32ole): add

View file

@ -1671,6 +1671,11 @@ iseq_specialized_instruction(yarv_iseq_t *iseq, INSN *iobj)
}
}
}
if (mid == idSend || mid == id__send__ || mid == id__send ||
mid == idFuncall || mid == id__send_bang) {
OPERAND_AT(iobj, 3) |= INT2FIX(VM_CALL_SEND_BIT);
}
}
return COMPILE_OK;
}

7
eval.c
View file

@ -1709,7 +1709,7 @@ send_funcall(int argc, VALUE *argv, VALUE recv, int scope)
* k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
*/
static VALUE
VALUE
rb_f_send(int argc, VALUE *argv, VALUE recv)
{
int scope = NOEX_PUBLIC;
@ -1736,7 +1736,7 @@ rb_f_send(int argc, VALUE *argv, VALUE recv)
* 1.funcall(:puts, "hello") # prints "foo"
*/
static VALUE
VALUE
rb_f_funcall(int argc, VALUE *argv, VALUE recv)
{
return send_funcall(argc, argv, recv, NOEX_NOSUPER | NOEX_PRIVATE);
@ -2894,13 +2894,12 @@ Init_eval()
rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */
rb_define_global_function("local_variables", rb_f_local_variables, 0);
rb_define_method(rb_mKernel, "send", rb_f_send, -1);
rb_define_method(rb_cBasicObject, "send", rb_f_send, -1);
rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1);
rb_define_method(rb_cBasicObject, "__send", rb_f_send, -1);
rb_define_method(rb_cBasicObject, "funcall", rb_f_funcall, -1);
rb_define_method(rb_cBasicObject, "__send!", rb_f_funcall, -1);
rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1);
rb_define_method(rb_mKernel, "instance_exec", rb_obj_instance_exec, -1);

View file

@ -1146,7 +1146,7 @@ defineclass
*/
DEFINE_INSN
send
(ID id, num_t op_argc, ISEQ blockiseq, num_t op_flag, IC ic)
(ID op_id, num_t op_argc, ISEQ blockiseq, num_t op_flag, IC ic)
(...)
(VALUE val) // inc += - (op_argc + ((op_flag & VM_CALL_ARGS_BLOCKARG_BIT) ? 1 : 0));
{
@ -1156,6 +1156,7 @@ send
yarv_block_t *blockptr = 0;
num_t num = op_argc;
num_t flag = op_flag;
ID id = op_id;
macro_eval_setup_send_arguments(num, blockptr, flag, blockiseq);
@ -1172,6 +1173,31 @@ send
mn = eval_method_search(id, klass, ic);
if ((flag & VM_CALL_SEND_BIT) && mn && nd_type(mn->nd_body) == NODE_CFUNC) {
NODE *node = mn->nd_body;
extern VALUE rb_f_funcall(int argc, VALUE *argv, VALUE recv);
extern VALUE rb_f_send(int argc, VALUE *argv, VALUE recv);
if (node->nd_cfnc == rb_f_funcall || node->nd_cfnc == rb_f_send) {
int i;
id = rb_to_id(TOPN(num - 1));
/* shift arguments */
for (i=1; i<num; i++) {
GET_SP()[-num+i-1] = GET_SP()[(-num+i-1)+1];
}
mn = rb_method_node(klass, id);
num -= 1;
INC_SP(-1);
}
if (node->nd_cfnc == rb_f_funcall) {
flag |= VM_CALL_FCALL_BIT;
}
}
#if CURRENT_INSN_send || CURRENT_INSN_send_SC_xx_ax
#if !YARV_AOT_COMPILED
if (0) {

View file

@ -59,6 +59,11 @@ ID idEnd;
ID idBitblt;
ID idAnswer;
ID idSvarPlaceholder;
ID idSend;
ID id__send__;
ID id__send;
ID idFuncall;
ID id__send_bang;
unsigned long yarvGlobalStateVersion = 1;
@ -996,6 +1001,12 @@ Init_yarvcore(void)
idAnswer = rb_intern("the_answer_to_life_the_universe_and_everything");
idSvarPlaceholder = rb_intern("#svar");
idSend = rb_intern("send");
id__send__ = rb_intern("__send__");
id__send = rb_intern("__send");
idFuncall = rb_intern("funcall");
id__send_bang = rb_intern("__send!");
#if TEST_AOT_COMPILE
Init_compiled();
#endif

View file

@ -143,6 +143,12 @@ extern ID idEnd;
extern ID idBitblt;
extern ID idAnswer;
extern ID idSvarPlaceholder;
extern ID idSend;
extern ID id__send__;
extern ID id__send;
extern ID idFuncall;
extern ID id__send_bang;
extern unsigned long yarvGlobalStateVersion;
@ -534,13 +540,14 @@ typedef struct {
/* used by compile time and send insn */
#define VM_CALL_ARGS_SPLAT_BIT 0x01
#define VM_CALL_ARGS_BLOCKARG_BIT 0x02
#define VM_CALL_FCALL_BIT 0x04
#define VM_CALL_VCALL_BIT 0x08
#define VM_CALL_TAILCALL_BIT 0x10
#define VM_CALL_TAILRECURSION_BIT 0x20
#define VM_CALL_SUPER_BIT 0x40
#define VM_CALL_ARGS_SPLAT_BIT (0x01 << 1)
#define VM_CALL_ARGS_BLOCKARG_BIT (0x01 << 2)
#define VM_CALL_FCALL_BIT (0x01 << 3)
#define VM_CALL_VCALL_BIT (0x01 << 4)
#define VM_CALL_TAILCALL_BIT (0x01 << 5)
#define VM_CALL_TAILRECURSION_BIT (0x01 << 6)
#define VM_CALL_SUPER_BIT (0x01 << 7)
#define VM_CALL_SEND_BIT (0x01 << 8)
/* inline method cache */
#define NEW_INLINE_CACHE_ENTRY() NEW_WHILE(Qundef, 0, 0)

View file

@ -535,5 +535,64 @@ class TestMethod < YarvTestBase
C.new.m
}
end
def test_send
ae %q{
$r = []
class C
def m *args
$r << "C#m #{args.inspect} #{block_given?}"
end
end
obj = C.new
obj.send :m
obj.send :m, :x
obj.send :m, :x, :y
obj.send(:m){}
obj.send(:m, :x){}
$r
}
end
def test_send_with_private
ae %q{
begin
def m
end
self.send :m
rescue NoMethodError
:ok
else
:ng
end
}
ae %q{
begin
def m
end
send :m
rescue NoMethodError
:ng
else
:ok
end
}
end
def test_funcall
ae %q{
$r = []
def m *args
$r << "m() #{args.inspect} #{block_given?}"
end
funcall :m
funcall :m, :x
funcall :m, :x, :y
funcall(:m){}
funcall(:m, :x){}
}
end
end