Skip to content

Commit c492a7f

Browse files
authored
[YARP] Miscellaneous bug fixes (#8453)
Miscellaneous bug fixes
1 parent c87f2a4 commit c492a7f

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

yarp/yarp_compiler.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ yp_static_node_literal_p(yp_node_t *node)
151151
case YP_INTEGER_NODE:
152152
case YP_NIL_NODE:
153153
case YP_RATIONAL_NODE:
154-
case YP_SELF_NODE:
155154
case YP_STRING_NODE:
156-
case YP_SOURCE_ENCODING_NODE:
157-
case YP_SOURCE_FILE_NODE:
158-
case YP_SOURCE_LINE_NODE:
159155
case YP_SYMBOL_NODE:
160156
case YP_TRUE_NODE:
161157
return true;
@@ -167,13 +163,25 @@ yp_static_node_literal_p(yp_node_t *node)
167163
static inline VALUE
168164
yp_static_literal_value(yp_node_t *node)
169165
{
170-
switch (YP_NODE_TYPE(node)) {
166+
switch(YP_NODE_TYPE(node)) {
167+
case YP_FALSE_NODE:
168+
return Qfalse;
169+
case YP_FLOAT_NODE:
170+
return parse_float(node);
171+
case YP_IMAGINARY_NODE:
172+
return parse_imaginary((yp_imaginary_node_t *)node);
173+
case YP_INTEGER_NODE:
174+
return parse_integer(node);
171175
case YP_NIL_NODE:
172176
return Qnil;
177+
case YP_RATIONAL_NODE:
178+
return parse_rational(node);
179+
case YP_STRING_NODE:
180+
return parse_string(&((yp_string_node_t *)node)->unescaped);
181+
case YP_SYMBOL_NODE:
182+
return ID2SYM(parse_string_symbol(&((yp_symbol_node_t *)node)->unescaped));
173183
case YP_TRUE_NODE:
174184
return Qtrue;
175-
case YP_FALSE_NODE:
176-
return Qfalse;
177185
// TODO: Implement this method for the other literal nodes described above
178186
default:
179187
rb_raise(rb_eArgError, "Don't have a literal value for this type");
@@ -296,6 +304,9 @@ yp_compile_if(rb_iseq_t *iseq, const int line, yp_statements_node_t *node_body,
296304
INIT_ANCHOR(then_seq);
297305
if (node_body) {
298306
yp_compile_node(iseq, (yp_node_t *)node_body, then_seq, src, popped, compile_context);
307+
if (popped) {
308+
ADD_INSN(ret, &line_node, pop);
309+
}
299310
}
300311
else {
301312
if (!popped) {
@@ -334,9 +345,6 @@ yp_compile_if(rb_iseq_t *iseq, const int line, yp_statements_node_t *node_body,
334345
ADD_LABEL(ret, end_label);
335346
}
336347

337-
if (popped) {
338-
ADD_INSN(ret, &line_node, pop);
339-
}
340348
return;
341349
}
342350

@@ -427,10 +435,13 @@ yp_interpolated_node_compile(yp_node_list_t parts, rb_iseq_t *iseq, NODE dummy_l
427435
ADD_INSN1(ret, &dummy_line_node, putobject, parse_string(&string_node->unescaped));
428436
}
429437
else {
430-
YP_COMPILE(part);
438+
YP_COMPILE_NOT_POPPED(part);
431439
ADD_INSN(ret, &dummy_line_node, dup);
432440
ADD_INSN1(ret, &dummy_line_node, objtostring, new_callinfo(iseq, idTo_s, 0, VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE , NULL, FALSE));
433441
ADD_INSN(ret, &dummy_line_node, anytostring);
442+
if (popped) {
443+
ADD_INSN(ret, &dummy_line_node, pop);
444+
}
434445
}
435446
}
436447
}
@@ -550,7 +561,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
550561
yp_and_node_t *and_node = (yp_and_node_t *) node;
551562

552563
LABEL *end_label = NEW_LABEL(lineno);
553-
YP_COMPILE(and_node->left);
564+
YP_COMPILE_NOT_POPPED(and_node->left);
554565
if (!popped) {
555566
ADD_INSN(ret, &dummy_line_node, dup);
556567
}
@@ -574,7 +585,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
574585
case YP_ARRAY_NODE: {
575586
yp_array_node_t *array_node = (yp_array_node_t *) node;
576587
yp_node_list_t elements = array_node->elements;
577-
if (elements.size == 1 && yp_static_node_literal_p(elements.nodes[0])) {
588+
if (elements.size == 1 && yp_static_node_literal_p(elements.nodes[0]) && !popped) {
578589
VALUE ary = rb_ary_hidden_new(1);
579590
rb_ary_push(ary, yp_static_literal_value(elements.nodes[0]));
580591
OBJ_FREEZE(ary);
@@ -665,7 +676,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
665676
}
666677
} else {
667678
yp_arguments_node_t *arguments = call_node->arguments;
668-
YP_COMPILE((yp_node_t *) arguments);
679+
YP_COMPILE_NOT_POPPED((yp_node_t *) arguments);
669680
orig_argc = (int)arguments->arguments.size;
670681
}
671682

@@ -1402,9 +1413,6 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
14021413
if (!popped) {
14031414
ADD_INSN(ret, &dummy_line_node, intern);
14041415
}
1405-
else {
1406-
ADD_INSN(ret, &dummy_line_node, pop);
1407-
}
14081416

14091417
return;
14101418
}
@@ -1638,7 +1646,7 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
16381646
yp_or_node_t *or_node = (yp_or_node_t *) node;
16391647

16401648
LABEL *end_label = NEW_LABEL(lineno);
1641-
YP_COMPILE(or_node->left);
1649+
YP_COMPILE_NOT_POPPED(or_node->left);
16421650

16431651
if (!popped) {
16441652
ADD_INSN(ret, &dummy_line_node, dup);
@@ -1901,10 +1909,6 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
19011909
INT2FIX(VM_DEFINECLASS_TYPE_SINGLETON_CLASS));
19021910
RB_OBJ_WRITTEN(iseq, Qundef, (VALUE)singleton_class);
19031911

1904-
if (popped) {
1905-
ADD_INSN(ret, &dummy_line_node, pop);
1906-
}
1907-
19081912
return;
19091913
}
19101914
case YP_SOURCE_ENCODING_NODE: {

0 commit comments

Comments
 (0)