node.h: remove NODE_PRELUDE
NODE_PRELUDE contains a `BEGIN` node, a main node, and compile_option. This node is assumed that it must be located immediately under the root NODE_SCOPE, but this strange assumption is not so good, IMO. This change removes the assumtion; it integrates the former two nodes by block_append, and moves compile_option into rb_ast_body_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
92b81dc597
commit
38c62063c0
22
compile.c
22
compile.c
@ -1227,7 +1227,7 @@ new_child_iseq(rb_iseq_t *iseq, const NODE *const node,
|
|||||||
rb_ast_body_t ast;
|
rb_ast_body_t ast;
|
||||||
|
|
||||||
ast.root = node;
|
ast.root = node;
|
||||||
ast.reserved = 0;
|
ast.compile_option = 0;
|
||||||
|
|
||||||
debugs("[new_child_iseq]> ---------------------------------------\n");
|
debugs("[new_child_iseq]> ---------------------------------------\n");
|
||||||
ret_iseq = rb_iseq_new_with_opt(&ast, name,
|
ret_iseq = rb_iseq_new_with_opt(&ast, name,
|
||||||
@ -7098,26 +7098,6 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NODE_PRELUDE:{
|
|
||||||
const rb_compile_option_t *orig_opt = ISEQ_COMPILE_DATA(iseq)->option;
|
|
||||||
rb_compile_option_t new_opt = *orig_opt;
|
|
||||||
if (node->nd_compile_option) {
|
|
||||||
rb_iseq_make_compile_option(&new_opt, node->nd_compile_option);
|
|
||||||
ISEQ_COMPILE_DATA(iseq)->option = &new_opt;
|
|
||||||
}
|
|
||||||
if (!new_opt.coverage_enabled) ISEQ_COVERAGE_SET(iseq, Qfalse);
|
|
||||||
CHECK(COMPILE_POPPED(ret, "prelude", node->nd_head));
|
|
||||||
CHECK(COMPILE_(ret, "body", node->nd_body, popped));
|
|
||||||
ISEQ_COMPILE_DATA(iseq)->option = orig_opt;
|
|
||||||
/* Do NOT restore ISEQ_COVERAGE!
|
|
||||||
* If ISEQ_COVERAGE is not false, finish_iseq_build function in iseq.c
|
|
||||||
* will initialize the counter array of line coverage.
|
|
||||||
* We keep ISEQ_COVERAGE as nil to disable this initialization.
|
|
||||||
* This is not harmful assuming that NODE_PRELUDE pragma does not occur
|
|
||||||
* in NODE tree except the root.
|
|
||||||
*/
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NODE_LAMBDA:{
|
case NODE_LAMBDA:{
|
||||||
/* compile same as lambda{...} */
|
/* compile same as lambda{...} */
|
||||||
const rb_iseq_t *block = NEW_CHILD_ISEQ(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, line);
|
const rb_iseq_t *block = NEW_CHILD_ISEQ(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, line);
|
||||||
|
@ -469,7 +469,6 @@ count_nodes(int argc, VALUE *argv, VALUE os)
|
|||||||
COUNT_NODE(NODE_POSTEXE);
|
COUNT_NODE(NODE_POSTEXE);
|
||||||
COUNT_NODE(NODE_DSYM);
|
COUNT_NODE(NODE_DSYM);
|
||||||
COUNT_NODE(NODE_ATTRASGN);
|
COUNT_NODE(NODE_ATTRASGN);
|
||||||
COUNT_NODE(NODE_PRELUDE);
|
|
||||||
COUNT_NODE(NODE_LAMBDA);
|
COUNT_NODE(NODE_LAMBDA);
|
||||||
#undef COUNT_NODE
|
#undef COUNT_NODE
|
||||||
case NODE_LAST: break;
|
case NODE_LAST: break;
|
||||||
|
7
iseq.c
7
iseq.c
@ -520,9 +520,12 @@ rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE rea
|
|||||||
const NODE *node = ast ? ast->root : 0;
|
const NODE *node = ast ? ast->root : 0;
|
||||||
/* TODO: argument check */
|
/* TODO: argument check */
|
||||||
rb_iseq_t *iseq = iseq_alloc();
|
rb_iseq_t *iseq = iseq_alloc();
|
||||||
|
rb_compile_option_t new_opt;
|
||||||
|
|
||||||
if (!option) option = &COMPILE_OPTION_DEFAULT;
|
new_opt = option ? *option : COMPILE_OPTION_DEFAULT;
|
||||||
prepare_iseq_build(iseq, name, path, realpath, first_lineno, node ? &node->nd_loc : NULL, parent, type, option);
|
if (ast && ast->compile_option) rb_iseq_make_compile_option(&new_opt, ast->compile_option);
|
||||||
|
|
||||||
|
prepare_iseq_build(iseq, name, path, realpath, first_lineno, node ? &node->nd_loc : NULL, parent, type, &new_opt);
|
||||||
|
|
||||||
rb_iseq_compile_node(iseq, node);
|
rb_iseq_compile_node(iseq, node);
|
||||||
finish_iseq_build(iseq);
|
finish_iseq_build(iseq);
|
||||||
|
44
node.c
44
node.c
@ -101,37 +101,6 @@ struct add_option_arg {
|
|||||||
st_index_t count;
|
st_index_t count;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
|
||||||
add_option_i(VALUE key, VALUE val, VALUE args)
|
|
||||||
{
|
|
||||||
struct add_option_arg *argp = (void *)args;
|
|
||||||
VALUE buf = argp->buf;
|
|
||||||
VALUE indent = argp->indent;
|
|
||||||
|
|
||||||
A_INDENT;
|
|
||||||
A("+- ");
|
|
||||||
AR(rb_sym2str(key));
|
|
||||||
A(": ");
|
|
||||||
A_LIT(val);
|
|
||||||
A("\n");
|
|
||||||
return ST_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
dump_option(VALUE buf, VALUE indent, VALUE opt)
|
|
||||||
{
|
|
||||||
struct add_option_arg arg;
|
|
||||||
|
|
||||||
if (!RB_TYPE_P(opt, T_HASH)) {
|
|
||||||
A_LIT(opt);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
arg.buf = buf;
|
|
||||||
arg.indent = indent;
|
|
||||||
arg.count = 0;
|
|
||||||
rb_hash_foreach(opt, add_option_i, (VALUE)&arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dump_node(VALUE, VALUE, int, const NODE *);
|
static void dump_node(VALUE, VALUE, int, const NODE *);
|
||||||
static const char default_indent[] = "| ";
|
static const char default_indent[] = "| ";
|
||||||
|
|
||||||
@ -960,19 +929,6 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
|
|||||||
F_NODE(nd_args, "arguments");
|
F_NODE(nd_args, "arguments");
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case NODE_PRELUDE:
|
|
||||||
ANN("pre-execution");
|
|
||||||
ANN("format: BEGIN { [nd_head] }; [nd_body]");
|
|
||||||
ANN("example: bar; BEGIN { foo }");
|
|
||||||
F_NODE(nd_head, "prelude");
|
|
||||||
if (!node->nd_compile_option) LAST_NODE;
|
|
||||||
F_NODE(nd_body, "body");
|
|
||||||
if (node->nd_compile_option) {
|
|
||||||
LAST_NODE;
|
|
||||||
F_OPTION(nd_compile_option, "compile_option");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
|
|
||||||
case NODE_LAMBDA:
|
case NODE_LAMBDA:
|
||||||
ANN("lambda expression");
|
ANN("lambda expression");
|
||||||
ANN("format: -> [nd_body]");
|
ANN("format: -> [nd_body]");
|
||||||
|
5
node.h
5
node.h
@ -216,8 +216,6 @@ enum node_type {
|
|||||||
#define NODE_DSYM NODE_DSYM
|
#define NODE_DSYM NODE_DSYM
|
||||||
NODE_ATTRASGN,
|
NODE_ATTRASGN,
|
||||||
#define NODE_ATTRASGN NODE_ATTRASGN
|
#define NODE_ATTRASGN NODE_ATTRASGN
|
||||||
NODE_PRELUDE,
|
|
||||||
#define NODE_PRELUDE NODE_PRELUDE
|
|
||||||
NODE_LAMBDA,
|
NODE_LAMBDA,
|
||||||
#define NODE_LAMBDA NODE_LAMBDA
|
#define NODE_LAMBDA NODE_LAMBDA
|
||||||
NODE_LAST
|
NODE_LAST
|
||||||
@ -458,7 +456,6 @@ typedef struct RNode {
|
|||||||
#define NEW_PREEXE(b) NEW_SCOPE(b)
|
#define NEW_PREEXE(b) NEW_SCOPE(b)
|
||||||
#define NEW_POSTEXE(b) NEW_NODE(NODE_POSTEXE,0,b,0)
|
#define NEW_POSTEXE(b) NEW_NODE(NODE_POSTEXE,0,b,0)
|
||||||
#define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
|
#define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
|
||||||
#define NEW_PRELUDE(p,b,o) NEW_NODE(NODE_PRELUDE,p,b,o)
|
|
||||||
|
|
||||||
#define NODE_SPECIAL_REQUIRED_KEYWORD ((NODE *)-1)
|
#define NODE_SPECIAL_REQUIRED_KEYWORD ((NODE *)-1)
|
||||||
#define NODE_SPECIAL_NO_NAME_REST ((NODE *)-1)
|
#define NODE_SPECIAL_NO_NAME_REST ((NODE *)-1)
|
||||||
@ -469,7 +466,7 @@ typedef struct node_buffer_struct node_buffer_t;
|
|||||||
/* T_IMEMO/ast */
|
/* T_IMEMO/ast */
|
||||||
typedef struct rb_ast_body_struct {
|
typedef struct rb_ast_body_struct {
|
||||||
const NODE *root;
|
const NODE *root;
|
||||||
VALUE reserved;
|
VALUE compile_option;
|
||||||
} rb_ast_body_t;
|
} rb_ast_body_t;
|
||||||
typedef struct rb_ast_struct {
|
typedef struct rb_ast_struct {
|
||||||
VALUE flags;
|
VALUE flags;
|
||||||
|
10
parse.y
10
parse.y
@ -5646,7 +5646,7 @@ yycompile0(VALUE arg)
|
|||||||
mesg = rb_class_new_instance(0, 0, rb_eSyntaxError);
|
mesg = rb_class_new_instance(0, 0, rb_eSyntaxError);
|
||||||
}
|
}
|
||||||
rb_set_errinfo(mesg);
|
rb_set_errinfo(mesg);
|
||||||
return 0;
|
return FALSE;
|
||||||
}
|
}
|
||||||
tree = ruby_eval_tree;
|
tree = ruby_eval_tree;
|
||||||
if (!tree) {
|
if (!tree) {
|
||||||
@ -5658,12 +5658,14 @@ yycompile0(VALUE arg)
|
|||||||
NODE *body = parser_append_options(parser, tree->nd_body);
|
NODE *body = parser_append_options(parser, tree->nd_body);
|
||||||
if (!opt) opt = rb_obj_hide(rb_ident_hash_new());
|
if (!opt) opt = rb_obj_hide(rb_ident_hash_new());
|
||||||
rb_hash_aset(opt, rb_sym_intern_ascii_cstr("coverage_enabled"), cov);
|
rb_hash_aset(opt, rb_sym_intern_ascii_cstr("coverage_enabled"), cov);
|
||||||
prelude = NEW_PRELUDE(ruby_eval_tree_begin, body, opt);
|
prelude = block_append(ruby_eval_tree_begin, body, &body->nd_loc /* dummy location */);
|
||||||
add_mark_object(opt);
|
add_mark_object(opt);
|
||||||
prelude->nd_loc = body->nd_loc;
|
prelude->nd_loc = body->nd_loc;
|
||||||
tree->nd_body = prelude;
|
tree->nd_body = prelude;
|
||||||
|
parser->ast->body.compile_option = opt;
|
||||||
}
|
}
|
||||||
return (VALUE)tree;
|
parser->ast->body.root = tree;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rb_ast_t *
|
static rb_ast_t *
|
||||||
@ -5675,7 +5677,7 @@ yycompile(VALUE vparser, struct parser_params *parser, VALUE fname, int line)
|
|||||||
ruby_sourceline = line - 1;
|
ruby_sourceline = line - 1;
|
||||||
|
|
||||||
parser->ast = ast = rb_ast_new();
|
parser->ast = ast = rb_ast_new();
|
||||||
ast->body.root = (NODE *)rb_suppress_tracing(yycompile0, (VALUE)parser);
|
rb_suppress_tracing(yycompile0, (VALUE)parser);
|
||||||
parser->ast = 0;
|
parser->ast = 0;
|
||||||
RB_GC_GUARD(vparser); /* prohibit tail call optimization */
|
RB_GC_GUARD(vparser); /* prohibit tail call optimization */
|
||||||
|
|
||||||
|
2
vm.c
2
vm.c
@ -953,7 +953,7 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I
|
|||||||
MEMCPY(dyns + 1, dynvars, ID, dyncount);
|
MEMCPY(dyns + 1, dynvars, ID, dyncount);
|
||||||
rb_node_init(&tmp_node, NODE_SCOPE, (VALUE)dyns, 0, 0);
|
rb_node_init(&tmp_node, NODE_SCOPE, (VALUE)dyns, 0, 0);
|
||||||
ast.root = &tmp_node;
|
ast.root = &tmp_node;
|
||||||
ast.reserved = 0;
|
ast.compile_option = 0;
|
||||||
|
|
||||||
if (base_iseq) {
|
if (base_iseq) {
|
||||||
iseq = rb_iseq_new(&ast, base_iseq->body->location.label, path, realpath, base_iseq, ISEQ_TYPE_EVAL);
|
iseq = rb_iseq_new(&ast, base_iseq->body->location.label, path, realpath, base_iseq, ISEQ_TYPE_EVAL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user