summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/compile.c b/compile.c
index bc11cd282a..650424a70e 100644
--- a/compile.c
+++ b/compile.c
@@ -3736,13 +3736,16 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
/*
* a[x] (op)= y
*
- * eval a # a
- * eval x # a x
- * dupn 2 # a x a x
- * send :[] # a x a[x]
- * eval y # a x a[x] y
- * send op # a x a[x]+y
- * send []= # ret
+ * nil # nil
+ * eval a # nil a
+ * eval x # nil a x
+ * dupn 2 # nil a x a x
+ * send :[] # nil a x a[x]
+ * eval y # nil a x a[x] y
+ * send op # nil a x ret
+ * setn 3 # ret a x ret
+ * send []= # ret ?
+ * pop # ret
*/
/*
@@ -3753,10 +3756,13 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
* nd_mid
*/
+ if (!poped) {
+ ADD_INSN(ret, nd_line(node), putnil);
+ }
COMPILE(ret, "NODE_OP_ASGN1 recv", node->nd_recv);
- if (nd_type(node->nd_args->nd_body) != NODE_ZARRAY) {
+ if (nd_type(node->nd_args->nd_head) != NODE_ZARRAY) {
INIT_ANCHOR(args);
- argc = setup_args(iseq, args, node->nd_args->nd_body, &flag);
+ argc = setup_args(iseq, args, node->nd_args->nd_head, &flag);
ADD_SEQ(ret, args);
}
else {
@@ -3791,7 +3797,10 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
ADD_INSN(ret, nd_line(node), pop);
}
- COMPILE(ret, "NODE_OP_ASGN1 args->head: ", node->nd_args->nd_head);
+ COMPILE(ret, "NODE_OP_ASGN1 args->body: ", node->nd_args->nd_body);
+ if (!poped) {
+ ADD_INSN1(ret, nd_line(node), setn, INT2FIX(3));
+ }
if (flag & VM_CALL_ARGS_SPLAT_BIT) {
ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1));
ADD_INSN(ret, nd_line(node), concatarray);
@@ -3802,15 +3811,21 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
ADD_SEND_R(ret, nd_line(node), ID2SYM(idASET),
INT2FIX(FIX2INT(argc) + 1), Qfalse, LONG2FIX(flag));
}
+ ADD_INSN(ret, nd_line(node), pop);
ADD_INSNL(ret, nd_line(node), jump, lfin);
ADD_LABEL(ret, label);
- ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 1));
- ADD_INSN1(ret, nd_line(node), adjuststack, INT2FIX(FIX2INT(argc) + 1));
+ if (!poped) {
+ ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 2));
+ }
+ ADD_INSN1(ret, nd_line(node), adjuststack, INT2FIX(FIX2INT(argc) + 2));
ADD_LABEL(ret, lfin);
}
else {
- COMPILE(ret, "NODE_OP_ASGN1 args->head: ", node->nd_args->nd_head);
+ COMPILE(ret, "NODE_OP_ASGN1 args->body: ", node->nd_args->nd_body);
ADD_SEND(ret, nd_line(node), ID2SYM(id), INT2FIX(1));
+ if (!poped) {
+ ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 2));
+ }
if (flag & VM_CALL_ARGS_SPLAT_BIT) {
ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1));
ADD_INSN(ret, nd_line(node), concatarray);
@@ -3821,9 +3836,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
ADD_SEND_R(ret, nd_line(node), ID2SYM(idASET),
INT2FIX(FIX2INT(argc) + 1), Qfalse, LONG2FIX(flag));
}
- }
- if (poped) {
ADD_INSN(ret, nd_line(node), pop);
}