summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2017-03-13 00:03:09 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-09-01 15:19:11 +0900
commitcbf841e3ed511123ba0457f3fc6b4c85ca075bd0 (patch)
tree0d89f46a2fd44b5e449b9ec2026f0a3167cf9bf5 /compile.c
parentd7bba95eba62093b521cd112ff629f5fddb0f0f5 (diff)
Extract compile_errinfo from iseq_compile_each0
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4795
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/compile.c b/compile.c
index 00bc3953ff..ee2507d898 100644
--- a/compile.c
+++ b/compile.c
@@ -8802,6 +8802,34 @@ compile_dots(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, in
return COMPILE_OK;
}
+static int
+compile_errinfo(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped)
+{
+ if (!popped) {
+ if (iseq->body->type == ISEQ_TYPE_RESCUE) {
+ ADD_GETLOCAL(ret, node, LVAR_ERRINFO, 0);
+ }
+ else {
+ const rb_iseq_t *ip = iseq;
+ int level = 0;
+ while (ip) {
+ if (ip->body->type == ISEQ_TYPE_RESCUE) {
+ break;
+ }
+ ip = ip->body->parent_iseq;
+ level++;
+ }
+ if (ip) {
+ ADD_GETLOCAL(ret, node, LVAR_ERRINFO, level);
+ }
+ else {
+ ADD_INSN(ret, node, putnil);
+ }
+ }
+ }
+ return COMPILE_OK;
+}
+
static int iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped);
/**
compile each node
@@ -9458,31 +9486,9 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
}
break;
}
- case NODE_ERRINFO:{
- if (!popped) {
- if (body->type == ISEQ_TYPE_RESCUE) {
- ADD_GETLOCAL(ret, node, LVAR_ERRINFO, 0);
- }
- else {
- const rb_iseq_t *ip = iseq;
- int level = 0;
- while (ip) {
- if (ip->body->type == ISEQ_TYPE_RESCUE) {
- break;
- }
- ip = ip->body->parent_iseq;
- level++;
- }
- if (ip) {
- ADD_GETLOCAL(ret, node, LVAR_ERRINFO, level);
- }
- else {
- ADD_INSN(ret, node, putnil);
- }
- }
- }
+ case NODE_ERRINFO:
+ CHECK(compile_errinfo(iseq, ret, node, popped));
break;
- }
case NODE_DEFINED:
if (!popped) {
CHECK(compile_defined_expr(iseq, ret, node, Qtrue));