summaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-01 04:35:58 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-01 04:35:58 +0000
commit75d28f887089c8582b63a64cf5df1d0270f15cc1 (patch)
tree1a274ad80a96f2546c0aba4701fd0c0e78857b5b /proc.c
parentea2cb282aeba0457aa775d5dbfa1da6810fafa45 (diff)
* yarvcore.h, compile.c (set_arguments): support post arguments.
* test/ruby/test_method.rb: add tests for above. * test/ruby/test_proc.rb: ditto. * proc.c: fix an arity bug ([ruby-core:11029]). * vm.c, vm.h, insns.def, vm_dump.h: fix bmethod process. * vm.c: support block argument on block parameter. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12231 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/proc.c b/proc.c
index 98d62e2a35..66eebec8ab 100644
--- a/proc.c
+++ b/proc.c
@@ -247,14 +247,23 @@ proc_new(VALUE klass, int is_lambda)
if ((GC_GUARDED_PTR_REF(cfp->lfp[0])) != 0 &&
!RUBY_VM_CLASS_SPECIAL_P(cfp->lfp[0])) {
+
block = GC_GUARDED_PTR_REF(cfp->lfp[0]);
+ cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
}
else {
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
+
if ((GC_GUARDED_PTR_REF(cfp->lfp[0])) != 0 &&
!RUBY_VM_CLASS_SPECIAL_P(cfp->lfp[0])) {
+
block = GC_GUARDED_PTR_REF(cfp->lfp[0]);
+ /* TODO: check more (cfp limit, called via cfunc, etc) */
+ while (cfp->dfp != block->dfp) {
+ cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
+ }
+
if (is_lambda) {
rb_warn("tried to create Proc object without a block");
}
@@ -265,7 +274,6 @@ proc_new(VALUE klass, int is_lambda)
}
}
- cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
procval = th_make_proc(th, cfp, block);
if (is_lambda) {
@@ -389,6 +397,7 @@ proc_call(int argc, VALUE *argv, VALUE procval)
{
rb_proc_t *proc;
GetProcPtr(procval, proc);
+
return th_invoke_proc(GET_THREAD(), proc, proc->block.self, argc, argv);
}
@@ -424,6 +433,7 @@ rb_proc_call(VALUE proc, VALUE args)
* Proc.new {|a,b,c|}.arity #=> 3
* Proc.new {|*a|}.arity #=> -1
* Proc.new {|a,*b|}.arity #=> -2
+ * Proc.new {|a,*b, c|}.arity #=> -3
*/
static VALUE
@@ -434,11 +444,11 @@ proc_arity(VALUE self)
GetProcPtr(self, proc);
iseq = proc->block.iseq;
if (iseq && BUILTIN_TYPE(iseq) != T_NODE) {
- if (iseq->arg_rest == 0 && iseq->arg_opts == 0) {
+ if (iseq->arg_rest < 0) {
return INT2FIX(iseq->argc);
}
else {
- return INT2FIX(-iseq->argc - 1);
+ return INT2FIX(-(iseq->argc + 1 + iseq->arg_post_len));
}
}
else {
@@ -1150,16 +1160,6 @@ rb_node_arity(NODE* body)
return 0;
case NODE_BMETHOD:
return rb_proc_arity(body->nd_cval);
- case NODE_SCOPE:
- body = body->nd_next; /* skip NODE_SCOPE */
- if (nd_type(body) == NODE_BLOCK)
- body = body->nd_head;
- if (!body)
- return 0;
- n = body->nd_frml ? RARRAY_LEN(body->nd_frml) : 0;
- if (body->nd_opt || body->nd_rest)
- n = -n - 1;
- return n;
case RUBY_VM_METHOD_NODE:{
rb_iseq_t *iseq;
GetISeqPtr((VALUE)body->nd_body, iseq);
@@ -1167,7 +1167,7 @@ rb_node_arity(NODE* body)
return iseq->argc;
}
else {
- return -iseq->argc - 1;
+ return -(iseq->argc + 1 + iseq->arg_post_len);
}
}
default: