10000 Remove compiler code to handle keywords and blocks in operator assign… · jeremyevans/ruby@3567335 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3567335

Browse files
committed
Remove compiler code to handle keywords and blocks in operator assignment syntax
Code such as: ```ruby foo[0, &bar] = baz foo[0, bar: 1] = baz foo[0, **bar] = baz ``` Is now a syntax error, so all of the removed code is now dead.
1 parent 548203e commit 3567335

File tree

1 file changed

+13
-103
lines changed

1 file changed

+13
-103
lines changed

compile.c

Lines changed: 13 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -9038,9 +9038,6 @@ compile_op_asgn1(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node
90389038
unsigned int flag = 0;
90399039
int asgnflag = 0;
90409040
ID id = RNODE_OP_ASGN1(node)->nd_mid;
9041-
int boff = 0;
9042-
int keyword_len = 0;
9043-
struct rb_callinfo_kwarg *keywords = NULL;
90449041

90459042
/*
90469043
* a[x] (op)= y
@@ -9074,32 +9071,14 @@ compile_op_asgn1(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node
90749071
case NODE_ZLIST:
90759072
argc = INT2FIX(0);
90769073
break;
9077-
case NODE_BLOCK_PASS:
9078-
boff = 1;
9079-
/* fall through */
90809074
default:
9081-
argc = setup_args(iseq, ret, RNODE_OP_ASGN1(node)->nd_index, &flag, &keywords);
9082-
if (flag & VM_CALL_KW_SPLAT) {
9083-
if (boff) {
9084-
ADD_INSN(ret, node, splatkw);
9085-
}
9086-
else {
9087-
/* Make sure to_hash is only called once and not twice */
9088-
ADD_INSN(ret, node, dup);
9089-
ADD_INSN(ret, node, splatkw);
9090-
ADD_INSN(ret, node, pop);
9091-
}
9092-
}
9075+
argc = setup_args(iseq, ret, RNODE_OP_ASGN1(node)->nd_index, &flag, NULL);
90939076
CHECK(!NIL_P(argc));
90949077
}
9095-
int dup_argn = FIX2INT(argc) + 1 + boff;
9096-
if (keywords) {
9097-
keyword_len = keywords->keyword_len;
9098-
dup_argn += keyword_len;
9099-
}
9078+
int dup_argn = FIX2INT(argc) + 1;
91009079
ADD_INSN1(ret, node, dupn, INT2FIX(dup_argn));
91019080
flag |= asgnflag;
9102-
ADD_SEND_R(ret, node, idAREF, argc, NULL, INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT|VM_CALL_KW_SPLAT_MUT)), keywords);
9081+
ADD_SEND_R(ret, node, idAREF, argc, NULL, INT2FIX(flag & ~VM_CALL_ARGS_SPLAT_MUT), NULL);
91039082

