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:
parent
f70aa7637b
commit
ac3bad418c
4 changed files with 24 additions and 7 deletions
13
compile.c
13
compile.c
|
@ -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
12
node.c
|
@ -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
1
node.h
|
@ -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
5
vm.c
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue