summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-03 20:12:55 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-03 20:12:55 +0000
commite96cd603e5f5da7a887cff4feded62ff05d02d0d (patch)
treeb90a0320810addbdd7001d938fba54a41a7943ec /iseq.c
parent21b644e8123d357df653b65689273be51617bae3 (diff)
* iseq.c (set_relation): added.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c78
1 files changed, 44 insertions, 34 deletions
diff --git a/iseq.c b/iseq.c
index da0652092f..7e1b40c5fb 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;
}