[前][次][番号順一覧][スレッド一覧]

ruby-changes:49495

From: mame <ko1@a...>
Date: Fri, 5 Jan 2018 17:59:29 +0900 (JST)
Subject: [ruby-changes:49495] mame:r61610 (trunk): node.h: remove NODE_PRELUDE

mame	2018-01-05 17:59:23 +0900 (Fri, 05 Jan 2018)

  New Revision: 61610

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61610

  Log:
    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.

  Modified files:
    trunk/compile.c
    trunk/ext/objspace/objspace.c
    trunk/iseq.c
    trunk/node.c
    trunk/node.h
    trunk/parse.y
    trunk/vm.c
Index: node.c
===================================================================
--- node.c	(revision 61609)
+++ node.c	(revision 61610)
@@ -101,37 +101,6 @@ struct add_option_arg { https://github.com/ruby/ruby/blob/trunk/node.c#L101
     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 const char default_indent[] = "|   ";
 
@@ -960,19 +929,6 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L929
 	F_NODE(nd_args, "arguments");
 	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:
 	ANN("lambda expression");
 	ANN("format: -> [nd_body]");
Index: node.h
===================================================================
--- node.h	(revision 61609)
+++ node.h	(revision 61610)
@@ -216,8 +216,6 @@ enum node_type { https://github.com/ruby/ruby/blob/trunk/node.h#L216
 #define NODE_DSYM        NODE_DSYM
     NODE_ATTRASGN,
 #define NODE_ATTRASGN    NODE_ATTRASGN
-    NODE_PRELUDE,
-#define NODE_PRELUDE     NODE_PRELUDE
     NODE_LAMBDA,
 #define NODE_LAMBDA      NODE_LAMBDA
     NODE_LAST
@@ -458,7 +456,6 @@ typedef struct RNode { https://github.com/ruby/ruby/blob/trunk/node.h#L456
 #define NEW_PREEXE(b) NEW_SCOPE(b)
 #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_PRELUDE(p,b,o) NEW_NODE(NODE_PRELUDE,p,b,o)
 
 #define NODE_SPECIAL_REQUIRED_KEYWORD ((NODE *)-1)
 #define NODE_SPECIAL_NO_NAME_REST     ((NODE *)-1)
@@ -469,7 +466,7 @@ typedef struct node_buffer_struct node_b https://github.com/ruby/ruby/blob/trunk/node.h#L466
 /* T_IMEMO/ast */
 typedef struct rb_ast_body_struct {
     const NODE *root;
-    VALUE reserved;
+    VALUE compile_option;
 } rb_ast_body_t;
 typedef struct rb_ast_struct {
     VALUE flags;
Index: parse.y
===================================================================
--- parse.y	(revision 61609)
+++ parse.y	(revision 61610)
@@ -5646,7 +5646,7 @@ yycompile0(VALUE arg) https://github.com/ruby/ruby/blob/trunk/parse.y#L5646
 	    mesg = rb_class_new_instance(0, 0, rb_eSyntaxError);
 	}
 	rb_set_errinfo(mesg);
-	return 0;
+	return FALSE;
     }
     tree = ruby_eval_tree;
     if (!tree) {
@@ -5658,12 +5658,14 @@ yycompile0(VALUE arg) https://github.com/ruby/ruby/blob/trunk/parse.y#L5658
 	NODE *body = parser_append_options(parser, tree->nd_body);
 	if (!opt) opt = rb_obj_hide(rb_ident_hash_new());
 	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);
 	prelude->nd_loc = body->nd_loc;
 	tree->nd_body = prelude;
+	parser->ast->body.compile_option = opt;
     }
-    return (VALUE)tree;
+    parser->ast->body.root = tree;
+    return TRUE;
 }
 
 static rb_ast_t *
@@ -5675,7 +5677,7 @@ yycompile(VALUE vparser, struct parser_p https://github.com/ruby/ruby/blob/trunk/parse.y#L5677
     ruby_sourceline = line - 1;
 
     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;
     RB_GC_GUARD(vparser); /* prohibit tail call optimization */
 
Index: ext/objspace/objspace.c
===================================================================
--- ext/objspace/objspace.c	(revision 61609)
+++ ext/objspace/objspace.c	(revision 61610)
@@ -469,7 +469,6 @@ count_nodes(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L469
 		COUNT_NODE(NODE_POSTEXE);
 		COUNT_NODE(NODE_DSYM);
 		COUNT_NODE(NODE_ATTRASGN);
-		COUNT_NODE(NODE_PRELUDE);
 		COUNT_NODE(NODE_LAMBDA);
 #undef COUNT_NODE
 	      case NODE_LAST: break;
Index: iseq.c
===================================================================
--- iseq.c	(revision 61609)
+++ iseq.c	(revision 61610)
@@ -520,9 +520,12 @@ rb_iseq_new_with_opt(const rb_ast_body_t https://github.com/ruby/ruby/blob/trunk/iseq.c#L520
     const NODE *node = ast ? ast->root : 0;
     /* TODO: argument check */
     rb_iseq_t *iseq = iseq_alloc();
+    rb_compile_option_t new_opt;
 
-    if (!option) option = &COMPILE_OPTION_DEFAULT;
-    prepare_iseq_build(iseq, name, path, realpath, first_lineno, node ? &node->nd_loc : NULL, parent, type, option);
+    new_opt = option ? *option : COMPILE_OPTION_DEFAULT;
+    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);
     finish_iseq_build(iseq);
Index: vm.c
===================================================================
--- vm.c	(revision 61609)
+++ vm.c	(revision 61610)
@@ -953,7 +953,7 @@ rb_binding_add_dynavars(VALUE bindval, r https://github.com/ruby/ruby/blob/trunk/vm.c#L953
     MEMCPY(dyns + 1, dynvars, ID, dyncount);
     rb_node_init(&tmp_node, NODE_SCOPE, (VALUE)dyns, 0, 0);
     ast.root = &tmp_node;
-    ast.reserved = 0;
+    ast.compile_option = 0;
 
     if (base_iseq) {
 	iseq = rb_iseq_new(&ast, base_iseq->body->location.label, path, realpath, base_iseq, ISEQ_TYPE_EVAL);
Index: compile.c
===================================================================
--- compile.c	(revision 61609)
+++ compile.c	(revision 61610)
@@ -1227,7 +1227,7 @@ new_child_iseq(rb_iseq_t *iseq, const NO https://github.com/ruby/ruby/blob/trunk/compile.c#L1227
     rb_ast_body_t ast;
 
     ast.root = node;
-    ast.reserved = 0;
+    ast.compile_option = 0;
 
     debugs("[new_child_iseq]> ---------------------------------------\n");
     ret_iseq = rb_iseq_new_with_opt(&ast, name,
@@ -7098,26 +7098,6 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L7098
 
 	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:{
 	/* compile same as lambda{...} */
 	const rb_iseq_t *block = NEW_CHILD_ISEQ(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, line);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]