* include/ruby/ruby.h, vm_core.h: add a type rb_blockptr.

* vm_insnhelper.c (vm_yield_with_cfunc): vm_yield_with_cfunc receives
  blockptr and passes it to iterating block.

* proc.c (rb_proc_call), include/ruby/intern.h: rb_proc_call receives
  blockptr.  "rb_proc_call(self, args, blockptr)" in C corresponds to
  "self.call(*args, &block)" in Ruby.

* proc.c (proc_call): pass blockptr to block that is written in C.

* proc.c (curry): receive blockptr and pass it to original proc.
  [ruby-core:15551]

* vm.c (invoke_block_from_c): fix for change of vm_yield_with_cfunc.

* thread.c (call_trace_proc), eval_jump.c (rb_call_end_proc): fix for
  change of rb_proc_call.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2008-06-09 15:52:51 +00:00
Родитель 4879ae65fd
Коммит f2400eca0b
9 изменённых файлов: 41 добавлений и 14 удалений

Просмотреть файл

@ -1,3 +1,24 @@
Tue Jun 10 00:50:51 2008 Yusuke Endoh <mame@tsg.ne.jp>
* include/ruby/ruby.h, vm_core.h: add a type rb_blockptr.
* vm_insnhelper.c (vm_yield_with_cfunc): vm_yield_with_cfunc receives
blockptr and passes it to iterating block.
* proc.c (rb_proc_call), include/ruby/intern.h: rb_proc_call receives
blockptr. "rb_proc_call(self, args, blockptr)" in C corresponds to
"self.call(*args, &block)" in Ruby.
* proc.c (proc_call): pass blockptr to block that is written in C.
* proc.c (curry): receive blockptr and pass it to original proc.
[ruby-core:15551]
* vm.c (invoke_block_from_c): fix for change of vm_yield_with_cfunc.
* thread.c (call_trace_proc), eval_jump.c (rb_call_end_proc): fix for
change of rb_proc_call.
Tue Jun 10 00:10:49 2008 Tanaka Akira <akr@fsij.org>
* common.mk (test-knownbug): give $(OPTS) for bootstraptest/runner.rb.

Просмотреть файл

@ -10,7 +10,7 @@
void
rb_call_end_proc(VALUE data)
{
rb_proc_call(data, rb_ary_new());
rb_proc_call(data, rb_ary_new(), 0);
}
/*

Просмотреть файл

@ -270,7 +270,7 @@ VALUE rb_class_new_instance(int, VALUE*, VALUE);
VALUE rb_block_proc(void);
VALUE rb_f_lambda(void);
VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE);
VALUE rb_proc_call(VALUE, VALUE);
VALUE rb_proc_call(VALUE, VALUE, rb_blockptr);
int rb_proc_arity(VALUE);
VALUE rb_binding_new(void);
VALUE rb_obj_method(VALUE, VALUE);

Просмотреть файл

@ -824,6 +824,8 @@ PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2);
PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2);
PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4);
typedef struct rb_block_struct *rb_blockptr;
typedef VALUE rb_block_call_func(VALUE, VALUE, int, VALUE*);
VALUE rb_each(VALUE);

15
proc.c
Просмотреть файл

@ -490,7 +490,7 @@ proc_call(int argc, VALUE *argv, VALUE procval)
rb_block_t *blockptr = 0;
GetProcPtr(procval, proc);
if (BUILTIN_TYPE(proc->block.iseq) != T_NODE &&
if (BUILTIN_TYPE(proc->block.iseq) == T_NODE ||
proc->block.iseq->arg_block != -1) {
if (rb_block_given_p()) {
@ -507,12 +507,12 @@ proc_call(int argc, VALUE *argv, VALUE procval)
}
VALUE
rb_proc_call(VALUE self, VALUE args)
rb_proc_call(VALUE self, VALUE args, rb_blockptr blockptr)
{
rb_proc_t *proc;
GetProcPtr(self, proc);
return vm_invoke_proc(GET_THREAD(), proc, proc->block.self,
RARRAY_LEN(args), RARRAY_PTR(args), 0);
RARRAY_LEN(args), RARRAY_PTR(args), blockptr);
}
/*
@ -1584,7 +1584,7 @@ proc_binding(VALUE self)
return bindval;
}
static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv);
static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv, rb_blockptr blockptr);
static VALUE
make_curry_proc(VALUE proc, VALUE passed, VALUE arity)
@ -1600,7 +1600,7 @@ make_curry_proc(VALUE proc, VALUE passed, VALUE arity)
}
static VALUE
curry(VALUE dummy, VALUE args, int argc, VALUE *argv)
curry(VALUE dummy, VALUE args, int argc, VALUE *argv, rb_blockptr blockptr)
{
VALUE proc, passed, arity;
proc = RARRAY_PTR(args)[0];
@ -1610,10 +1610,13 @@ curry(VALUE dummy, VALUE args, int argc, VALUE *argv)
passed = rb_ary_plus(passed, rb_ary_new4(argc, argv));
rb_ary_freeze(passed);
if(RARRAY_LEN(passed) < FIX2INT(arity)) {
if (blockptr) {
rb_warn("given block not used");
}
arity = make_curry_proc(proc, passed, arity);
return arity;
}
arity = rb_proc_call(proc, passed);
arity = rb_proc_call(proc, passed, blockptr);
return arity;
}

Просмотреть файл

@ -3105,7 +3105,7 @@ call_trace_proc(VALUE args, int tracing)
eventname, filename, INT2FIX(line),
id ? ID2SYM(id) : Qnil,
p->self ? rb_binding_new() : Qnil,
klass ? klass : Qnil));
klass ? klass : Qnil), 0);
}
static void

2
vm.c
Просмотреть файл

@ -448,7 +448,7 @@ invoke_block_from_c(rb_thread_t *th, const rb_block_t *block,
return vm_eval_body(th);
}
else {
return vm_yield_with_cfunc(th, block, self, argc, argv);
return vm_yield_with_cfunc(th, block, self, argc, argv, blockptr);
}
}

Просмотреть файл

@ -345,7 +345,7 @@ typedef struct {
VALUE prof_time_chld; /* cfp[13] */
} rb_control_frame_t;
typedef struct {
typedef struct rb_block_struct {
VALUE self; /* share with method frame if it's only block */
VALUE *lfp; /* share with method frame if it's only block */
VALUE *dfp; /* share with method frame if it's only block */

Просмотреть файл

@ -651,7 +651,8 @@ block_proc_is_lambda(const VALUE procval)
static inline VALUE
vm_yield_with_cfunc(rb_thread_t *th, const rb_block_t *block,
VALUE self, int argc, const VALUE *argv)
VALUE self, int argc, const VALUE *argv,
const rb_block_t *blockptr)
{
NODE *ifunc = (NODE *) block->iseq;
VALUE val;
@ -672,7 +673,7 @@ vm_yield_with_cfunc(rb_thread_t *th, const rb_block_t *block,
self, (VALUE)block->dfp,
0, th->cfp->sp, block->lfp, 1);
val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, argc, argv);
val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, argc, argv, blockptr);
th->cfp++;
return val;
@ -831,7 +832,7 @@ vm_invoke_block(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_num_t num, rb_n
return Qundef;
}
else {
VALUE val = vm_yield_with_cfunc(th, block, block->self, argc, STACK_ADDR_FROM_TOP(argc));
VALUE val = vm_yield_with_cfunc(th, block, block->self, argc, STACK_ADDR_FROM_TOP(argc), 0);
POPN(argc); /* TODO: should put before C/yield? */
return val;
}