Skip to content

Commit 276fb7e

Browse files
author
matz
committed
* compile.c (iseq_compile_each): should consider block on stack,
if block argument is passed. [ruby-core:30534] * parse.c (arg_concat_gen): should append to nd_head, not to nd_iter for NODE_BLOCK_PASS. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 4c897fd commit 276fb7e

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

ChangeLog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Wed Jun 2 11:40:02 2010 Yukihiro Matsumoto <matz@ruby-lang.org>
2+
3+
* compile.c (iseq_compile_each): should consider block on stack,
4+
if block argument is passed. [ruby-core:30534]
5+
6+
* parse.c (arg_concat_gen): should append to nd_head, not to
7+
nd_iter for NODE_BLOCK_PASS.
8+
19
Tue Jun 1 23:12:06 2010 NARUSE, Yui <naruse@ruby-lang.org>
210

311
* re.c (unescape_nonascii): \P{FOO} is also Unicode property in

compile.c

+37-9
Original file line numberDiff line numberDiff line change
@@ -3743,6 +3743,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
37433743
VALUE argc;
37443744
unsigned long flag = 0;
37453745
ID id = node->nd_mid;
3746+
int boff = 0;
37463747

37473748
/*
37483749
* a[x] (op)= y
@@ -3771,15 +3772,18 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
37713772
ADD_INSN(ret, nd_line(node), putnil);
37723773
}
37733774
COMPILE(ret, "NODE_OP_ASGN1 recv", node->nd_recv);
3774-
if (nd_type(node->nd_args->nd_head) != NODE_ZARRAY) {
3775+
switch (nd_type(node->nd_args->nd_head)) {
3776+
case NODE_ZARRAY:
3777+
argc = INT2FIX(0);
3778+
break;
3779+
case NODE_BLOCK_PASS:
3780+
boff = 1;
3781+
default:
37753782
INIT_ANCHOR(args);
37763783
argc = setup_args(iseq, args, node->nd_args->nd_head, &flag);
37773784
ADD_SEQ(ret, args);
37783785
}
3779-
else {
3780-
argc = INT2FIX(0);
3781-
}
3782-
ADD_INSN1(ret, nd_line(node), dupn, FIXNUM_INC(argc, 1));
3786+
ADD_INSN1(ret, nd_line(node), dupn, FIXNUM_INC(argc, 1 + boff));
37833787
ADD_SEND_R(ret, nd_line(node), ID2SYM(idAREF), argc, Qfalse, LONG2FIX(flag));
37843788

37853789
if (id == 0 || id == 1) {
@@ -3808,40 +3812,64 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
38083812

38093813
COMPILE(ret, "NODE_OP_ASGN1 args->body: ", node->nd_args->nd_body);
38103814
if (!poped) {
3811-
ADD_INSN1(ret, nd_line(node), setn, FIXNUM_INC(argc, 2));
3815+
ADD_INSN1(ret, nd_line(node), setn, FIXNUM_INC(argc, 2+boff));
38123816
}
38133817
if (flag & VM_CALL_ARGS_SPLAT_BIT) {
38143818
ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1));
3819+
if (boff > 0) {
3820+
ADD_INSN1(ret, nd_line(node), dupn, INT2FIX(3));
3821+
ADD_INSN(ret, nd_line(node), swap);
3822+
ADD_INSN(ret, nd_line(node), pop);
3823+
}
38153824
ADD_INSN(ret, nd_line(node), concatarray);
3825+
if (boff > 0) {
3826+
ADD_INSN1(ret, nd_line(node), setn, INT2FIX(3));
3827+
ADD_INSN(ret, nd_line(node), pop);
3828+
ADD_INSN(ret, nd_line(node), pop);
3829+
}
38163830
ADD_SEND_R(ret, nd_line(node), ID2SYM(idASET),
38173831
argc, Qfalse, LONG2FIX(flag));
38183832
}
38193833
else {
3834+
if (boff > 0)
3835+
ADD_INSN(ret, nd_line(node), swap);
38203836
ADD_SEND_R(ret, nd_line(node), ID2SYM(idASET),
38213837
FIXNUM_INC(argc, 1), Qfalse, LONG2FIX(flag));
38223838
}
38233839
ADD_INSN(ret, nd_line(node), pop);
38243840
ADD_INSNL(ret, nd_line(node), jump, lfin);
38253841
ADD_LABEL(ret, label);
38263842
if (!poped) {
3827-
ADD_INSN1(ret, nd_line(node), setn, FIXNUM_INC(argc, 2));
3843+
ADD_INSN1(ret, nd_line(node), setn, FIXNUM_INC(argc, 2+boff));
38283844
}
3829-
ADD_INSN1(ret, nd_line(node), adjuststack, FIXNUM_INC(argc, 2));
3845+
ADD_INSN1(ret, nd_line(node), adjuststack, FIXNUM_INC(argc, 2+boff));
38303846
ADD_LABEL(ret, lfin);
38313847
}
38323848
else {
38333849
COMPILE(ret, "NODE_OP_ASGN1 args->body: ", node->nd_args->nd_body);
38343850
ADD_SEND(ret, nd_line(node), ID2SYM(id), INT2FIX(1));
38353851
if (!poped) {
3836-
ADD_INSN1(ret, nd_line(node), setn, FIXNUM_INC(argc, 2));
3852+
ADD_INSN1(ret, nd_line(node), setn, FIXNUM_INC(argc, 2+boff));
38373853
}
38383854
if (flag & VM_CALL_ARGS_SPLAT_BIT) {
38393855
ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1));
3856+
if (boff > 0) {
3857+
ADD_INSN1(ret, nd_line(node), dupn, INT2FIX(3));
3858+
ADD_INSN(ret, nd_line(node), swap);
3859+
ADD_INSN(ret, nd_line(node), pop);
3860+
}
38403861
ADD_INSN(ret, nd_line(node), concatarray);
3862+
if (boff > 0) {
3863+
ADD_INSN1(ret, nd_line(node), setn, INT2FIX(3));
3864+
ADD_INSN(ret, nd_line(node), pop);
3865+
ADD_INSN(ret, nd_line(node), pop);
3866+
}
38413867
ADD_SEND_R(ret, nd_line(node), ID2SYM(idASET),
38423868
argc, Qfalse, LONG2FIX(flag));
38433869
}
38443870
else {
3871+
if (boff > 0)
3872+
ADD_INSN(ret, nd_line(node), swap);
38453873
ADD_SEND_R(ret, nd_line(node), ID2SYM(idASET),
38463874
FIXNUM_INC(argc, 1), Qfalse, LONG2FIX(flag));
38473875
}

insns.def

+1
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ concatarray
498498
(VALUE ary1, VALUE ary2st)
499499
(VALUE ary)
500500
{
501+
const VALUE *sp = GET_SP();
501502
const VALUE ary2 = ary2st;
502503
VALUE tmp1 = rb_check_convert_type(ary1, T_ARRAY, "Array", "to_a");
503504
VALUE tmp2 = rb_check_convert_type(ary2, T_ARRAY, "Array", "to_a");

parse.y

+10-2
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,12 @@ arg : lhs '=' arg
19531953

19541954
value_expr($6);
19551955
if (!$3) $3 = NEW_ZARRAY();
1956-
args = arg_concat($3, $6);
1956+
if (nd_type($3) == NODE_BLOCK_PASS) {
1957+
args = NEW_ARGSCAT($3, $6);
1958+
}
1959+
else {
1960+
args = arg_concat($3, $6);
1961+
}
19571962
if ($5 == tOROP) {
19581963
$5 = 0;
19591964
}
@@ -8309,7 +8314,10 @@ arg_concat_gen(struct parser_params *parser, NODE *node1, NODE *node2)
83098314
if (!node2) return node1;
83108315
switch (nd_type(node1)) {
83118316
case NODE_BLOCK_PASS:
8312-
node1->nd_iter = arg_concat(node1->nd_iter, node2);
8317+
if (node1->nd_head)
8318+
node1->nd_head = arg_concat(node1->nd_head, node2);
8319+
else
8320+
node1->nd_head = NEW_LIST(node2);
83138321
return node1;
83148322
case NODE_ARGSPUSH:
83158323
if (nd_type(node2) != NODE_ARRAY) break;

0 commit comments

Comments
 (0)