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

2162 Коммитов

Автор SHA1 Сообщение Дата
S.H ec7f14d9fa
Add `nd_type_p` macro 2021-12-04 00:01:24 +09:00
Nobuyoshi Nakada c14f230b26 Assign temporary ID to anonymous ID [Bug #18250]
Dumped iseq binary can not have unnamed symbols/IDs, and ID 0 is
stored instead.  As `struct rb_id_table` disallows ID 0, also for
the distinction, re-assign a new temporary ID based on the local
variable table index when loading from the binary, as well as the
parser.
2021-11-23 21:03:19 +09:00
Yusuke Endoh feda058531 Refactor hacky ID tables to struct rb_ast_id_table_t
The implementation of a local variable tables was represented as `ID*`,
but it was very hacky: the first element is not an ID but the size of
the table, and, the last element is (sometimes) a link to the next local
table only when the id tables are a linked list.

This change converts the hacky implementation to a normal struct.
2021-11-21 08:59:24 +09:00
Jeremy Evans 4adb012926 Anonymous block forwarding allows a method to forward a passed
block to another method without having to provide a name for the
block parameter.

Implements [Feature #11256]

Co-authored-by: Yusuke Endoh mame@ruby-lang.org
Co-authored-by: Nobuyoshi Nakada nobu@ruby-lang.org
2021-11-18 14:17:57 -08:00
Yusuke Endoh 415671a282 parse.y: Fix memory leak at parse error
Local variable tables might leak at the parse error.
2021-11-12 17:36:39 +09:00
Peter Zhu aeae6e2842 [Feature #18290] Remove all usages of rb_gc_force_recycle
This commit removes usages of rb_gc_force_recycle since it is a burden
to maintain and makes changes to the GC difficult.
2021-11-08 14:05:54 -05:00
Nobuyoshi Nakada 13a9597c7c Argument forwarding definition without parentheses [Bug #18267] 2021-10-31 18:27:55 +09:00
Nobuyoshi Nakada b7f7117bdc
Rename `in_kwarg` as `in_argdef` as unrelated to keywords 2021-10-31 13:55:14 +09:00
Nobuyoshi Nakada 1b59ad57ae
Reduce parser stack usage at pattern matching 2021-10-31 13:49:21 +09:00
Nobuyoshi Nakada e1ecda297e
Make new object for negated float as `Float` is always frozen now 2021-10-26 20:17:00 +09:00
Yusuke Endoh 09fa773e04
ast.c: Use kept script_lines data instead of re-opening the source file (#5019)
ast.c: Use kept script_lines data instead of re-open the source file
2021-10-26 01:58:01 +09:00
Koichi Sasada c7550537f1 `RubyVM.keep_script_lines`
`RubyVM.keep_script_lines` enables to keep script lines
for each ISeq and AST. This feature is for debugger/REPL
support.

```ruby
RubyVM.keep_script_lines = true
RubyVM::keep_script_lines = true

eval("def foo = nil\ndef bar = nil")
pp RubyVM::InstructionSequence.of(method(:foo)).script_lines
```
2021-10-21 16:17:39 +09:00
Jeremy Evans fac2c0f73c
Fix evaluation order of hash values for duplicate keys
Fixes [Bug #17719]

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Ivo Anjo <ivo@ivoanjo.me>
2021-10-18 09:09:07 -07:00
Nobuyoshi Nakada 8057129da6
Remove duplicate value checks on `mrhs` which always has the value 2021-10-08 00:11:22 +09:00
Nobuyoshi Nakada a15996c752
Split parser_yyerror0 from parser_yyerror
The former uses the current location, while the latter takes a
non-null location.
2021-10-05 16:59:35 +09:00
Nobuyoshi Nakada 1f544d6715
Show the last line at unexpected end-of-input error 2021-10-05 16:44:43 +09:00
Nobuyoshi Nakada 126122bb6c
Replace inaccurate error messages
When Bison reports "memory exhausted", it means the parser stack
depth reached the limit `YYMAXDEPTH` which is defaulted to 10_000,
but not memory allocation failed.
2021-10-05 15:00:02 +09:00
Nobuyoshi Nakada 28392d3045
The same warning for static symbol literal 2021-10-04 12:16:31 +09:00
Nobuyoshi Nakada da139317a5
Fix the warning message for dynamic symbol literal in condition 2021-10-04 12:16:31 +09:00
Nobuyoshi Nakada fa05697e48 Use `%printer` directive for Bison 3.8 2021-09-14 18:51:38 +09:00
Shugo Maeda 7686776c05
Hash values should be omitted in Ripper results 2021-09-11 22:03:10 +09:00
Shugo Maeda c60dbcd1c5
Allow value omission in Hash literals
`{x:, y:}` is a syntax sugar of `{x: x, y: y}`.
2021-09-11 18:52:25 +09:00
S-H-GAMELINKS bdd6d8746f Replace RBOOL macro 2021-09-05 23:01:27 +09:00
Nobuyoshi Nakada c38c2d8ee2 Moved exported symbols in internal/util.h to ruby/util.h
[Feature #18051]
2021-08-24 10:37:41 +09:00
Yusuke Endoh cad83fa3c4 ast.c: Rename "save_script_lines" to "keep_script_lines"
... as per ko1's preference. He is preparing to extend this feature to
ISeq for his new debugger. He prefers "keep" to "save" for this wording.
This API is internal and not included in any released version, so I
change it in advance.
2021-08-20 16:18:36 +09:00
Kazuki Tsujimoto ecb6d6a4ef
Allow omission of parentheses in one line pattern matching [Feature #16182] 2021-08-19 17:07:58 +09:00
Nobuyoshi Nakada 2aa6826e81 Extract the wrapped value when yydebug [Bug #18075] 2021-08-15 11:40:06 +09:00
eileencodes b940a45357 Fix interpolated heredoc
This fixes https://bugs.ruby-lang.org/issues/18038. The provided
reproduction showed that this happens in heredocs with double
interpolation. In this case `DSTR` was getting returned but needs to be
convered to a `EVSTR` which is what is returned by the function. There
may be an additional bug here that we weren't able to produce. It seems
odd that `STR` returns `DSTR` while everything else should return
`EVSTR` since the function is `new_evstr`.

[Bug #18038][ruby-core:104597]

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-07-21 10:06:33 -07:00
Kazuki Tsujimoto eed5e8f796
One-line pattern matching is no longer experimental
https://github.com/ruby/dev-meeting-log/blob/master/DevelopersMeeting20210715Japan.md#feature-17724-make-the-pin-operator-support-instanceclassglobal-variables-jeremyevans0
2021-07-17 11:13:52 +09:00
Jeremy Evans fa87f72e1e Add pattern matching pin support for instance/class/global variables
Pin matching for local variables and constants is already supported,
and it is fairly simple to add support for these variable types.

Note that pin matching for method calls is still not supported
without wrapping in parentheses (pin expressions).  I think that's
for the best as method calls are far more complex (arguments/blocks).

Implements [Feature #17724]
2021-07-15 09:56:02 -07:00
Yusuke Endoh fb01411ae8 node.h: Reduce struct size to fit with Ruby object size (five VALUEs)
by merging `rb_ast_body_t#line_count` and `#script_lines`.

Fortunately `line_count == RARRAY_LEN(script_lines)` was always
satisfied. When script_lines is saved, it has an array of lines, and
when not saved, it has a Fixnum that represents the old line_count.
2021-06-18 02:34:27 +09:00
Yusuke Endoh acae5f363d ast.rb: RubyVM::AST.parse and .of accepts `save_script_lines: true`
This option makes the parser keep the original source as an array of
the original code lines. This feature exploits the mechanism of
`SCRIPT_LINES__` but records only the specified code that is passed to
RubyVM::AST.of or .parse, instead of recording all parsed program texts.
2021-06-18 02:34:27 +09:00
Nobuyoshi Nakada e4f891ce8d
Adjust styles [ci skip]
* --braces-after-func-def-line
* --dont-cuddle-else
* --procnames-start-lines
* --space-after-for
* --space-after-if
* --space-after-while
2021-06-17 10:13:40 +09:00
Yusuke Endoh 70313ec01a parse.y: Fix the location of a target constant of OP_CDECL
```
p RubyVM::AbstractSyntaxTree.parse("::Foo += 1").children
 #=> before: [[], nil, (OP_CDECL@1:0-1:10 (COLON3@1:0-1:10 :Foo) :+ (LIT@1:9-1:10 1))]
 #=> after:  [[], nil, (OP_CDECL@1:0-1:10 (COLON3@1:0-1:5 :Foo) :+ (LIT@1:9-1:10 1))]
```
2021-06-14 10:02:02 +09:00
Nobuyoshi Nakada 9f3888d6a3 Warn more duplicate literal hash keys
Following non-special_const literals:
* T_REGEXP
2021-06-03 15:11:18 +09:00
Nobuyoshi Nakada 37eb5e7439 Warn more duplicate literal hash keys
Following non-special_const literals:
* T_BIGNUM
* T_FLOAT (non-flonum)
* T_RATIONAL
* T_COMPLEX
2021-06-03 15:11:18 +09:00
Nobuyoshi Nakada 50a534a152 ripper: wrap endless method in bodystmt [Bug #17869] 2021-05-21 18:28:24 +09:00
Nobuyoshi Nakada 110f242ef9
Also `\U` after control/meta is invalid [Bug #17861]
As well as `\u`, `\U` should be invalid there too.
And highlight including `u`/`U` not only the backslash before it.
2021-05-13 12:54:56 +09:00
Jeremy Evans 11ae581a4a Fix handling of control/meta escapes in literal regexps
Ruby uses a recursive algorithm for handling control/meta escapes
in strings (read_escape).  However, the equivalent code for regexps
(tokadd_escape) in did not use a recursive algorithm.  Due to this,
Handling of control/meta escapes in regexp did not have the same
behavior as in strings, leading to behavior such as the following
returning nil:

```ruby
/\c\xFF/ =~ "\c\xFF"
```

Switch the code for handling \c, \C and \M in literal regexps to
use the same code as for strings (read_escape), to keep behavior
consistent between the two.

Fixes [Bug #14367]
2021-05-12 18:55:43 -07:00
Yusuke Endoh 31794d2e73 parse.y: Allow "command" syntax in endless method definition
This change allows `def hello = puts "Hello"` without parentheses.

Note that `private def hello = puts "Hello"` does not parse for
technical reason.

[Feature #17398]
2021-05-13 00:14:50 +09:00
Yusuke Endoh d405b1a878 Make imemo_ast WB-protected again
by firing the write barrier of imemo_ast after nd_lit is modified.
This will fix the issue of https://github.com/ruby/ruby/pull/4416 more
gracefully.
2021-04-27 17:05:19 +09:00
Nobuyoshi Nakada 607aa11711
Ignore useless separators preceding a file encoding comment 2021-03-23 17:20:19 +09:00
Kazuki Tsujimoto 21863470d9
Pattern matching pin operator against expression [Feature #17411]
This commit is based on the patch by @nobu.
2021-03-21 15:14:31 +09:00
Takashi Tamura 990b54054d Add a missing semicolon. 2021-02-15 10:46:29 +09:00
Nobuyoshi Nakada b091889ed6 Removed YYUSE [Bug #17582]
Although it was used just to suppress an "unsed argument" warning
in the same manner as other bison-provided functions, it has been
dropped since Bision 3.7.5.  And we always suppress that
warnings.
2021-01-26 21:57:09 +09:00
Nobuyoshi Nakada 6bcc4664bd
Return new NODE_LIT
As NODE_ZLIST/NODE_LIST are not markable, cannot be reused as
NODE_LIT.
2021-01-14 16:15:25 +09:00
Nobuyoshi Nakada bb40c5cbe9
Ensure symbol list node is either NODE_STR or NODE_DSTR 2021-01-14 16:13:26 +09:00
Nobuyoshi Nakada 0036648a42
Capture to reserved name variables if already defined [Bug #17533] 2021-01-13 21:16:00 +09:00
Nobuhiro IMAI 7ff0e93f96
parse.y: handle "duplicated argument name" appropriately on ripper.y
refs: 733ed1e184
2021-01-09 13:33:33 +09:00
Nobuyoshi Nakada 35c3a24c8c
Fixed error message when % at EOF 2021-01-04 12:11:37 +09:00