aboutsummaryrefslogtreecommitdiffstats
path: root/node.c
Commit message (Collapse)AuthorAgeFilesLines
* Make `rb_ast_dispose` use `RB_OBJ_WRITE`mame2017-11-101-5/+5
| | | | | | | | | 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
* node.c (dump_node): add an explanation of NODE_HASH's nd_alenmame2017-11-091-0/+7
| | | | | | | | 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
* Introduce `rb_code_location_t`mame2017-11-041-2/+3
| | | | | | | | `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
* Avoid usage of the magic number `(NODE*)-1`mame2017-11-041-6/+6
| | | | | | | | | | | | | 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
* Remove NODE-related pieces of code from GCmame2017-11-041-163/+7
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c: Add some commentsyui-knk2017-11-031-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c: Fix possible alignment bugsyui-knk2017-11-031-2/+2
| | | | | | | | | * node.c (rb_node_buffer_new): Use offsetof for node_buffer_t size calculation. * node.c (rb_ast_newnode): Use offsetof for node_buffer_elem_t size calculation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Use NODE_CASE2 if case expressions don't existyui-knk2017-10-311-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Store lineno on RNodeyui-knk2017-10-301-1/+1
| | | | | | | | | | | | | | | * 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
* * node.h (ast_t): renamed to `rb_ast_t`.ko12017-10-291-9/+9
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c: removed duplicate node_buffer_t definitionnobu2017-10-271-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Revert "Revert "Manage AST NODEs out of GC""mame2017-10-271-0/+104
| | | | | | | This re-introduces r60485. This reverts commit 5a176b75b1187cbd3861c387bde65ff66396a07c. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Revert "Manage AST NODEs out of GC"mame2017-10-271-104/+0
| | | | | | This reverts commit 620ba74778bfdbdc34ffbb142d49ce84a0ef58e9. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Manage AST NODEs out of GCmame2017-10-271-0/+104
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Removed NODE_OPT_Nnobu2017-10-241-6/+0
| | | | | | | | | * 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
* Remove dynamic NODE allocation out of parsermame2017-10-241-0/+12
| | | | | | | | 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
* Remove special handling for (NODE*)1mame2017-10-241-6/+1
| | | | | | | | 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
* remove NODE_DREGX_ONCEnobu2017-10-221-6/+0
| | | | | | | * 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
* Remove not used node_type NODE_BMETHODyui-knk2017-10-221-1/+0
| | | | | | | | | * 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
* Remove not used node_type NODE_BLOCK_ARGyui-knk2017-10-221-2/+0
| | | | | | | | | * 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
* Remove not used node_type NODE_TO_ARYyui-knk2017-10-221-2/+0
| | | | | | | | | * 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
* Remove not used node_type NODE_CVDECLyui-knk2017-10-211-1/+0
| | | | | | | | | | * 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
* Remove not used node_type NODE_IASGN2yui-knk2017-10-211-2/+0
| | | | | | | | | | | * 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
* Replace NODE_ALLOCA with T_IMEMO (imemo_alloc)mame2017-10-211-12/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Store token first column number on RNodeyui-knk2017-10-201-1/+1
| | | | | | | | | | | | | | | | | * 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: all node typesnobu2017-10-171-82/+92
| | | | | | | * 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
* node.c: adjust indentnobu2017-10-171-11/+11
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Improve some annotation names of output of parsetree-with-commentmame2017-10-171-9/+12
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c: Add NODE_OP_CDECL to dump node list.yui-knk2017-10-171-0/+16
| | | | | | * node.c (dump_node): Add NODE_OP_CDECL to dump node list. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Introduce NODE_UNLESS for branch coveragemame2017-09-141-0/+10
| | | | | | | `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
* separate hash literal and keyword argumentsnobu2017-08-111-3/+10
| | | | | | | | | * compile.c (compile_array_keyword_arg): separate keyword splat inside hash literal from argument list. * parse.y (rparen): flag hash literal. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: should not warn op method callnobu2017-06-231-0/+1
| | | | | | | * 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
* no mark of u3 in NODE_BLOCK_PASSnobu2017-04-091-1/+1
| | | | | | | * 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
* fix nd_ainfo->kw_rest_argnobu2017-02-271-1/+1
| | | | | | | [Fix GH-5129] Author: fate0 <fate0@users.noreply.github.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c: fix NODE_OP_ASGN1nobu2017-02-261-3/+9
| | | | | | | | | * node.c (dump_node): fix a typo, index and rvalue. fix NODE_OP_ASGN1 operator to nd_mid. [Fix GH-1528] Author: fate0 <fate0@users.noreply.github.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* remove warning about enum and int comparison.ko12017-02-081-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c: compress logop sequencenobu2017-02-081-2/+9
| | | | | | | * node.c (dump_node): compress sequence of same logical binary operators, NODE_AND/NODE_OR. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c: Fix a typoyui-knk2017-02-051-1/+1
| | | | | | * node.c (dump_node): Fix a typo of || operator example git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57540 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c: flatten NODE_BLOCK [ci skip]nobu2016-10-051-4/+19
| | | | | | * node.c (dump_node): flatten statements in NODE_BLOCK. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * node.c (dump_array): remove duplicate header of NODE_ARRAY/ktsj2016-09-251-1/+0
| | | | | | NODE_VALUES. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c: nd_alen only in the headnobu2016-08-151-5/+21
| | | | | | | * 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: mark u3 of NODE_MATCH2nobu2016-03-211-1/+1
| | | | | | | * 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
* optimize named capture assignmentnobu2016-03-141-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * compile.c (compile_named_capture_assign): optimize named capture assignments, by replacing repeating global variable accesses with `dup`, and by returning the matched result instead of re-getting it from the MatchData. * parse.y (reg_named_capture_assign_gen): build just assignment nodes for the optimization. ex. `/(?<x>.)/ =~ "bar"` - old ``` 0000 putstring "bar" 0002 opt_regexpmatch1 /(?<x>.)/ 0004 pop 0005 getglobal $~ 0007 branchunless 25 0009 getglobal $~ 0011 putobject :x 0013 opt_aref <callinfo!mid:[], argc:1, ARGS_SIMPLE> 0016 setlocal_OP__WC__0 2 0018 getglobal $~ 0020 putobject_OP_INT2FIX_O_0_C_ 0021 opt_send_without_block <callinfo!mid:begin, argc:1, ARGS_SIMPLE> 0024 leave 0025 putobject nil 0027 setlocal_OP__WC__0 2 0029 putobject nil 0031 leave ``` - new ``` 0000 putstring "bar" 0002 opt_regexpmatch1 /(?<x>.)/ 0004 getglobal $~ 0006 dup 0007 branchunless 14 0009 putobject :x 0011 opt_aref <callinfo!mid:[], argc:1, ARGS_SIMPLE> 0014 setlocal_OP__WC__0 2 0016 leave ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54100 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c: no nd_compile_option unless setnobu2016-03-101-3/+6
| | | | | | * 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: stringize before expansionnobu2016-03-101-4/+4
| | | | | | | * 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: hidden options hashnobu2016-03-101-4/+45
| | | | | | | * 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
* node.c: NODE_QCALLnobu2015-12-051-0/+10
| | | | | | | * node.c (dump_node): dump NODE_QCALL. [Feature #11537] http://twitter.com/watson1978/status/673042429931446272 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Safe navigation operatornobu2015-10-221-1/+4
| | | | | | | | | | | | | * 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: update commentnobu2015-10-121-6/+2
| | | | | | | * node.c (dump_node): update comment for OP_ASGN2 and fix unused field. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.c: no attrset ID in NODEnobu2015-10-121-2/+4
| | | | | | * 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