diff --git a/compile.c b/compile.c index 7c1c359b22..e7fd0a0201 100644 --- a/compile.c +++ b/compile.c @@ -1224,9 +1224,13 @@ new_child_iseq(rb_iseq_t *iseq, const NODE *const node, VALUE name, const rb_iseq_t *parent, enum iseq_type type, int line_no) { rb_iseq_t *ret_iseq; + rb_ast_body_t ast; + + ast.root = node; + ast.reserved = 0; debugs("[new_child_iseq]> ---------------------------------------\n"); - ret_iseq = rb_iseq_new_with_opt(node, name, + ret_iseq = rb_iseq_new_with_opt(&ast, name, rb_iseq_path(iseq), rb_iseq_realpath(iseq), INT2FIX(line_no), parent, type, ISEQ_COMPILE_DATA(iseq)->option); debugs("[new_child_iseq]< ---------------------------------------\n"); diff --git a/iseq.c b/iseq.c index ee78a918f1..1723579864 100644 --- a/iseq.c +++ b/iseq.c @@ -476,24 +476,24 @@ make_compile_option_value(rb_compile_option_t *option) } rb_iseq_t * -rb_iseq_new(const NODE *node, VALUE name, VALUE path, VALUE realpath, +rb_iseq_new(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum iseq_type type) { - return rb_iseq_new_with_opt(node, name, path, realpath, INT2FIX(0), parent, type, + return rb_iseq_new_with_opt(ast, name, path, realpath, INT2FIX(0), parent, type, &COMPILE_OPTION_DEFAULT); } rb_iseq_t * -rb_iseq_new_top(const NODE *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent) +rb_iseq_new_top(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent) { - return rb_iseq_new_with_opt(node, name, path, realpath, INT2FIX(0), parent, ISEQ_TYPE_TOP, + return rb_iseq_new_with_opt(ast, name, path, realpath, INT2FIX(0), parent, ISEQ_TYPE_TOP, &COMPILE_OPTION_DEFAULT); } rb_iseq_t * -rb_iseq_new_main(const NODE *node, VALUE path, VALUE realpath, const rb_iseq_t *parent) +rb_iseq_new_main(const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent) { - return rb_iseq_new_with_opt(node, rb_fstring_cstr("
"), + return rb_iseq_new_with_opt(ast, rb_fstring_cstr("
"), path, realpath, INT2FIX(0), parent, ISEQ_TYPE_MAIN, &COMPILE_OPTION_DEFAULT); } @@ -513,10 +513,11 @@ iseq_translate(rb_iseq_t *iseq) } rb_iseq_t * -rb_iseq_new_with_opt(const NODE *node, VALUE name, VALUE path, VALUE realpath, +rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, enum iseq_type type, const rb_compile_option_t *option) { + const NODE *node = ast ? ast->root : 0; /* TODO: argument check */ rb_iseq_t *iseq = iseq_alloc(); @@ -716,7 +717,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->body.root, label, file, realpath, line, + iseq = rb_iseq_new_with_opt(&ast->body, label, file, realpath, line, parent, type, &option); rb_ast_dispose(ast); } @@ -937,7 +938,7 @@ iseqw_s_compile_file(int argc, VALUE *argv, VALUE self) make_compile_option(&option, opt); - ret = iseqw_new(rb_iseq_new_with_opt(ast->body.root, rb_fstring_cstr("
"), + ret = iseqw_new(rb_iseq_new_with_opt(&ast->body, 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 e127eb1b68..e2a7a98522 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->body.root, rb_fstring_cstr(""), + iseq = rb_iseq_new_top(&ast->body, rb_fstring_cstr(""), fname, rb_realpath_internal(Qnil, fname, 1), NULL); rb_ast_dispose(ast); } diff --git a/ruby.c b/ruby.c index 83dcc4093b..7e58ecb510 100644 --- a/ruby.c +++ b/ruby.c @@ -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->body.root, opt->script_name, path, vm_block_iseq(base_block)); + iseq = rb_iseq_new_main(&ast->body, 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 b144f8ab0a..b12a27059c 100644 --- a/template/prelude.c.tmpl +++ b/template/prelude.c.tmpl @@ -165,7 +165,7 @@ prelude_eval(VALUE code, VALUE name, int line) rb_ast_dispose(ast); rb_exc_raise(rb_errinfo()); } - rb_iseq_eval(rb_iseq_new_with_opt(ast->body.root, name, name, Qnil, INT2FIX(line), + rb_iseq_eval(rb_iseq_new_with_opt(&ast->body, name, name, Qnil, INT2FIX(line), NULL, ISEQ_TYPE_TOP, &optimization)); rb_ast_dispose(ast); } diff --git a/vm.c b/vm.c index 640d02fc4f..96b7a07590 100644 --- a/vm.c +++ b/vm.c @@ -937,7 +937,8 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I const rb_env_t *env; rb_execution_context_t *ec = GET_EC(); const rb_iseq_t *base_iseq, *iseq; - NODE *node = 0, tmp_node; + rb_ast_body_t ast; + NODE tmp_node; ID minibuf[4], *dyns = minibuf; VALUE idtmp = 0; @@ -950,17 +951,18 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I dyns[0] = dyncount; MEMCPY(dyns + 1, dynvars, ID, dyncount); - node = &tmp_node; - rb_node_init(node, NODE_SCOPE, (VALUE)dyns, 0, 0); + rb_node_init(&tmp_node, NODE_SCOPE, (VALUE)dyns, 0, 0); + ast.root = &tmp_node; + ast.reserved = 0; if (base_iseq) { - iseq = rb_iseq_new(node, base_iseq->body->location.label, path, realpath, base_iseq, ISEQ_TYPE_EVAL); + iseq = rb_iseq_new(&ast, base_iseq->body->location.label, path, realpath, base_iseq, ISEQ_TYPE_EVAL); } else { VALUE tempstr = rb_fstring_cstr(""); - iseq = rb_iseq_new_top(node, tempstr, tempstr, tempstr, NULL); + iseq = rb_iseq_new_top(&ast, tempstr, tempstr, tempstr, NULL); } - node->nd_tbl = 0; /* reset table */ + tmp_node.nd_tbl = 0; /* reset table */ ALLOCV_END(idtmp); vm_set_eval_stack(ec, iseq, 0, base_block); diff --git a/vm_core.h b/vm_core.h index 59d627a935..bbb52d4ce1 100644 --- a/vm_core.h +++ b/vm_core.h @@ -884,10 +884,10 @@ typedef enum { RUBY_SYMBOL_EXPORT_BEGIN /* node -> iseq */ -rb_iseq_t *rb_iseq_new (const NODE *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum iseq_type); -rb_iseq_t *rb_iseq_new_top (const NODE *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent); -rb_iseq_t *rb_iseq_new_main (const NODE *node, VALUE path, VALUE realpath, const rb_iseq_t *parent); -rb_iseq_t *rb_iseq_new_with_opt(const NODE *node, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, +rb_iseq_t *rb_iseq_new (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum iseq_type); +rb_iseq_t *rb_iseq_new_top (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent); +rb_iseq_t *rb_iseq_new_main (const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent); +rb_iseq_t *rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, enum iseq_type, const rb_compile_option_t*); rb_iseq_t *rb_iseq_new_ifunc(const struct vm_ifunc *ifunc, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, enum iseq_type, const rb_compile_option_t*); diff --git a/vm_eval.c b/vm_eval.c index d9b2ec06b3..ee17ef6420 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1273,7 +1273,7 @@ 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->body.root) { - iseq = rb_iseq_new_with_opt(ast->body.root, + iseq = rb_iseq_new_with_opt(&ast->body, parent->body->location.label, fname, realpath, INT2FIX(line), parent, ISEQ_TYPE_EVAL, NULL);