diff --git a/iseq.c b/iseq.c index d985b57239..ee78a918f1 100644 --- a/iseq.c +++ b/iseq.c @@ -708,7 +708,7 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, c ast = (*parse)(parser, file, src, ln); } - if (!ast->root) { + if (!ast->body.root) { rb_ast_dispose(ast); rb_exc_raise(GET_EC()->errinfo); } @@ -716,7 +716,7 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, c INITIALIZED VALUE label = parent ? parent->body->location.label : rb_fstring_cstr(""); - iseq = rb_iseq_new_with_opt(ast->root, label, file, realpath, line, + iseq = rb_iseq_new_with_opt(ast->body.root, label, file, realpath, line, parent, type, &option); rb_ast_dispose(ast); } @@ -927,17 +927,17 @@ iseqw_s_compile_file(int argc, VALUE *argv, VALUE self) parser = rb_parser_new(); rb_parser_set_context(parser, NULL, FALSE); ast = rb_parser_compile_file_path(parser, file, f, NUM2INT(line)); - if (!ast->root) exc = GET_EC()->errinfo; + if (!ast->body.root) exc = GET_EC()->errinfo; rb_io_close(f); - if (!ast->root) { + if (!ast->body.root) { rb_ast_dispose(ast); rb_exc_raise(exc); } make_compile_option(&option, opt); - ret = iseqw_new(rb_iseq_new_with_opt(ast->root, rb_fstring_cstr("
"), + ret = iseqw_new(rb_iseq_new_with_opt(ast->body.root, rb_fstring_cstr("
"), file, rb_realpath_internal(Qnil, file, 1), line, NULL, ISEQ_TYPE_TOP, &option)); diff --git a/load.c b/load.c index cfc8b1f032..e127eb1b68 100644 --- a/load.c +++ b/load.c @@ -604,7 +604,7 @@ rb_load_internal0(rb_execution_context_t *ec, VALUE fname, int wrap) VALUE parser = rb_parser_new(); rb_parser_set_context(parser, NULL, FALSE); ast = (rb_ast_t *)rb_parser_load_file(parser, fname); - iseq = rb_iseq_new_top(ast->root, rb_fstring_cstr(""), + iseq = rb_iseq_new_top(ast->body.root, rb_fstring_cstr(""), fname, rb_realpath_internal(Qnil, fname, 1), NULL); rb_ast_dispose(ast); } diff --git a/node.c b/node.c index 4254fd7425..072f4f57b3 100644 --- a/node.c +++ b/node.c @@ -1150,7 +1150,7 @@ rb_ast_delete_node(rb_ast_t *ast, NODE *n) rb_ast_t * rb_ast_new(void) { - return (rb_ast_t *)rb_imemo_new(imemo_ast, 0, (VALUE)rb_node_buffer_new(), rb_ary_tmp_new(0), 0); + return (rb_ast_t *)rb_imemo_new(imemo_ast, rb_ary_tmp_new(0), 0, 0, (VALUE)rb_node_buffer_new()); } void diff --git a/node.h b/node.h index aa16a1f93f..f0ddf58d57 100644 --- a/node.h +++ b/node.h @@ -467,12 +467,15 @@ RUBY_SYMBOL_EXPORT_BEGIN typedef struct node_buffer_struct node_buffer_t; /* T_IMEMO/ast */ +typedef struct rb_ast_body_struct { + const NODE *root; + VALUE reserved; +} rb_ast_body_t; typedef struct rb_ast_struct { VALUE flags; - VALUE reserved1; - const NODE *root; node_buffer_t *node_buffer; VALUE mark_ary; + rb_ast_body_t body; } rb_ast_t; rb_ast_t *rb_ast_new(); void rb_ast_mark(rb_ast_t*); diff --git a/parse.y b/parse.y index a036c808b6..6df4a3b2ca 100644 --- a/parse.y +++ b/parse.y @@ -5675,7 +5675,7 @@ yycompile(VALUE vparser, struct parser_params *parser, VALUE fname, int line) ruby_sourceline = line - 1; parser->ast = ast = rb_ast_new(); - ast->root = (NODE *)rb_suppress_tracing(yycompile0, (VALUE)parser); + ast->body.root = (NODE *)rb_suppress_tracing(yycompile0, (VALUE)parser); parser->ast = 0; RB_GC_GUARD(vparser); /* prohibit tail call optimization */ diff --git a/ruby.c b/ruby.c index 452d0a0e3c..83dcc4093b 100644 --- a/ruby.c +++ b/ruby.c @@ -1704,7 +1704,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) rb_enc_set_default_internal(Qnil); rb_stdio_set_default_encoding(); - if (!ast->root) { + if (!ast->body.root) { rb_ast_dispose(ast); return Qfalse; } @@ -1726,7 +1726,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) } if (dump & (DUMP_BIT(parsetree)|DUMP_BIT(parsetree_with_comment))) { - rb_io_write(rb_stdout, rb_parser_dump_tree(ast->root, dump & DUMP_BIT(parsetree_with_comment))); + rb_io_write(rb_stdout, rb_parser_dump_tree(ast->body.root, dump & DUMP_BIT(parsetree_with_comment))); rb_io_flush(rb_stdout); dump &= ~DUMP_BIT(parsetree)&~DUMP_BIT(parsetree_with_comment); if (!dump) { @@ -1749,7 +1749,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) } } base_block = toplevel_context(toplevel_binding); - iseq = rb_iseq_new_main(ast->root, opt->script_name, path, vm_block_iseq(base_block)); + iseq = rb_iseq_new_main(ast->body.root, opt->script_name, path, vm_block_iseq(base_block)); rb_ast_dispose(ast); } diff --git a/template/prelude.c.tmpl b/template/prelude.c.tmpl index 3cf74eda12..b144f8ab0a 100644 --- a/template/prelude.c.tmpl +++ b/template/prelude.c.tmpl @@ -161,11 +161,11 @@ prelude_eval(VALUE code, VALUE name, int line) }; rb_ast_t *ast = rb_parser_compile_string_path(rb_parser_new(), name, code, line); - if (!ast->root) { + if (!ast->body.root) { rb_ast_dispose(ast); rb_exc_raise(rb_errinfo()); } - rb_iseq_eval(rb_iseq_new_with_opt(ast->root, name, name, Qnil, INT2FIX(line), + rb_iseq_eval(rb_iseq_new_with_opt(ast->body.root, name, name, Qnil, INT2FIX(line), NULL, ISEQ_TYPE_TOP, &optimization)); rb_ast_dispose(ast); } diff --git a/vm_eval.c b/vm_eval.c index 87fee5aa64..d9b2ec06b3 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1272,8 +1272,8 @@ eval_make_iseq(VALUE src, VALUE fname, int line, const rb_binding_t *bind, rb_parser_set_context(parser, base_block, FALSE); ast = rb_parser_compile_string_path(parser, fname, src, line); - if (ast->root) { - iseq = rb_iseq_new_with_opt(ast->root, + if (ast->body.root) { + iseq = rb_iseq_new_with_opt(ast->body.root, parent->body->location.label, fname, realpath, INT2FIX(line), parent, ISEQ_TYPE_EVAL, NULL);