summaryrefslogtreecommitdiff
path: root/vm_eval.c
diff options
context:
space:
mode:
authorHASUMI Hitoshi <[email protected]>2024-04-16 18:42:42 +0900
committerYuichiro Kaneko <[email protected]>2024-04-26 11:21:08 +0900
commit2244c58b009c31da60ad108d6cbccf99d97a5e29 (patch)
tree8d8a6cab701722368e72479a0f8505dfbf5d9a45 /vm_eval.c
parent9b5bc8e6ea3e5269a5415546a33fd09035eab168 (diff)
[Universal parser] Decouple IMEMO from rb_ast_t
This patch removes the `VALUE flags` member from the `rb_ast_t` structure making `rb_ast_t` no longer an IMEMO object. ## Background We are trying to make the Ruby parser generated from parse.y a universal parser that can be used by other implementations such as mruby. To achieve this, it is necessary to exclude VALUE and IMEMO from parse.y, AST, and NODE. ## Summary (file by file) - `rubyparser.h` - Remove the `VALUE flags` member from `rb_ast_t` - `ruby_parser.c` and `internal/ruby_parser.h` - Use TypedData_Make_Struct VALUE which wraps `rb_ast_t` `in ast_alloc()` so that GC can manage it - You can retrieve `rb_ast_t` from the VALUE by `rb_ruby_ast_data_get()` - Change the return type of `rb_parser_compile_XXXX()` functions from `rb_ast_t *` to `VALUE` - rb_ruby_ast_new() which internally `calls ast_alloc()` is to create VALUE vast outside ruby_parser.c - `iseq.c` and `vm_core.h` - Amend the first parameter of `rb_iseq_new_XXXX()` functions from `rb_ast_body_t *` to `VALUE` - This keeps the VALUE of AST on the machine stack to prevent being removed by GC - `ast.c` - Almost all change is replacement `rb_ast_t *ast` with `VALUE vast` (sorry for the big diff) - Fix `node_memsize()` - Now it includes `rb_ast_local_table_link`, `tokens` and script_lines - `compile.c`, `load.c`, `node.c`, `parse.y`, `proc.c`, `ruby.c`, `template/prelude.c.tmpl`, `vm.c` and `vm_eval.c` - Follow-up due to the above changes - `imemo.{c|h}` - If an object with `imemo_ast` appears, considers it a bug Co-authored-by: Nobuyoshi Nakada <[email protected]>
Diffstat (limited to 'vm_eval.c')
-rw-r--r--vm_eval.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/vm_eval.c b/vm_eval.c
index 542f8d0b3a..4dfff02f6b 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1753,6 +1753,7 @@ eval_make_iseq(VALUE src, VALUE fname, int line,
const VALUE parser = rb_parser_new();
const rb_iseq_t *const parent = vm_block_iseq(base_block);
rb_iseq_t *iseq = NULL;
+ VALUE vast;
rb_ast_t *ast;
int isolated_depth = 0;
@@ -1790,10 +1791,13 @@ eval_make_iseq(VALUE src, VALUE fname, int line,
rb_parser_set_context(parser, parent, FALSE);
if (ruby_vm_keep_script_lines) rb_parser_set_script_lines(parser);
- ast = rb_parser_compile_string_path(parser, fname, src, line);
+ vast = rb_parser_compile_string_path(parser, fname, src, line);
+
+ ast = rb_ruby_ast_data_get(vast);
+
if (ast->body.root) {
ast->body.coverage_enabled = coverage_enabled;
- iseq = rb_iseq_new_eval(&ast->body,
+ iseq = rb_iseq_new_eval(vast,
ISEQ_BODY(parent)->location.label,
fname, Qnil, line,
parent, isolated_depth);