Commit graph

2451 commits

Author SHA1 Message Date
S.H
f3df218f48
Introduced rb_node_const_decl_val function
Introduce `rb_node_const_decl_val` function to allow `rb_ary_join` and
`rb_ary_reverse` functions to be removed from Universal Parser.
2024-01-31 13:31:38 +09:00
Nobuyoshi Nakada
23b8337cd1
[Bug #20219] gettable returns NULL on error 2024-01-28 19:15:31 +09:00
Nobuyoshi Nakada
5f733a1ae7
[Bug #20217] rescue block is void only if all children are void 2024-01-28 18:44:09 +09:00
Nobuyoshi Nakada
fed877c791
[Bug #20217] return with ensure is a void value expression 2024-01-28 18:44:09 +09:00
Nobuyoshi Nakada
e018036d89
Rename nd_head in RNode_RESBODY as nd_next 2024-01-28 11:12:22 +09:00
Nobuyoshi Nakada
0f98d284f3
Remove unused nd_resq from RNode_ENSURE 2024-01-28 11:11:13 +09:00
S.H
9b40f42c22
Introduce NODE_ENCODING
`__ENCODING__ `was managed by `NODE_LIT` with Encoding object. 

Introduce `NODE_ENCODING` for
1. `__ENCODING__` is detectable from AST Node.
2. Reduce dependency Ruby object for parse.y
2024-01-27 08:11:10 +00:00
yui-knk
68b9a32a62 bvar is not NODE but ID
Before this commit `ruby -y -e 'tap {|;x, y|}'` failed with SEGV.
This change fixes it.
2024-01-27 16:50:35 +09:00
Nobuyoshi Nakada
ff55d6b8e1
Use token_seen and simplify comment_at_top
Instead of scanning before the current comment.
2024-01-25 15:06:14 +09:00
Jeremy Evans
4f77d8d328 Do not use ruby2_keywords for ... argument forwarding
This allows ... argument forwarding to benefit from Allocationless
Anonymous Splat Forwarding, allowing the `f` call below to not
allocate an array or a hash.

```ruby
a = [1]
kw = {b: 2}

def c(a, b:)
end

def f(...)
  c(...)
end

f(*a, **kw)
```

This temporarily skips prism locals tests until prism is changed
to use * and ** for ..., instead of using ruby2_keywords.

Ignore failures in rbs bundled gems tests, since they fail due
to this change.
2024-01-24 18:25:55 -08:00
yui-knk
ee7f63ebba Make lastline and nextline to be rb_parser_string
This commit changes `struct parser_params` lastline and nextline
from `VALUE` (String object) to `rb_parser_string_t *` so that
dependency on Ruby Object is reduced.
`parser_string_buffer_t string_buffer` is added to `struct parser_params`
to manage `rb_parser_string_t` pointers of each line. All allocated line
strings are freed in `rb_ruby_parser_free`.
2024-01-23 08:58:16 +09:00
yui-knk
3d19409637 Use index for referring to symbols in args rule instead of named references
In `args: args ',' arg_splat`, `args` is not unique name.
Currently the associated rule is interpreted as
`$$ = rest_arg_append(p, $$, $3, &@$);`.
The action works as expected because `$$` is initialized with
`$1` before each action is executed.
However it's misleading then change to use index.
2024-01-22 16:05:43 +09:00
Nobuyoshi Nakada
0610f555ea
Constify rb_global_parser_config 2024-01-14 17:55:11 +09:00
yui-knk
ccd45a1399 Stop using Array to manage dummy end token locations
Before this commit, Array is used to store token locations
which expect `end` token, e.g. `class` and `module`.
This commit introduces dedicated struct to manage them
so that dependency on Ruby Object is reduced.
2024-01-13 20:41:22 +09:00
S-H-GAMELINKS
524770d3dc Suppress warnings in parser_set_encode function 2024-01-12 22:46:07 +09:00
yui-knk
b35e21b388 Remove reference counter from rb_parser_config
It's allocated outside of parser then no need to track
reference count in rb_parser_config.
2024-01-12 21:17:41 +09:00
yui-knk
52d9e55903 Statically allocate parser config 2024-01-12 21:17:41 +09:00
yui-knk
c3b2436154 set_yylval_literal is not used 2024-01-12 21:11:00 +09:00
Nobuyoshi Nakada
3d3bc029c5
Reject encodings determined at runtime as source code encodings
The encodings determined at runtime are affected by the runtime
environment, such as the OS and locale, while the file contents are
not.
2024-01-11 18:46:51 +09:00
Nobuyoshi Nakada
7cc8d58cc9
Remove duplicate function nd_st_key_val 2024-01-11 17:46:09 +09:00
S-H-GAMELINKS
a971229462 Fixed return values for some node types in nd_st_key function 2024-01-11 12:26:30 +09:00
Nobuyoshi Nakada
e59a730477
st_index_t is not VALUE 2024-01-10 14:06:33 +09:00
Peter Zhu
02d8bad6e1 Fix memory leak in parser for invalid syntax
The strterm is leaked when there is invalid syntax.

For example:

    10.times do
      100_000.times do
        begin
          RubyVM::InstructionSequence.compile('private def foo = puts "Hello"')
        rescue SyntaxError
        end
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    20384
    26256
    32592
    36720
    42016
    47888
    53248
    57456
    62928
    65936

After:

    16720
    17488
    17616
    17616
    17616
    17616
    17616
    17616
    17616
    16032

Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
2024-01-09 09:41:02 -05:00
Nobuyoshi Nakada
38bc107f0b
Convert a series of else if lines to a switch 2024-01-09 18:47:15 +09:00
yui-knk
db476cc71c Introduce NODE_SYM to manage symbol literal
`:sym` was managed by `NODE_LIT` with `Symbol` object.
This commit introduces `NODE_SYM` so that

1. Symbol literal is detectable from AST Node
2. Reduce dependency on ruby object
2024-01-09 16:07:19 +09:00
Nobuyoshi Nakada
4b01983bf8
Simplify empty hahs with DSTAR 2024-01-09 13:05:34 +09:00
Nobuyoshi Nakada
a4406bc89a
Extract repeating NODE references as a local variable 2024-01-09 13:04:26 +09:00
yui-knk
5ecf2d2880 Use strcmp to compare strings 2024-01-09 07:42:44 +09:00
yui-knk
41e2d180a3 Do not convert NODE_STR to NODE_LIT when the string is hash key
parse.y converted NODE_STR when the string is hash key like

```
h1 = {"str1" => 1}
m1("str2" => 2)
m2({"str3" => 3})
```

This commit stop the conversion.
`static_literal_node_p` needs to know the node is for hash key or not
for the optimization.
2024-01-08 18:48:24 +09:00
yui-knk
7ffff3e043 Change numeric node value functions argument to NODE *
Change the argument to align with other node value functions
like `rb_node_line_lineno_val`.
2024-01-08 14:02:48 +09:00
yui-knk
9527093759 Fix numeric node print by -y option
These nodes are not NOTE_LIT, so need to treat separately.
2024-01-08 11:57:30 +09:00
Nobuyoshi Nakada
8b86d6f0c1
Suppress unused-but-set-variable warning in ripper
`set_yylval_node` in ripper does not use the argument at all.
2024-01-08 01:23:58 +09:00
Nobuyoshi Nakada
c30b8ae947
Adjust styles and indents [ci skip] 2024-01-08 00:50:41 +09:00
S-H-GAMELINKS
ad7aee35e4 Remove unneeded rb_parser_config_struct struct properties for Universal Parser 2024-01-07 21:16:31 +09:00
yui-knk
83c98ead4e Do not remove hash duplicated keys in parse.y
When hash keys are duplicated, e.g. `h = {k: 1, l: 2, k: 3}`,
parser changes node structure for correct compilation.
This generates tricky AST. This commit removes AST manipulation
from parser to keep AST structure simple.
2024-01-07 16:18:16 +09:00
yui-knk
9d3dcb86d1 Check hash key duplication for __LINE__ and __FILE__ 2024-01-07 14:32:10 +09:00
S-H-GAMELINKS
1b8d01136c Introduce Numeric Node's 2024-01-07 09:24:34 +09:00
yui-knk
7a050638b1 Introduce NODE_FILE
`__FILE__` was managed by `NODE_STR` with `String` object.
This commit introduces `NODE_FILE` and `struct rb_parser_string` so that

1. `__FILE__` is detectable from AST Node
2. Reduce dependency ruby object
2024-01-02 14:19:42 +09:00
yui-knk
6ec4d203f7 Warn "literal in condition" for __LINE__
Print warning for a code like

```ruby
if __LINE__
end

# => warning: literal in condition
```
2024-01-02 09:50:32 +09:00
yui-knk
1ade170a6c Introduce NODE_LINE
`__LINE__` was managed by `NODE_LIT` with `Integer` object.
This commit introduces `NODE_LINE` so that

1. `__LINE__` is detectable from AST Node
2. Reduce dependency ruby object
2023-12-29 18:32:27 +09:00
Nobuyoshi Nakada
bc002971b6
[Bug #20094] Distinguish begin and parentheses 2023-12-27 17:50:15 +09:00
Nobuyoshi Nakada
15c280639e
Initialize rb_node_block_t::nd_end at creation 2023-12-27 17:50:15 +09:00
Nobuyoshi Nakada
d0546012f2
Use NODE_ERROR as placeholder of error instead of NODE_BEGIN 2023-12-27 17:50:15 +09:00
yui-knk
33345d2e9f Include new node types into %printer 2023-12-27 12:25:17 +09:00
Nobuyoshi Nakada
596db9c1f4 [Feature #19370] Blocks without anonymous parameters should not affect 2023-12-25 18:28:21 +09:00
Takashi Kokubun
44592c4e20
Implement it (#9199)
[[Feature #18980]](https://bugs.ruby-lang.org/issues/18980)

Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
2023-12-25 01:15:41 -08:00
Nobuyoshi Nakada
a9f0961831 [Feature #19370] Prohibit nesting anonymous parameter forwarding 2023-12-25 14:44:04 +09:00
Nobuyoshi Nakada
40e3f782dd Extract forwarding_arg_check function 2023-12-22 23:08:10 +09:00
Nobuyoshi Nakada
11c2aa035b Extract arg_splat nonterminal symbol 2023-12-22 23:08:10 +09:00
Nobuyoshi Nakada
92b10f5be7 [Bug #20062] Fixed numbered parameter syntax error
At the method definition, the local scope that saves the context of
the numbered parameters needs to be pushed before saving.
2023-12-16 02:11:51 +09:00