1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Remove dynamic NODE allocation out of parser

A temporary NODE object was allocated to create iseq.  Instead, this
patch allocates a dummy NODE as auto variable, and discard it soon.
This change is intended as a preparation to manage AST NODEs out of GC.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2017-10-24 06:16:31 +00:00
parent f70aa7637b
commit ac3bad418c
4 changed files with 24 additions and 7 deletions

View file

@ -3963,11 +3963,14 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
int line = nd_line(node);
LABEL *lstart = NEW_LABEL(line);
LABEL *lend = NEW_LABEL(line);
const rb_iseq_t *rescue = NEW_CHILD_ISEQ(NEW_NIL(),
rb_str_concat(rb_str_new2
("defined guard in "),
iseq->body->location.label),
ISEQ_TYPE_DEFINED_GUARD, 0);
const rb_iseq_t *rescue;
NODE tmp_node, *node = &tmp_node;
rb_node_init(node, NODE_NIL, 0, 0, 0);
rescue = NEW_CHILD_ISEQ(node,
rb_str_concat(rb_str_new2
("defined guard in "),
iseq->body->location.label),
ISEQ_TYPE_DEFINED_GUARD, 0);
lstart->rescued = LABEL_RESCUE_BEG;
lend->rescued = LABEL_RESCUE_END;
APPEND_LABEL(ret, lcur, lstart);

12
node.c
View file

@ -1062,6 +1062,18 @@ rb_gc_free_node(VALUE obj)
}
}
void
rb_node_init(NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2)
{
VALUE klass = 0;
n->flags = T_NODE;
RBASIC_SET_CLASS_RAW((VALUE)n, klass);
n->u1.value = a0;
n->u2.value = a1;
n->u3.value = a2;
nd_set_type(n, type);
}
size_t
rb_node_memsize(VALUE obj)
{

1
node.h
View file

@ -461,6 +461,7 @@ NODE *rb_compile_cstr(const char*, const char*, int, int);
NODE *rb_compile_string(const char*, VALUE, int);
NODE *rb_compile_file(const char*, VALUE, int);
void rb_node_init(NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2);
NODE *rb_node_newnode(enum node_type,VALUE,VALUE,VALUE);
void rb_gc_free_node(VALUE obj);
size_t rb_node_memsize(VALUE obj);

5
vm.c
View file

@ -932,7 +932,7 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I
const rb_env_t *env;
rb_thread_t *th = GET_THREAD();
const rb_iseq_t *base_iseq, *iseq;
NODE *node = 0;
NODE *node = 0, tmp_node;
ID minibuf[4], *dyns = minibuf;
VALUE idtmp = 0;
@ -945,7 +945,8 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I
dyns[0] = dyncount;
MEMCPY(dyns + 1, dynvars, ID, dyncount);
node = NEW_NODE(NODE_SCOPE, dyns, 0, 0);
node = &tmp_node;
rb_node_init(node, NODE_SCOPE, (VALUE)dyns, 0, 0);
if (base_iseq) {
iseq = rb_iseq_new(node, base_iseq->body->location.label, path, realpath, base_iseq, ISEQ_TYPE_EVAL);