Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor parser compile functions #10597

Merged
merged 2 commits into from
Apr 22, 2024
Merged

Refactor parser compile functions #10597

merged 2 commits into from
Apr 22, 2024

Conversation

yui-knk
Copy link
Contributor

@yui-knk yui-knk commented Apr 22, 2024

Refactor parser compile functions to reduce the dependence
on ruby functions.
This commit includes these changes

  1. Refactor gets, input and gets_ of parser_params

Parser needs two different data structure to get next line, function (gets) and input data (input).
However gets_ is used for both function (call) and input data (ptr).
call is used for managing general callback function when rb_ruby_parser_compile_generic is used.
ptr is used for managing the current pointer on String when parser_compile_string is used.
This commit changes parser to used only gets and input then removes gets_.

  1. Move parser_compile functions and gets functions from parse.y to ruby_parser.c

This change reduces the dependence on ruby functions from parser.

  1. Change ruby_parser and ripper to take care of VALUE input GC mark

Move the responsibility of calling rb_gc_mark for VALUE input from parser to ruby_parser and ripper.
input is arbitrary data pointer from the viewpoint of parser.

  1. Introduce rb_parser_compile_array function

Caller of rb_parser_compile_generic needs to take care about GC because ruby_parser doesn’t know
about the detail of lex_gets and input.
Introduce rb_parser_compile_array to reduce the complexity of ast.c.

Refactor parser compile functions to reduce the dependence
on ruby functions.
This commit includes these changes

1. Refactor `gets`, `input` and `gets_` of `parser_params`

Parser needs two different data structure to get next line, function (`gets`) and input data (`input`).
However `gets_` is used for both function (`call`) and input data (`ptr`).
`call` is used for managing general callback function when `rb_ruby_parser_compile_generic` is used.
`ptr` is used for managing the current pointer on String when `parser_compile_string` is used.
This commit changes parser to used only `gets` and `input` then removes `gets_`.

2. Move parser_compile functions and `gets` functions from parse.y to ruby_parser.c

This change reduces the dependence on ruby functions from parser.

3. Change ruby_parser and ripper to take care of `VALUE input` GC mark

Move the responsibility of calling `rb_gc_mark` for `VALUE input` from parser to ruby_parser and ripper.
`input` is arbitrary data pointer from the viewpoint of parser.

4. Introduce rb_parser_compile_array function

Caller of `rb_parser_compile_generic` needs to take care about GC because ruby_parser doesn’t know
about the detail of `lex_gets` and `input`.
Introduce `rb_parser_compile_array` to reduce the complexity of ast.c.
@yui-knk yui-knk merged commit c7d9376 into ruby:master Apr 22, 2024
101 checks passed
@yui-knk yui-knk deleted the extract_gets branch April 22, 2024 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant