compile.c: compile_return
* compile.c (compile_return): extract from iseq_compile_each. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
865decb508
commit
6806c16fef
118
compile.c
118
compile.c
@ -5102,6 +5102,66 @@ compile_ensure(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node,
|
|||||||
return COMPILE_OK;
|
return COMPILE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
compile_return(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped)
|
||||||
|
{
|
||||||
|
const int line = nd_line(node);
|
||||||
|
|
||||||
|
if (iseq) {
|
||||||
|
enum iseq_type type = iseq->body->type;
|
||||||
|
const rb_iseq_t *parent_iseq = iseq->body->parent_iseq;
|
||||||
|
enum iseq_type parent_type;
|
||||||
|
LABEL *splabel = 0;
|
||||||
|
|
||||||
|
if (type == ISEQ_TYPE_TOP) {
|
||||||
|
splabel = NEW_LABEL(line);
|
||||||
|
ADD_LABEL(ret, splabel);
|
||||||
|
ADD_ADJUST(ret, line, 0);
|
||||||
|
ADD_INSN(ret, line, putnil);
|
||||||
|
ADD_INSN(ret, line, leave);
|
||||||
|
ADD_ADJUST_RESTORE(ret, splabel);
|
||||||
|
return COMPILE_OK;
|
||||||
|
}
|
||||||
|
else if ((type == ISEQ_TYPE_RESCUE || type == ISEQ_TYPE_ENSURE || type == ISEQ_TYPE_MAIN) &&
|
||||||
|
parent_iseq &&
|
||||||
|
((parent_type = parent_iseq->body->type) == ISEQ_TYPE_TOP ||
|
||||||
|
parent_type == ISEQ_TYPE_MAIN)) {
|
||||||
|
ADD_INSN(ret, line, putnil);
|
||||||
|
ADD_INSN1(ret, line, throw, INT2FIX(TAG_RETURN));
|
||||||
|
if (popped) {
|
||||||
|
ADD_INSN(ret, line, pop);
|
||||||
|
}
|
||||||
|
return COMPILE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == ISEQ_TYPE_METHOD) {
|
||||||
|
splabel = NEW_LABEL(0);
|
||||||
|
ADD_LABEL(ret, splabel);
|
||||||
|
ADD_ADJUST(ret, line, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(COMPILE(ret, "return nd_stts (return val)", node->nd_stts));
|
||||||
|
|
||||||
|
if (type == ISEQ_TYPE_METHOD) {
|
||||||
|
add_ensure_iseq(ret, iseq, 1);
|
||||||
|
ADD_TRACE(ret, line, RUBY_EVENT_RETURN);
|
||||||
|
ADD_INSN(ret, line, leave);
|
||||||
|
ADD_ADJUST_RESTORE(ret, splabel);
|
||||||
|
|
||||||
|
if (!popped) {
|
||||||
|
ADD_INSN(ret, line, putnil);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ADD_INSN1(ret, line, throw, INT2FIX(TAG_RETURN));
|
||||||
|
if (popped) {
|
||||||
|
ADD_INSN(ret, line, pop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return COMPILE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static int iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int popped);
|
static int iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int popped);
|
||||||
/**
|
/**
|
||||||
compile each node
|
compile each node
|
||||||
@ -6014,63 +6074,9 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NODE_RETURN:{
|
case NODE_RETURN:
|
||||||
rb_iseq_t *is = iseq;
|
CHECK(compile_return(iseq, ret, node, popped));
|
||||||
|
|
||||||
if (is) {
|
|
||||||
enum iseq_type type = is->body->type;
|
|
||||||
const rb_iseq_t *parent_iseq = is->body->parent_iseq;
|
|
||||||
enum iseq_type parent_type;
|
|
||||||
|
|
||||||
if (type == ISEQ_TYPE_TOP) {
|
|
||||||
LABEL *splabel = NEW_LABEL(line);
|
|
||||||
ADD_LABEL(ret, splabel);
|
|
||||||
ADD_ADJUST(ret, line, 0);
|
|
||||||
ADD_INSN(ret, line, putnil);
|
|
||||||
ADD_INSN(ret, line, leave);
|
|
||||||
ADD_ADJUST_RESTORE(ret, splabel);
|
|
||||||
}
|
|
||||||
else if ((type == ISEQ_TYPE_RESCUE || type == ISEQ_TYPE_ENSURE || type == ISEQ_TYPE_MAIN) &&
|
|
||||||
parent_iseq &&
|
|
||||||
((parent_type = parent_iseq->body->type) == ISEQ_TYPE_TOP ||
|
|
||||||
parent_type == ISEQ_TYPE_MAIN)) {
|
|
||||||
ADD_INSN(ret, line, putnil);
|
|
||||||
ADD_INSN1(ret, line, throw, INT2FIX(TAG_RETURN));
|
|
||||||
if (popped) {
|
|
||||||
ADD_INSN(ret, line, pop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LABEL *splabel = 0;
|
|
||||||
|
|
||||||
if (type == ISEQ_TYPE_METHOD) {
|
|
||||||
splabel = NEW_LABEL(0);
|
|
||||||
ADD_LABEL(ret, splabel);
|
|
||||||
ADD_ADJUST(ret, line, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK(COMPILE(ret, "return nd_stts (return val)", node->nd_stts));
|
|
||||||
|
|
||||||
if (type == ISEQ_TYPE_METHOD) {
|
|
||||||
add_ensure_iseq(ret, iseq, 1);
|
|
||||||
ADD_TRACE(ret, line, RUBY_EVENT_RETURN);
|
|
||||||
ADD_INSN(ret, line, leave);
|
|
||||||
ADD_ADJUST_RESTORE(ret, splabel);
|
|
||||||
|
|
||||||
if (!popped) {
|
|
||||||
ADD_INSN(ret, line, putnil);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ADD_INSN1(ret, line, throw, INT2FIX(TAG_RETURN));
|
|
||||||
if (popped) {
|
|
||||||
ADD_INSN(ret, line, pop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case NODE_YIELD:{
|
case NODE_YIELD:{
|
||||||
DECL_ANCHOR(args);
|
DECL_ANCHOR(args);
|
||||||
VALUE argc;
|
VALUE argc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user