diff options
| author | HASUMI Hitoshi <hasumikin@gmail.com> | 2024-03-28 10:26:42 +0900 |
|---|---|---|
| committer | Yuichiro Kaneko <spiketeika@gmail.com> | 2024-04-15 20:51:54 +0900 |
| commit | 9b1e97b211565b605b8eb7fab277efe117fe2604 (patch) | |
| tree | 8d2b58dc312f564005ab377d2f32ac1354dcc769 /node.c | |
| parent | bb1c3418d0fd3235c678ad68f7b45d32f8183a3f (diff) | |
[Universal parser] DeVALUE of p->debug_lines and ast->body.script_lines
This patch is part of universal parser work.
## Summary
- Decouple VALUE from members below:
- `(struct parser_params *)->debug_lines`
- `(rb_ast_t *)->body.script_lines`
- Instead, they are now `rb_parser_ary_t *`
- They can also be a `(VALUE)FIXNUM` as before to hold line count
- `ISEQ_BODY(iseq)->variable.script_lines` remains VALUE
- In order to do this,
- Add `VALUE script_lines` param to `rb_iseq_new_with_opt()`
- Introduce `rb_parser_build_script_lines_from()` to convert `rb_parser_ary_t *` into `VALUE`
## Other details
- Extend `rb_parser_ary_t *`. It previously could only store `rb_parser_ast_token *`, now can store script_lines, too
- Change tactics of building the top-level `SCRIPT_LINES__` in `yycompile0()`
- Before: While parsing, each line of the script is added to `SCRIPT_LINES__[path]`
- After: After `yyparse(p)`, `SCRIPT_LINES__[path]` will be built from `p->debug_lines`
- Remove the second parameter of `rb_parser_set_script_lines()` to make it simple
- Introduce `script_lines_free()` to be called from `rb_ast_free()` because the GC no longer takes care of the script_lines
- Introduce `rb_parser_string_deep_copy()` in parse.y to maintain script_lines when `rb_ruby_parser_free()` called
- With regard to this, please see *Future tasks* below
## Future tasks
- Decouple IMEMO from `rb_ast_t *`
- This lifts the five-members-restriction of Ruby object,
- So we will be able to move the ownership of the `lex.string_buffer` from parser to AST
- Then we remove `rb_parser_string_deep_copy()` to make the whole thing simple
Diffstat (limited to 'node.c')
| -rw-r--r-- | node.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -20,12 +20,13 @@ #include "internal.h" #include "internal/hash.h" -#include "internal/variable.h" #include "ruby/ruby.h" #include "vm_core.h" #endif +#include "internal/variable.h" + #define NODE_BUF_DEFAULT_SIZE (sizeof(struct RNode) * 16) static void @@ -344,18 +345,24 @@ iterate_node_values(rb_ast_t *ast, node_buffer_list_t *nb, node_itr_t * func, vo } } -void -rb_ast_mark_and_move(rb_ast_t *ast, bool reference_updating) +static void +script_lines_free(rb_ast_t *ast, rb_parser_ary_t *script_lines) { - if (ast->node_buffer) { - if (ast->body.script_lines) rb_gc_mark_and_move(&ast->body.script_lines); + for (long i = 0; i < script_lines->len; i++) { + parser_string_free(ast, (rb_parser_string_t *)script_lines->data[i]); } + xfree(script_lines->data); + xfree(script_lines); } void rb_ast_free(rb_ast_t *ast) { if (ast->node_buffer) { + if (ast->body.script_lines && !FIXNUM_P((VALUE)ast->body.script_lines)) { + script_lines_free(ast, ast->body.script_lines); + ast->body.script_lines = NULL; + } rb_node_buffer_free(ast, ast->node_buffer); ast->node_buffer = 0; } |
