From 7bf2102e80368adc983757f5da5073b73f487c11 Mon Sep 17 00:00:00 2001 From: ko1 Date: Tue, 3 Jul 2007 20:12:55 +0000 Subject: * iseq.c (set_relation): added. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@12689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- iseq.c | 78 +++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 34 deletions(-) (limited to 'iseq.c') diff --git a/iseq.c b/iseq.c index da0652092..7e1b40c5f 100644 --- a/iseq.c +++ b/iseq.c @@ -101,14 +101,52 @@ iseq_alloc(VALUE klass) return obj; } +static void +set_relation(rb_iseq_t *iseq, const VALUE parent) +{ + const int type = iseq->type; + rb_thread_t *th = GET_THREAD(); + + /* set class nest stack */ + if (type == ISEQ_TYPE_TOP) { + /* toplevel is private */ + iseq->cref_stack = NEW_BLOCK(th->top_wrapper ? th->top_wrapper : rb_cObject); + iseq->cref_stack->nd_file = 0; + iseq->cref_stack->nd_visi = NOEX_PRIVATE; + } + else if (type == ISEQ_TYPE_METHOD || type == ISEQ_TYPE_CLASS) { + iseq->cref_stack = NEW_BLOCK(0); /* place holder */ + iseq->cref_stack->nd_file = 0; + } + else if (RTEST(parent)) { + rb_iseq_t *piseq; + GetISeqPtr(parent, piseq); + iseq->cref_stack = piseq->cref_stack; + } + + if (type == ISEQ_TYPE_TOP || + type == ISEQ_TYPE_METHOD || type == ISEQ_TYPE_CLASS) { + iseq->local_iseq = iseq; + } + else if (RTEST(parent)) { + rb_iseq_t *piseq; + GetISeqPtr(parent, piseq); + iseq->local_iseq = piseq->local_iseq; + } + + if (RTEST(parent)) { + rb_iseq_t *piseq; + GetISeqPtr(parent, piseq); + iseq->parent_iseq = piseq; + } +} + static VALUE prepare_iseq_build(rb_iseq_t *iseq, VALUE name, VALUE filename, VALUE parent, VALUE type, VALUE block_opt, const rb_compile_option_t *option) { - rb_thread_t *th = GET_THREAD(); - OBJ_FREEZE(name); OBJ_FREEZE(filename); @@ -126,23 +164,6 @@ prepare_iseq_build(rb_iseq_t *iseq, iseq->cached_special_block_builder = 0; iseq->cached_special_block = 0; - /* set class nest stack */ - if (type == ISEQ_TYPE_TOP) { - /* toplevel is private */ - iseq->cref_stack = NEW_BLOCK(th->top_wrapper ? th->top_wrapper : rb_cObject); - iseq->cref_stack->nd_file = 0; - iseq->cref_stack->nd_visi = NOEX_PRIVATE; - } - else if (type == ISEQ_TYPE_METHOD || type == ISEQ_TYPE_CLASS) { - iseq->cref_stack = NEW_BLOCK(0); /* place holder */ - iseq->cref_stack->nd_file = 0; - } - else if (parent) { - rb_iseq_t *piseq; - GetISeqPtr(parent, piseq); - iseq->cref_stack = piseq->cref_stack; - } - iseq->compile_data = ALLOC(struct iseq_compile_data); MEMZERO(iseq->compile_data, struct iseq_compile_data, 1); iseq->compile_data->mark_ary = rb_ary_new(); @@ -162,21 +183,7 @@ prepare_iseq_build(rb_iseq_t *iseq, (char *)(&iseq->compile_data->storage_head->buff + 1); iseq->compile_data->option = option; - if (type == ISEQ_TYPE_TOP || - type == ISEQ_TYPE_METHOD || type == ISEQ_TYPE_CLASS) { - iseq->local_iseq = iseq; - } - else { - rb_iseq_t *piseq; - GetISeqPtr(parent, piseq); - iseq->local_iseq = piseq->local_iseq; - } - - if (RTEST(parent)) { - rb_iseq_t *piseq; - GetISeqPtr(parent, piseq); - iseq->parent_iseq = piseq; - } + set_relation(iseq, parent); return Qtrue; } @@ -1382,6 +1389,7 @@ rb_iseq_build_for_ruby2cext( iseq->name = rb_str_new2(name); iseq->filename = rb_str_new2(filename); iseq->mark_ary = rb_ary_new(); + iseq->self = iseqval; iseq->iseq = ALLOC_N(VALUE, iseq->iseq_size); @@ -1408,6 +1416,8 @@ rb_iseq_build_for_ruby2cext( ALLOC_AND_COPY(iseq->arg_opt_table, arg_opt_table, VALUE, iseq->arg_opts); + set_relation(iseq, 0); + return iseqval; } -- cgit