Граф коммитов

190 Коммитов

Автор SHA1 Сообщение Дата
nobu b4b3de3e7c node.c: predicates for special NODEs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-20 13:30:57 +00:00
mame 4b6f3bce25 node.c: Stop double meaning of NODE_FOR by introducing NODE_FOR_MASGN
NODE_FOR was used both for "for"-statement itself and for
multi-assignment of for-statement (for x, y, in...end).
This change separates the two purposes, NODE_FOR for the former, and
newly introduced NODE_FOR_MASGN for the latter.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-16 07:24:53 +00:00
mame 15352965c2 parse.y: Remove almost all *_gen macros by passing parser_params explicitly
In parse.y many functions were suffixed "_gen" and had companion macros
to pass struct parser_params implicitly, which made parse.c bigger and
more obscure.

This change expands and removes almost all "*_gen" macros.  This
requires explicit passing of struct parser_params, i.e., we need to
write "foo(p, ..)" instead of "foo(..)".  However, it is just extra
three letters.  I believe that this is easier to understand.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-14 13:51:44 +00:00
mame 4928900814 Rename code_range to code_location
Because the name "code_range" is ambiguous with encoding's.
Abbreviations ("crange", and "cr") are also renamed to "loc".

The traditional "code_location" (a pair of lineno and column) is
renamed to "code_position".  Abbreviations are also renamed
(first_loc to beg_pos, and last_loc to end_pos).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 08:45:35 +00:00
mame 52057336b7 parse.y: Make consistent with the terms about code ranges and locations
"loc" was ambiguous; it might refer both a location and a code range.
This change uses "loc" for a location, and "crange" or "cr" for a code
range.

A location (abbr. loc) is a point in a program and consists of line
number and column number.  A code range (abbr. crange and cr) is a range
within a program and consists of a pair of locations which is the first
and the last.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08 12:56:58 +00:00
mame 47cf2fd7ec parse.y: Factor out code fragments that merges two code ranges
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08 12:30:35 +00:00
mame ec01271cae parse.y: Remove dispose_string
I think that recycling the delimiter string objects doesn't pay its
complexity.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08 09:39:01 +00:00
mame 413d862f23 parse.y: make all NEW_NODE macros receive location
This looks a big change, but just for refactoring.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08 01:29:35 +00:00
mame c515395561 node_h (NEW_DEFN): remove unused argument
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05 15:16:42 +00:00
mame 38c62063c0 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
2018-01-05 08:59:23 +00:00
mame 503b858cef node.h: define rb_ast_body_t and restructure rb_ast_t
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05 08:59:20 +00:00
mame a6794c4b01 node.c: constify NODE* arguments in node.c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05 07:47:51 +00:00
mame 0947c2ba63 node.h: add NODE_ONCE instead of reuse of NODE_SCOPE
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-04 12:47:22 +00:00
mame 4abc1a24af node.h: add nd_last_loc and nd_set_last_loc
Just refactoring.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-14 08:22:22 +00:00
mame ad12b5c285 node.[ch], parse.y, compile.c: rename nd_column to nd_first_column
nd_set_column -> nd_first_set_column
nd_lineno -> nd_first_lineno
nd_set_lineno -> nd_first_set_lineno

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-14 06:02:26 +00:00
yui-knk 6240f58353 node.h: Remove not used macros
* node.h (nd_modl, nd_clss_, nd_tval, nd_visi_): Remove
  not used macros.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60902 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-24 13:08:21 +00:00
mame ec3a906bb6 Refactoring out the direct accesses of NODE's u1, u2, and u3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16 11:03:37 +00:00
yui-knk 1ef7b0cd5a Store last location of a node on RNode
* node.c (rb_node_init): Initialize last location with 0.

* node.h (struct rb_code_range_struct): Define a structure
  which contains first location and last location of a node.
* node.h (struct RNode): Use rb_code_range_t to store last
  location of a node.
