ruby-changes:48520
From: mame <ko1@a...>
Date: Sat, 4 Nov 2017 13:59:24 +0900 (JST)
Subject: [ruby-changes:48520] mame:r60635 (trunk): Revert "Replace NODE_STRTERM and NODE_HEREDOC with imemo_strterm"
mame 2017-11-04 13:59:19 +0900 (Sat, 04 Nov 2017) New Revision: 60635 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60635 Log: Revert "Replace NODE_STRTERM and NODE_HEREDOC with imemo_strterm" Due to build failure on mswin and mingw. Modified files: trunk/gc.c trunk/internal.h trunk/parse.y Index: gc.c =================================================================== --- gc.c (revision 60634) +++ gc.c (revision 60635) @@ -4546,9 +4546,6 @@ gc_mark_imemo(rb_objspace_t *objspace, V https://github.com/ruby/ruby/blob/trunk/gc.c#L4546 case imemo_ast: rb_ast_mark(&RANY(obj)->as.imemo.ast); return; - case imemo_strterm: - rb_strterm_mark(obj); - return; #if VM_CHECK_MODE > 0 default: VM_UNREACHABLE(gc_mark_imemo); Index: parse.y =================================================================== --- parse.y (revision 60634) +++ parse.y (revision 60635) @@ -178,8 +178,6 @@ typedef struct token_info { https://github.com/ruby/ruby/blob/trunk/parse.y#L178 struct token_info *next; } token_info; -typedef struct rb_strterm_struct rb_strterm_t; - /* Structure of Lexer Buffer: @@ -195,7 +193,7 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L193 YYSTYPE *lval; struct { - rb_strterm_t *strterm; + NODE *strterm; VALUE (*gets)(struct parser_params*,VALUE); VALUE input; VALUE lastline; @@ -740,41 +738,17 @@ static int lvar_defined_gen(struct parse https://github.com/ruby/ruby/blob/trunk/parse.y#L738 #define RE_OPTION_MASK 0xff #define RE_OPTION_ARG_ENCODING_NONE 32 -/* structs for managing terminator of string literal and heredocment */ -typedef struct rb_strterm_literal_struct { - long nest; - long func; /* STR_FUNC_* (e.g., STR_FUNC_ESCAPE and STR_FUNC_EXPAND) */ - long paren; /* '(' of `%q(...)` */ - long term; /* ')' of `%q(...)` */ -} rb_strterm_literal_t; - -typedef struct rb_strterm_heredoc_struct { - VALUE sourceline; - VALUE term; /* `"END"` of `<<"END"` */ - long lastidx; /* the column of `<<"END"` */ - VALUE lastline; /* the string of line that contains `<<"END"` */ -} rb_strterm_heredoc_t; - -#define STRTERM_HEREDOC IMEMO_FL_USER0 - -typedef struct rb_strterm_struct { - VALUE flags; - union { - rb_strterm_literal_t literal; - rb_strterm_heredoc_t heredoc; - } u; -} rb_strterm_t; - -void -rb_strterm_mark(VALUE obj) -{ - rb_strterm_t *strterm = (rb_strterm_t*)obj; - if (RBASIC(obj)->flags & STRTERM_HEREDOC) { - rb_strterm_heredoc_t *heredoc = &strterm->u.heredoc; - rb_gc_mark(heredoc->term); - rb_gc_mark(heredoc->lastline); - } -} +#define NODE_STRTERM NODE_ZARRAY /* nothing to gc */ +#define NODE_HEREDOC NODE_ARRAY /* 1, 3 to gc */ +#define SIGN_EXTEND(x,n) (((1<<(n)-1)^((x)&~(~0<<(n))))-(1<<(n)-1)) +#define nd_func u1.id +#if SIZEOF_SHORT == 2 +#define nd_term(node) ((signed short)(node)->u2.id) +#else +#define nd_term(node) SIGN_EXTEND((node)->u2.id, CHAR_BIT*2) +#endif +#define nd_paren(node) (char)((node)->u2.id >> CHAR_BIT*2) +#define nd_nest u3.cnt #define TOKEN2ID(tok) ( \ tTOKEN_LOCAL_BEGIN<(tok)&&(tok)<tTOKEN_LOCAL_END ? TOKEN2LOCALID(tok) : \ @@ -973,7 +947,6 @@ static void token_info_pop_gen(struct pa https://github.com/ruby/ruby/blob/trunk/parse.y#L947 ID id; int num; const struct vtable *vars; - struct rb_strterm_struct *strterm; } %token <id> @@ -4241,14 +4214,13 @@ string_content : tSTRING_CONTENT https://github.com/ruby/ruby/blob/trunk/parse.y#L4214 } | tSTRING_DVAR { - /* need to backup lex_stream so that a string literal `%&foo,#$&,bar&` can be parsed */ - $<strterm>$ = lex_strterm; + $<node>$ = lex_strterm; lex_strterm = 0; SET_LEX_STATE(EXPR_BEG); } string_dvar { - lex_strterm = $<strterm>2; + lex_strterm = $<node>2; /*%%%*/ $$ = NEW_EVSTR($3); nd_set_lineno($$, @1.first_line); @@ -4265,8 +4237,7 @@ string_content : tSTRING_CONTENT https://github.com/ruby/ruby/blob/trunk/parse.y#L4237 CMDARG_SET(0); } { - /* need to backup lex_stream so that a string literal `%!foo,#{ !0 },bar!` can be parsed */ - $<strterm>$ = lex_strterm; + $<node>$ = lex_strterm; lex_strterm = 0; } { @@ -4285,7 +4256,7 @@ string_content : tSTRING_CONTENT https://github.com/ruby/ruby/blob/trunk/parse.y#L4256 { COND_SET($<val>1); CMDARG_SET($<val>2); - lex_strterm = $<strterm>3; + lex_strterm = $<node>3; SET_LEX_STATE($<num>4); brace_nest = $<num>5; heredoc_indent = $<num>6; @@ -5164,8 +5135,8 @@ none : /* none */ https://github.com/ruby/ruby/blob/trunk/parse.y#L5135 static int parser_regx_options(struct parser_params*); static int parser_tokadd_string(struct parser_params*,int,int,int,long*,rb_encoding**); static void parser_tokaddmbc(struct parser_params *parser, int c, rb_encoding *enc); -static enum yytokentype parser_parse_string(struct parser_params*,rb_strterm_literal_t*); -static enum yytokentype parser_here_document(struct parser_params*,rb_strterm_heredoc_t*); +static enum yytokentype parser_parse_string(struct parser_params*,NODE*); +static enum yytokentype parser_here_document(struct parser_params*,NODE*); # define nextc() parser_nextc(parser) @@ -6495,9 +6466,8 @@ parser_tokadd_string(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L6466 return c; } -/* imemo_strterm for literal */ #define NEW_STRTERM(func, term, paren) \ - (rb_strterm_t*)rb_imemo_new(imemo_strterm, (VALUE)(func), (VALUE)(paren), (VALUE)(term), 0) + rb_node_newnode(NODE_STRTERM, (func), (term) | ((paren) << (CHAR_BIT * 2)), 0) #ifdef RIPPER static void @@ -6596,6 +6566,7 @@ parser_peek_variable_name(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6566 static inline enum yytokentype parser_string_term(struct parser_params *parser, int func) { + rb_discard_node(lex_strterm); lex_strterm = 0; if (func & STR_FUNC_REGEXP) { set_yylval_num(regx_options()); @@ -6613,11 +6584,11 @@ parser_string_term(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L6584 } static enum yytokentype -parser_parse_string(struct parser_params *parser, rb_strterm_literal_t *quote) +parser_parse_string(struct parser_params *parser, NODE *quote) { - int func = (int)quote->func; - int term = (int)quote->term; - int paren = (int)quote->paren; + int func = (int)quote->nd_func; + int term = nd_term(quote); + int paren = nd_paren(quote); int c, space = 0; rb_encoding *enc = current_enc; VALUE lit; @@ -6632,9 +6603,9 @@ parser_parse_string(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L6603 do {c = nextc();} while (ISSPACE(c)); space = 1; } - if (c == term && !quote->nest) { + if (c == term && !quote->nd_nest) { if (func & STR_FUNC_QWORDS) { - quote->func |= STR_FUNC_TERM; + quote->nd_func |= STR_FUNC_TERM; return ' '; } return parser_string_term(parser, func); @@ -6651,7 +6622,7 @@ parser_parse_string(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L6622 c = nextc(); } pushback(c); - if (tokadd_string(func, term, paren, "e->nest, + if (tokadd_string(func, term, paren, "e->nd_nest, &enc) == -1) { if (parser->eofp) { #ifndef RIPPER @@ -6666,7 +6637,7 @@ parser_parse_string(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L6637 else { unterminated_literal("unterminated string meets end of file"); } - quote->func |= STR_FUNC_TERM; + quote->nd_func |= STR_FUNC_TERM; } } @@ -6686,6 +6657,7 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6657 long len; int newline = 0; int indent = 0; + VALUE lit; if (c == '-') { c = nextc(); @@ -6750,14 +6722,13 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6722 dispatch_scan_event(tHEREDOC_BEG); len = lex_p - lex_pbeg; lex_goto_eol(parser); - - lex_strterm = (rb_strterm_t*)rb_imemo_new(imemo_strterm, - STR_NEW(tok(), toklen()), /* term */ - len, /* lastidx */ - lex_lastline, /* lastline */ - ruby_sourceline); - lex_strterm->flags |= STRTERM_HEREDOC; - + add_mark_object(lit = STR_NEW(tok(), toklen())); + add_mark_object(lex_lastline); + lex_strterm = rb_node_newnode(NODE_HEREDOC, + lit, /* nd_lit */ + len, /* nd_nth */ + lex_lastline); /* nd_orig */ + parser_set_line(lex_strterm, ruby_sourceline); token_flush(parser); heredoc_indent = indent; heredoc_line_indent = 0; @@ -6765,18 +6736,20 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6736 } static void -parser_heredoc_restore(struct parser_params *parser, rb_strterm_heredoc_t *here) +parser_heredoc_restore(struct parser_params *parser, NODE *here) { VALUE line; lex_strterm = 0; - line = here->lastline; + line = here->nd_orig; lex_lastline = line; lex_pbeg = RSTRING_PTR(line); lex_pend = lex_pbeg + RSTRING_LEN(line); - lex_p = lex_pbeg + here->lastidx; + lex_p = lex_pbeg + here->nd_nth; heredoc_end = ruby_sourceline; - ruby_sourceline = here->sourceline; + ruby_sourceline = nd_line(here); + dispose_string(parser, here->nd_lit); + rb_discard_node(here); token_flush(parser); } @@ -6972,7 +6945,7 @@ ripper_dispatch_heredoc_end(struct parse https://github.com/ruby/ruby/blob/trunk/parse.y#L6945 #endif static enum yytokentype -parser_here_document(struct parser_params *parser, rb_strterm_heredoc_t *here) +parser_here_document(struct parser_params *parser, NODE *here) { int c, func, indent = 0; const char *eos, *p, *pend; @@ -6980,8 +6953,8 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L6953 VALUE str = 0; rb_encoding *enc = current_enc; - eos = RSTRING_PTR(here->term); - len = RSTRING_LEN(here->term) - 1; + eos = RSTRING_PTR(here->nd_lit); + len = RSTRING_LEN(here->nd_lit) - 1; indent = (func = *eos++) & STR_FUNC_INDENT; if ((c = nextc()) == -1) { @@ -7012,13 +6985,13 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L6985 lex_goto_eol(parser); #endif restore: - heredoc_restore(&lex_strterm->u.heredoc); + heredoc_restore(lex_strterm); lex_strterm = 0; return 0; } if (was_bol() && whole_match_p(eos, len, indent)) { dispatch_heredoc_end(); - heredoc_restore(&lex_strterm->u.heredoc); + heredoc_restore(lex_strterm); lex_strterm = 0; SET_LEX_STATE(EXPR_END); return tSTRING_END; @@ -7112,7 +7085,7 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L7085 str = ripper_new_yylval(ripper_token2eventid(tSTRING_CONTENT), yylval.val, str); #endif - heredoc_restore(&lex_strterm->u.heredoc); + heredoc_restore(lex_strterm); lex_strterm = NEW_STRTERM(func | STR_FUNC_TERM, 0, 0); set_yylval_str(str); add_mark_object(str); @@ -8270,11 +8243,11 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8243 int token_seen = parser->token_seen; if (lex_strterm) { - if (lex_strterm->flags & STRTERM_HEREDOC) { - return here_document(&lex_strterm->u.heredoc); + if (nd_type(lex_strterm) == NODE_HEREDOC) { + return here_document(lex_strterm); } else { - return parse_string(&lex_strterm->u.literal); + return parse_string(lex_strterm); } } cmd_state = command_start; @@ -11569,12 +11542,12 @@ parser_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/parse.y#L11542 rb_gc_mark(lex_lastline); rb_gc_mark(lex_nextline); rb_gc_mark(ruby_sourcefile_string); - rb_gc_mark((VALUE)lex_strterm); #ifndef RIPPER rb_gc_mark(ruby_debug_lines); rb_gc_mark(parser->compile_option); rb_gc_mark(parser->error_buffer); #else + rb_gc_mark((VALUE)lex_strterm); rb_gc_mark(parser->delayed); rb_gc_mark(parser->value); rb_gc_mark(parser->result); Index: internal.h =================================================================== --- internal.h (revision 60634) +++ internal.h (revision 60635) @@ -845,8 +845,7 @@ enum imemo_type { https://github.com/ruby/ruby/blob/trunk/internal.h#L845 imemo_ment = 6, imemo_iseq = 7, imemo_alloc = 8, - imemo_ast = 9, - imemo_strterm = 10 + imemo_ast = 9 }; #define IMEMO_MASK 0x0f @@ -942,8 +941,6 @@ typedef struct rb_imemo_alloc_struct { https://github.com/ruby/ruby/blob/trunk/internal.h#L941 rb_imemo_alloc_t *rb_imemo_alloc_new(VALUE, VALUE, VALUE, VALUE); -void rb_strterm_mark(VALUE obj); - /*! MEMO * * @see imemo_type -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/