* node.c (rb_ast_dispose): since `ast->node_buffer` is freed in
`rb_ast_free()`, it should be always NULL.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
I want to add a new field to rb_ast_t whose size is restricted because
it is an imemo. This change makes one room in rb_ast_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This is NG. The ISO C section 6.7.2.1 explicitly states that
structs having flexible array members "shall not be a member
of a structure or an element of an array."
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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
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
"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
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
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
* node.c (COMPOUND_FIELD, FIELD_BLOCK): moved block outside
arguments like as SIMPLE_FIELD.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This affects only `--dump=parsetree` and `--dump=parsetree_with_comment`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* 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
This fixes the mistake of r60722.
I used `rb_gc_writebarrier_remember` to notify to GC that the references
is changed. But the function just adds the object to the remember set
blindly. Ko1 told me that `RB_OBJ_WRITE` is suitable in this case.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60737 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
The field has a flag to represent if it is a keyword argument (that has
no braces, e.g., `foo(k:1)`) or hash literal (that has braces, e.g.,
`foo({k:1})`).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
`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
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
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
* 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
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
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
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
The magic number was used to mark NODE_ATTRASGN when its receiver is
self. But the hack was refactored at r46366. So the remaining code
fragments are no longer needed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* 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
* 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
* 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
* 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
* 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
* 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
* node.c (dump_node): moved rb_bug for unknown node outside to let
unhandled node types be warned.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60202 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
`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
* node.c (rb_gc_mark_node): u3 in NODE_BLOCK_PASS is not used and
does not need to be marked.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c (dump_array): show nd_alen field in NODE_ARRAY only in
the first node. it is nd_end in the rest nodes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55901 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c (rb_gc_mark_node): NODE_MATCH2 can have nd_args, u3,
since r54100.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54209 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c (dump_node): show nd_compile_option only when it is set.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c (F_NODE, F_OPTION): stringize member names defined as
macros before expansion.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c (dump_option): nd_compile_option is a hidden hash object,
cannot call inspect on it.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_peephole_optimize): peephole optimization for
branchnil jumps.
* compile.c (iseq_compile_each): generate save navigation operator
code.
* insns.def (branchnil): new opcode to pop the tos and branch if
it is nil.
* parse.y (NEW_QCALL, call_op, parser_yylex): parse token '.?'.
[Feature #11537]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c (dump_node): attrset ID is no longer in NODE_OP_ASGN2.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c (dump_node): fix comments of dynamic string literals,
nd_next->nd_head is the interpolation but not a literal string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c (A_FIELD_HEADER): reduce text size by sharing messages
with and without comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each): override compile option by option
given by pragma.
* iseq.c (rb_iseq_make_compile_option): extract a function to
overwrite rb_compile_option_t.
* parse.y (parser_set_compile_option_flag): introduce pragma to
override compile options.
* parse.y (magic_comments): new pragma "fronzen-string-literal".
[Feature #8976]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c (rb_alloc_tmp_buffer): round up the size and check the
range.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c (rb_alloc_tmp_buffer): use NODE_ALLOCA to mark locations
like as builtin alloca. [ruby-core:70251] [Bug #11418]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e