* node.h (nd_column, nd_set_column, nd_lineno, nd_set_lineno):
  Follow-up the change of struct RNode.
* node.h (nd_last_column, nd_set_last_column, nd_last_lineno, nd_set_last_lineno):
  Define getter/setter macros for last location of RNode.

* parse.y : Set last location of tokens.

Thanks to Yusuke Endoh (mame) for design of data structures.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-13 00:14:33 +00:00
yui-knk a6f372d129 Omit first argument of NEW_CASE2
* node.h (NEW_CASE2): Omit first argument of NEW_CASE2,
  bacause the first argument of NEW_CASE2 is always 0.
* parse.y: Ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-08 00:03:02 +00:00
mame cb7d9fe95f Revert "Introduce rb_code_range_t and replace YYLTYPE with it"
r60655 changed the usage of bison by defining a customized YYLTYPE,
which seemed to cause a random stall at rb_thread_terminate_all.

Kazuki Tsujimoto investigated the issue and pointed out the commit that
caused it.  Thanks!

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-05 03:52:22 +00:00
mame a9fd7d9396 Introduce rb_code_range_t and replace YYLTYPE with it
rb_code_range_t has two t_code_location_t, i.e., the first and last
locations.

This is used for YYLTYPE, tracked locations of bison, and will be also
used for representing the "range", the first and the last locations of
each NODE.  Currently, each NODE keeps only the first location, though.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-04 16:34:00 +00:00
mame 0ee24acb5a Introduce `rb_code_location_t`
`rb_code_location_t` has two integers, lineno and column, which point to
one location on a code.  Now `rb_code_location_t` is used instead of
`VALUE nd_location`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-04 15:22:18 +00:00
mame af9b0da125 Avoid usage of the magic number `(NODE*)-1`
This magic number has two meanings depending upon the context:

