summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJemma Issroff <[email protected]>2023-08-30 17:27:08 -0400
committerGitHub <[email protected]>2023-08-30 14:27:08 -0700
commit0ec5021f3d14707d1354158b8dec26ba6e079396 (patch)
treebf1a243f1f15d4941819d55cc11e6d74915c33f9
parentf1790fa4e713f364bd6983586c0ba749e7b54968 (diff)
[YARP] Implement BreakNode, NextNode, RedoNode (#8334)
Notes
Notes: Merged-By: jemmaissroff
-rw-r--r--yarp/yarp_compiler.c47
1 files changed, 37 insertions, 10 deletions
diff --git a/yarp/yarp_compiler.c b/yarp/yarp_compiler.c
index e1e8ff6669..e75937d689 100644
--- a/yarp/yarp_compiler.c
+++ b/yarp/yarp_compiler.c
@@ -268,28 +268,25 @@ yp_compile_while(rb_iseq_t *iseq, int lineno, yp_node_flags_t flags, enum yp_nod
LABEL *prev_start_label = ISEQ_COMPILE_DATA(iseq)->start_label;
LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
LABEL *prev_redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label;
- int prev_loopval_popped = ISEQ_COMPILE_DATA(iseq)->loopval_popped;
// TODO: Deal with ensures in here
- LABEL *next_label = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(lineno); /* next */
- LABEL *redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label = NEW_LABEL(lineno); /* redo */
- LABEL *break_label = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(lineno); /* break */
+ LABEL *next_label = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(lineno); /* next */
+ LABEL *redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label = NEW_LABEL(lineno); /* redo */
+ LABEL *break_label = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(lineno); /* break */
LABEL *end_label = NEW_LABEL(lineno);
LABEL *adjust_label = NEW_LABEL(lineno);
LABEL *next_catch_label = NEW_LABEL(lineno);
LABEL *tmp_label = NULL;
- ISEQ_COMPILE_DATA(iseq)->loopval_popped = 0;
-
// begin; end while true
if (flags & YP_LOOP_FLAGS_BEGIN_MODIFIER) {
- ADD_INSNL(ret, &dummy_line_node, jump, next_label);
+ tmp_label = NEW_LABEL(lineno);
+ ADD_INSNL(ret, &dummy_line_node, jump, tmp_label);
}
else {
// while true; end
- tmp_label = NEW_LABEL(lineno);
- ADD_INSNL(ret, &dummy_line_node, jump, tmp_label);
+ ADD_INSNL(ret, &dummy_line_node, jump, next_label);
}
ADD_LABEL(ret, adjust_label);
@@ -334,7 +331,6 @@ yp_compile_while(rb_iseq_t *iseq, int lineno, yp_node_flags_t flags, enum yp_nod
ISEQ_COMPILE_DATA(iseq)->start_label = prev_start_label;
ISEQ_COMPILE_DATA(iseq)->end_label = prev_end_label;
ISEQ_COMPILE_DATA(iseq)->redo_label = prev_redo_label;
- ISEQ_COMPILE_DATA(iseq)->loopval_popped = prev_loopval_popped;
return;
}
@@ -483,6 +479,19 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
}
return;
}
+ case YP_NODE_BREAK_NODE: {
+ yp_break_node_t *break_node = (yp_break_node_t *) node;
+ if (break_node->arguments) {
+ yp_compile_node(iseq, (yp_node_t *)break_node->arguments, ret, src, Qfalse, compile_context);
+ }
+ else {
+ ADD_INSN(ret, &dummy_line_node, putnil);
+ }
+
+ ADD_INSNL(ret, &dummy_line_node, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
+
+ return;
+ }
case YP_NODE_CALL_NODE: {
yp_call_node_t *call_node = (yp_call_node_t *) node;
@@ -985,6 +994,20 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
return;
}
+ case YP_NODE_NEXT_NODE: {
+ yp_next_node_t *next_node = (yp_next_node_t *) node;
+ if (next_node->arguments) {
+ yp_compile_node(iseq, (yp_node_t *)next_node->arguments, ret, src, Qfalse, compile_context);
+ }
+ else {
+ ADD_INSN(ret, &dummy_line_node, putnil);
+ }
+
+ ADD_INSN(ret, &dummy_line_node, pop);
+ ADD_INSNL(ret, &dummy_line_node, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
+
+ return;
+ }
case YP_NODE_NIL_NODE:
if (!popped) {
ADD_INSN(ret, &dummy_line_node, putnil);
@@ -1086,6 +1109,10 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
}
return;
}
+ case YP_NODE_REDO_NODE: {
+ ADD_INSNL(ret, &dummy_line_node, jump, ISEQ_COMPILE_DATA(iseq)->redo_label);
+ return;
+ }
case YP_NODE_RETURN_NODE: {
yp_arguments_node_t *arguments = ((yp_return_node_t *)node)->arguments;