summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-24 06:16:31 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-24 06:16:31 +0000
commitac3bad418c37195547a09bf6d1e3fc9d5ec99460 (patch)
treec3110ced5a14785b9b2afd2f03c1cc1a08aa8a8b
parentf70aa7637b68dc7035c4598f97220ad778693aa2 (diff)
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
-rw-r--r--compile.c13
-rw-r--r--node.c12
-rw-r--r--node.h1
-rw-r--r--vm.c5
4 files changed, 24 insertions, 7 deletions
diff --git a/compile.c b/compile.c
index 8c7676d4c9..a1887521a0 100644
--- a/compile.c
+++ b/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);
diff --git a/node.c b/node.c
index 4070bec825..d0288beead 100644
--- a/node.c
+++ b/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)
{
diff --git a/node.h b/node.h
index 33c4a77396..c7475cf980 100644
--- a/node.h
+++ b/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);
diff --git a/vm.c b/vm.c
index 0ede2b8327..19ec4f4a09 100644
--- a/vm.c
+++ b/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);