Skip to content

Commit

Permalink
* include/ruby/ruby.h, vm_core.h: add a type rb_blockptr.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mame committed Jun 9, 2008
1 parent 4879ae6 commit f2400ec
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 14 deletions.
21 changes: 21 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion eval_jump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion include/ruby/intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/ruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
}

/*
Expand Down Expand Up @@ -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)
Expand All @@ -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];
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion vm_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
7 changes: 4 additions & 3 deletions vm_insnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f2400ec

Please sign in to comment.