Refactor ISEQ_TYPE_DEFINED_GUARD out

This commit removes ISEQ_TYPE_DEFINED_GUARD because it is no longer
needed.  And this introduces ISEQ_TYPE_PLAIN which means that the iseq
does nothing special but just wrap an expression.  Currently, this is
used for once execution: `/foo#{ bar }baz/o`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2018-01-05 00:49:41 +00:00
Родитель ecc29dc209
Коммит e1428e5c92
3 изменённых файлов: 10 добавлений и 15 удалений

Просмотреть файл

@ -29,8 +29,6 @@
#undef RUBY_UNTYPED_DATA_WARNING
#define RUBY_UNTYPED_DATA_WARNING 0
#define ISEQ_TYPE_ONCE_GUARD ISEQ_TYPE_DEFINED_GUARD
#define FIXNUM_INC(n, i) ((n)+(INT2FIX(i)&~FIXNUM_FLAG))
#define FIXNUM_OR(n, i) ((n)|INT2FIX(i))
@ -706,9 +704,8 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node)
iseq_set_exception_local_table(iseq);
CHECK(COMPILE_POPPED(ret, "ensure", node));
break;
case ISEQ_TYPE_DEFINED_GUARD:
iseq_set_exception_local_table(iseq);
CHECK(COMPILE(ret, "defined guard", node));
case ISEQ_TYPE_PLAIN:
CHECK(COMPILE(ret, "ensure", node));
break;
default:
COMPILE_ERROR(ERROR_ARGS "unknown scope: %d", iseq->body->type);
@ -6626,10 +6623,8 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
}
case NODE_ONCE:{
int ic_index = iseq->body->is_size++;
NODE tmp_node;
const rb_iseq_t *block_iseq;
rb_node_init(&tmp_node, NODE_SCOPE, 0, (VALUE)node->nd_body, 0);
block_iseq = NEW_CHILD_ISEQ(&tmp_node, make_name_for_block(iseq), ISEQ_TYPE_ONCE_GUARD, line);
block_iseq = NEW_CHILD_ISEQ(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_PLAIN, line);
ADD_INSN2(ret, line, once, block_iseq, INT2FIX(ic_index));

12
iseq.c
Просмотреть файл

@ -575,7 +575,7 @@ iseq_type_from_sym(VALUE type)
const ID id_ensure = rb_intern("ensure");
const ID id_eval = rb_intern("eval");
const ID id_main = rb_intern("main");
const ID id_defined_guard = rb_intern("defined_guard");
const ID id_plain = rb_intern("plain");
/* ensure all symbols are static or pinned down before
* conversion */
const ID typeid = rb_check_id(&type);
@ -587,7 +587,7 @@ iseq_type_from_sym(VALUE type)
if (typeid == id_ensure) return ISEQ_TYPE_ENSURE;
if (typeid == id_eval) return ISEQ_TYPE_EVAL;
if (typeid == id_main) return ISEQ_TYPE_MAIN;
if (typeid == id_defined_guard) return ISEQ_TYPE_DEFINED_GUARD;
if (typeid == id_plain) return ISEQ_TYPE_PLAIN;
return (enum iseq_type)-1;
}
@ -1240,7 +1240,7 @@ static VALUE iseq_data_to_ary(const rb_iseq_t *iseq);
* The type of the instruction sequence.
*
* Valid values are +:top+, +:method+, +:block+, +:class+, +:rescue+,
* +:ensure+, +:eval+, +:main+, and +:defined_guard+.
* +:ensure+, +:eval+, +:main+, and +plain+.
*
* [locals]
* An array containing the names of all arguments and local variables as
@ -2145,7 +2145,7 @@ iseq_data_to_ary(const rb_iseq_t *iseq)
DECL_SYMBOL(ensure);
DECL_SYMBOL(eval);
DECL_SYMBOL(main);
DECL_SYMBOL(defined_guard);
DECL_SYMBOL(plain);
if (sym_top == 0) {
int i;
@ -2160,7 +2160,7 @@ iseq_data_to_ary(const rb_iseq_t *iseq)
INIT_SYMBOL(ensure);
INIT_SYMBOL(eval);
INIT_SYMBOL(main);
INIT_SYMBOL(defined_guard);
INIT_SYMBOL(plain);
}
/* type */
@ -2173,7 +2173,7 @@ iseq_data_to_ary(const rb_iseq_t *iseq)
case ISEQ_TYPE_ENSURE: type = sym_ensure; break;
case ISEQ_TYPE_EVAL: type = sym_eval; break;
case ISEQ_TYPE_MAIN: type = sym_main; break;
case ISEQ_TYPE_DEFINED_GUARD: type = sym_defined_guard; break;
case ISEQ_TYPE_PLAIN: type = sym_plain; break;
default: rb_bug("unsupported iseq type");
};

Просмотреть файл

@ -299,7 +299,7 @@ struct rb_iseq_constant_body {
ISEQ_TYPE_ENSURE,
ISEQ_TYPE_EVAL,
ISEQ_TYPE_MAIN,
ISEQ_TYPE_DEFINED_GUARD
ISEQ_TYPE_PLAIN
} type; /* instruction sequence type */
unsigned int iseq_size;