91049083
if (id == idOROP || id == idANDOP) {
91059084
/* a[x] ||= y or a[x] &&= y
@@ -9127,57 +9106,17 @@ compile_op_asgn1(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node
91279106
ADD_INSN1(ret, node, setn, INT2FIX(dup_argn+1));
91289107
}
91299108
if (flag & VM_CALL_ARGS_SPLAT) {
9130-
if (flag & VM_CALL_KW_SPLAT) {
9131-
ADD_INSN1(ret, node, topn, INT2FIX(2 + boff));
9132-
if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
9133-
ADD_INSN1(ret, node, splatarray, Qtrue);
9134-
flag |= VM_CALL_ARGS_SPLAT_MUT;
9135-
}
9109+
if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
91369110
ADD_INSN(ret, node, swap);
9137-
ADD_INSN1(ret, node, pushtoarray, INT2FIX(1));
9138-
ADD_INSN1(ret, node, setn, INT2FIX(2 + boff));
9139-
ADD_INSN(ret, node, pop);
9140-
}
9141-
else {
9142-
if (boff > 0) {
9143-
ADD_INSN1(ret, node, dupn, INT2FIX(3));
9144-
ADD_INSN(ret, node, swap);
9145-
ADD_INSN(ret, node, pop);
9146-
}
9147-
if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
9148-
ADD_INSN(ret, node, swap);
9149-
ADD_INSN1(ret, node, splatarray, Qtrue);
9150-
ADD_INSN(ret, node, swap);
9151-
flag |= VM_CALL_ARGS_SPLAT_MUT;
9152-
}
9153-
ADD_INSN1(ret, node, pushtoarray, INT2FIX(1));
9154-
if (boff > 0) {
9155-
ADD_INSN1(ret, node, setn, INT2FIX(3));
9156-
ADD_INSN(ret, node, pop);
9157-
ADD_INSN(ret, node, pop);
9158-
}
9159-
}
9160-
ADD_SEND_R(ret, node, idASET, argc, NULL, INT2FIX(flag), keywords);
9161-
}
9162-
else if (flag & VM_CALL_KW_SPLAT) {
9163-
if (boff > 0) {
9164-
ADD_INSN1(ret, node, topn, INT2FIX(2));
9111+
ADD_INSN1(ret, node, splatarray, Qtrue);
91659112
ADD_INSN(ret, node, swap);
9166-
ADD_INSN1(ret, node, setn, INT2FIX(3));
9167-
ADD_INSN(ret, node, pop);
9113+
flag |= VM_CALL_ARGS_SPLAT_MUT;
91689114
}
9169-
ADD_INSN(ret, node, swap);
9170-
ADD_SEND_R(ret, node, idASET, FIXNUM_INC(argc, 1), NULL, INT2FIX(flag), keywords);
9171-
}
9172-
else if (keyword_len) {
9173-
ADD_INSN1(ret, node, opt_reverse, INT2FIX(keyword_len+boff+1));
9174-
ADD_INSN1(ret, node, opt_reverse, INT2FIX(keyword_len+boff+0));
9175-
ADD_SEND_R(ret, node, idASET, FIXNUM_INC(argc, 1), NULL, INT2FIX(flag), keywords);
9115+
ADD_INSN1(ret, node, pushtoarray, INT2FIX(1));
9116+
ADD_SEND_R(ret, node, idASET, argc, NULL, INT2FIX(flag), NULL);
91769117
}
91779118
else {
9178-
if (boff > 0)
9179-
ADD_INSN(ret, node, swap);
9180-
ADD_SEND_R(ret, node, idASET, FIXNUM_INC(argc, 1), NULL, INT2FIX(flag), keywords);
9119+
ADD_SEND_R(ret, node, idASET, FIXNUM_INC(argc, 1), NULL, INT2FIX(flag), NULL);
91819120
}
91829121
ADD_INSN(ret, node, pop);
91839122
ADD_INSNL(ret, node, jump, lfin);
@@ -9196,58 +9135,29 @@ compile_op_asgn1(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node
91969135
}
91979136
if (flag & VM_CALL_ARGS_SPLAT) {
91989137
if (flag & VM_CALL_KW_SPLAT) {
9199-
ADD_INSN1(ret, node, topn, INT2FIX(2 + boff));
9138+
ADD_INSN1(ret, node, topn, INT2FIX(2));
92009139
if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
92019140
ADD_INSN1(ret, node, splatarray, Qtrue);
92029141
flag |= VM_CALL_ARGS_SPLAT_MUT;
92039142
}
92049143
ADD_INSN(ret, node, swap);
92059144
ADD_INSN1(ret, node, pushtoarray, INT2FIX(1));
9206-
ADD_INSN1(ret, node, setn, INT2FIX(2 + boff));
9145+
ADD_INSN1(ret, node, setn, INT2FIX(2));
92079146
ADD_INSN(ret, node, pop);
92089147
}
92099148
else {
9210-
if (boff > 0) {
9211-
ADD_INSN1(ret, node, dupn, INT2FIX(3));
9212-
ADD_INSN(ret, node, swap);
9213-
ADD_INSN(ret, node, pop);
9214-
}
92159149
if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
92169150
ADD_INSN(ret, node, swap);
92179151
ADD_INSN1(ret, node, splatarray, Qtrue);
92189152
ADD_INSN(ret, node, swap);
92199153
flag |= VM_CALL_ARGS_SPLAT_MUT;
92209154
}
92219155
ADD_INSN1(ret, node, pushtoarray, INT2FIX(1));
9222-
if (boff > 0) {
9223-
ADD_INSN1(ret, node, setn, INT2FIX(3));
9224-
ADD_INSN(ret, node, pop);
9225-
ADD_INSN(ret, node, pop);
9226-
}
9227-
}
9228-
ADD_SEND_R(ret, node, idASET, argc, NULL, INT2FIX(flag), keywords);
9229-
}
9230-
else if (flag & VM_CALL_KW_SPLAT) {
9231-
if (boff > 0) {
9232-
ADD_INSN1(ret, node, topn, INT2FIX(2));
9233-
ADD_INSN(ret, node, swap);
9234-
ADD_INSN1(ret, node, setn, INT2FIX(3));
9235-
ADD_INSN(ret, node, pop);
92369156
}
9237-
ADD_INSN(ret, node, swap);
9238-
ADD_SEND_R(ret, node, idASET, FIXNUM_INC(argc, 1), NULL, INT2FIX(flag), keywords);
9239-
}
9240-
else if (keyword_len) {
9241-
ADD_INSN(ret, node, dup);
9242-
ADD_INSN1(ret, node, opt_reverse, INT2FIX(keyword_len+boff+2));
9243-
ADD_INSN1(ret, node, opt_reverse, INT2FIX(keyword_len+boff+1));
9244-
ADD_INSN(ret, node, pop);
9245-
ADD_SEND_R(ret, node, idASET, FIXNUM_INC(argc, 1), NULL, INT2FIX(flag), keywords);
9157+
ADD_SEND_R(ret, node, idASET, argc, NULL, INT2FIX(flag), NULL);
92469158
}
92479159
else {
9248-
if (boff > 0)
9249-
ADD_INSN(ret, node, swap);
9250-
ADD_SEND_R(ret, node, idASET, FIXNUM_INC(argc, 1), NULL, INT2FIX(flag), keywords);
9160+
ADD_SEND_R(ret, node, idASET, FIXNUM_INC(argc, 1), NULL, INT2FIX(flag), NULL);
92519161
}
92529162
ADD_INSN(ret, node, pop);
92539163
}

0 commit comments

Comments
 (0)
0