ruby-changes:48275
From: mame <ko1@a...>
Date: Tue, 24 Oct 2017 15:16:37 +0900 (JST)
Subject: [ruby-changes:48275] mame:r60390 (trunk): Remove dynamic NODE allocation out of parser
mame 2017-10-24 15:16:31 +0900 (Tue, 24 Oct 2017) New Revision: 60390 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60390 Log: 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. Modified files: trunk/compile.c trunk/node.c trunk/node.h trunk/vm.c Index: vm.c =================================================================== --- vm.c (revision 60389) +++ vm.c (revision 60390) @@ -932,7 +932,7 @@ rb_binding_add_dynavars(VALUE bindval, r https://github.com/ruby/ruby/blob/trunk/vm.c#L932 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, r https://github.com/ruby/ruby/blob/trunk/vm.c#L945 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); Index: compile.c =================================================================== --- compile.c (revision 60389) +++ compile.c (revision 60390) @@ -3963,11 +3963,14 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L3963 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); Index: node.c =================================================================== --- node.c (revision 60389) +++ node.c (revision 60390) @@ -1062,6 +1062,18 @@ rb_gc_free_node(VALUE obj) https://github.com/ruby/ruby/blob/trunk/node.c#L1062 } } +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) { Index: node.h =================================================================== --- node.h (revision 60389) +++ node.h (revision 60390) @@ -461,6 +461,7 @@ NODE *rb_compile_cstr(const char*, const https://github.com/ruby/ruby/blob/trunk/node.h#L461 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/