* "required keyword argument (no name)" on NODE_LASGN (`def foo(x:)`)
* "rest argument (no name)" on NODE_MASGN and NODE_POSTARG
  ('a, b, * = ary` or `a, b, *, z = ary`)

To show this intention explicitly, two macros are introduced:
NODE_SPECIAL_REQUIRED_KEYWORD and NODE_SPECIAL_NO_NAME_REST.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-04 14:24:16 +00:00
mame b6e80c2260 Remove RNODE cast from NODE utility functions
Now, casting NODE to VALUE is not recommended.  This change requires an
explicit cast from VALUE to NODE to use the NODE utility functions such
as `nd_type`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-04 11:37:19 +00:00
mame deb5693149 Remove NODE-related pieces of code from GC
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-04 10:02:43 +00:00
yui-knk 77fae4b4c0 node.h: Remove obsolete comment
* node.h: NODE_FL_CREF_PUSHED_BY_EVAL was defined as
  NODE_FL_NEWLINE by r25984, redefined by r40703
  and removed by r49897.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-03 02:17:07 +00:00
yui-knk 5f77f1e30d node.h: Rename nd_reserved to nd_location
* node.h (RNode): Now nd_reserved is used to store location
  information, so rename nd_reserved to nd_location.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-31 13:29:54 +00:00
yui-knk a09e175068 Use NODE_CASE2 if case expressions don't exist
When NODE_WHEN is compiled by iseq_compile_each0,
the node passed to compile_when is NODE_WHEN (not NODE_CASE).
So we can not handle the location of NODE_CASE of
case statements which don't have case expressions.

e.g. :

```
case; when 1; foo; when 2; bar; else baz; end
```

This commit adds NODE_CASE2, and compiles it by
iseq_compile_each0.

* compile.c (compile_case): Does not call COMPILE_ when
  NODE_CASE does not have case expressions.
* compile.c (compile_case2): Compile NODE_CASE2 by compile_case2.
* compile.c (compile_when): Delete an obsoleted function.
* compile.c (iseq_compile_each0): Compile NODE_CASE2.

* ext/objspace/objspace.c (count_nodes): Add NODE_CASE2 case.

* node.c (dump_node, rb_gc_mark_node): Add NODE_CASE2 case.

* node.h (node_type): Add NODE_CASE2.
* node.h (NEW_CASE2): Add a macro which generates NODE_CASE2.

* parse.y: Generate NODE_CASE2 if case expressions don't exist.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-31 00:46:30 +00:00
yui-knk 7a42b03b0c Store lineno on RNode
* node.c (A_NODE_HEADER): Print lineno.

* node.h (nd_column, nd_set_column): Store column
  number with 16-bit.
* node.h (nd_lineno, nd_set_lineno): Define
  getter/setter macros for lineno of RNode.

* parse.y : Set first lineno of tokens.

Thanks to takeshinoda for review.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-30 13:36:20 +00:00
ko1 85fcaf025d * node.h (ast_t): renamed to `rb_ast_t`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29 15:51:23 +00:00
mame e35fe8d11b Revert "Revert "Manage AST NODEs out of GC""
This re-introduces r60485.
This reverts commit 5a176b75b1.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 16:44:57 +00:00
mame 5a176b75b1 Revert "Manage AST NODEs out of GC"
This reverts commit 620ba74778.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 16:02:34 +00:00
mame 620ba74778 Manage AST NODEs out of GC
NODEs in AST are no longer objects managed by GC.  This change will
remove the restriction imposed by the GC.  For example, a NODE can use
more than five words (this is my primary purpose; we want to store the
position data for each NODE, for coverage library), or even a NODE can
have variable length (some kinds of NODEs have unused fields).
To do this, however, we need more work, since Ripper still uses T_NODE
objects managed by the GC.

The life time of NODEs is more obvious than other kinds of objects; they
are created at parsing, and they become disused immediately after
compilation.  This change releases all NODEs by a few `xfree`s after
compilation, so performance will be improved a bit.  In extreme example,
`eval("x=1;" * 10000000)` runs much faster (40 sec. -> 7.8 sec. on my
machine).

The most important part of this change is `ast_t` struct, which has
three contents: (1) NODE buffer (malloc'ed memory), (2) a reference to
the root NODE, and (3) an array that contains objects that must be
marked during parsing (such as literal objects).  Some functions that
had received `NODE*` arguments, must now receive `ast_t*`.

* node.c, node.h: defines `ast_t` struct and related operations.
* gc.c, internal.h: defines `imemo_ast`.
* parse.y: makes `parser_params` struct have a reference to `ast_t`.
  Instead of `rb_node_newnode`, use `rb_ast_newnode` to create a NODE.
* iseq.c, load.c, ruby.c, template/prelude.c.tmpl: modifies some
  functions to handle `ast_t*` instead of `NODE*`.
* test/ruby/test_gc.rb: ad-hoc fix for a failed test.  The test assumes
  GC eden is increased at startup by NODE object creation.  However,
  this change now create no NODE object, so GC eden is not necessarily
  increased.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 15:59:02 +00:00
nobu 2c786bf35d Removed NODE_OPT_N
* node.h (NODE_OPT_N): removed.

* parse.y (parser_append_options): expand -n option loop to while
  gets loop.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24 08:00:36 +00:00
nobu 30f5c55890 parse.y: rb_parser_set_options
* parse.y (yycompile0): append top-level addenda before appending
  prelude nodes.

* parse.y (rb_parser_set_options): set top-level addendum options
  before parsing.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24 07:41:48 +00:00
mame ac3bad418c Remove dynamic NODE allocation out of parser
A temporary NODE object was allocated to create iseq.  Instead, this
patch allocates a dummy NODE as auto variable, and discard it soon.
This change is intended as a preparation to manage AST NODEs out of GC.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24 06:16:31 +00:00
nobu 1528a9859c remove NODE_DREGX_ONCE
* node.h (enum node_type): remove NODE_DREGX_ONCE which is not
  used anymore.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 05:13:57 +00:00
yui-knk 25a7dfc6d7 Remove not used node_type NODE_BMETHOD
* ext/objspace/objspace.c (count_nodes): This node_type has
  not been used since r24128.
* node.c (dump_node): ditto
* node.h (node_type, NEW_BMETHOD): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 00:45:05 +00:00
yui-knk fdc5864090 Remove not used node_type NODE_BLOCK_ARG
* ext/objspace/objspace.c (count_nodes): This node_type has
  not been used since r11840.
* node.c (dump_node, rb_gc_mark_node): ditto
* node.h (node_type, NEW_BLOCK_ARG): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 00:29:40 +00:00
yui-knk f36ee4406e Remove not used node_type NODE_TO_ARY
* ext/objspace/objspace.c (count_nodes): This node_type has
  not been used since r13236.
* node.c (dump_node, rb_gc_mark_node): ditto
* node.h (node_type, NEW_TO_ARY): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 00:17:39 +00:00
yui-knk d98db55b73 Remove not used node_type NODE_CVDECL
* compile.c (defined_expr0): This node_type has
  not been used since r11614.
* ext/objspace/objspace.c (count_nodes): ditto
* node.c (dump_node): ditto
* node.h (node_type, NEW_CVDECL): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 16:09:51 +00:00
yui-knk 92746378ab Remove not used node_type NODE_IASGN2
* compile.c (compile_massign_opt, iseq_compile_each0): This
  node_type has not been used since r11813.
* ext/objspace/objspace.c (count_nodes): ditto
* node.c (dump_node, rb_gc_mark_node): ditto
* node.h (node_type, NEW_IASGN2): ditto
* parse.y (node_assign_gen): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 15:56:03 +00:00
yui-knk 7f7d5d0c90 node.h: Remove a not used function prototype
* node.h (rb_node_newnode_longlife): The definition
  of this function was deleted r24490.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60265 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 13:06:36 +00:00
mame ccfe37884a Replace NODE_ALLOCA with T_IMEMO (imemo_alloc)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 08:40:28 +00:00
yui-knk 6d4b557811 Store token first column number on RNode
* node.c (A_NODE_HEADER): Print column number.
* node.h (nd_column, nd_set_column): Define getter/setter
  macros for column number of RNode.
* parse.y: Set first column number of tokens.

Notes:

* Use `@n` to get the location of token in parse.y.
* When we use `@n`, arguments of yyerror and yylex are
  changed.
* Initialize column of nodes with -1 to make it easy
  to detect nodes which we forget to set a column number.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-20 16:22:22 +00:00
yui-knk affa40b9ea node.h: Remove a not used macro
* node.h (nd_refinements_): nd_refinements_ was
  introduced on r49894. But this macro has not been
  used since r49897.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-17 07:19:20 +00:00
mame 3c8c17d30d Introduce NODE_UNLESS for branch coverage
`unless` statement was a syntactic sugar for `if` statement,
which made the result of branch coverage hard to understand.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 05:27:02 +00:00
nobu af4ba5c12a parse.y: should not warn op method call
* parse.y (void_expr_gen): should warn operator expression style
  calls only, but not method style calls.  [Fix GH-1660]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23 11:56:48 +00:00
nobu c6c55bb784 node.h: sign-extend
* node.h (nd_line): should sign-extend.  shifting `VALUE` extends
  with zero bits if `sizeof(VALUE)` equals to `sizeof(int)`.  the
  zero bits are truncated if `sizeof(VALUE)` is bigger enough.
  [ruby-core:80920] [Bug #13523]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-29 02:58:53 +00:00
hsbt 6851be0f0c * compile.c: fix typos.
[ci skip][fix GH-1140] Patch by @jutaz
* dir.c: ditto.
* gc.c: ditto.
* io.c: ditto.
* node.h: ditto.
* thread_pthread.c: ditto.
* vm_insnhelper.c: ditto.
* vsnprintf.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53103 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-14 02:51:13 +00:00