summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-17 03:20:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-17 03:20:58 +0000
commit467830e86751e864410791334e36c4c8c4d54937 (patch)
treeeff61c98cf143fc265760a639e80eea4fc74e244 /iseq.c
parentfd639a4c3bb7f5a9f0f33c2230ab58fd4bd3d70b (diff)
compile.c: struct accessors
* compile.c (rb_method_for_self_aref, rb_method_for_self_aset): move from iseq.c to build from node instead of arrays. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c122
1 files changed, 0 insertions, 122 deletions
diff --git a/iseq.c b/iseq.c
index d2608e8..de65dcb 100644
--- a/iseq.c
+++ b/iseq.c
@@ -553,128 +553,6 @@ iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
return iseqval;
}
-static VALUE
-caller_location(VALUE *path, VALUE *absolute_path)
-{
- rb_thread_t *th = GET_THREAD();
- rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
-
- if (cfp) {
- int line = rb_vm_get_sourceline(cfp);
- *path = cfp->iseq->location.path;
- *absolute_path = cfp->iseq->location.absolute_path;
- return INT2FIX(line);
- }
- else {
- *path = rb_str_new2("<compiled>");
- *absolute_path = *path;
- return INT2FIX(1);
- }
-}
-
-VALUE
-rb_method_for_self_aref(VALUE name, VALUE arg, rb_insn_func_t func)
-{
- VALUE iseqval = iseq_alloc(rb_cISeq);
- rb_iseq_t *iseq;
- VALUE path, absolute_path;
- VALUE lineno = caller_location(&path, &absolute_path);
- VALUE parent = 0;
- VALUE misc, locals, params, exception, body, send_arg;
-
- GetISeqPtr(iseqval, iseq);
- iseq->self = iseqval;
- iseq->local_iseq = iseq;
-
- prepare_iseq_build(iseq, rb_sym2str(name), path, absolute_path,
- lineno, parent,
- ISEQ_TYPE_METHOD, &COMPILE_OPTION_DEFAULT);
-
- misc = params = rb_hash_new(); /* empty */
- locals = exception = rb_ary_tmp_new(0); /* empty */
- body = rb_ary_tmp_new(5);
-
-#define S(s) ID2SYM(rb_intern(#s))
-#define ADD(a) rb_ary_push(body, rb_obj_hide(a))
- /* def name; self[arg]; end */
- ADD(lineno);
- ADD(rb_ary_new3(2, S(putobject), arg));
-
-#if SIZEOF_VALUE <= SIZEOF_LONG
- send_arg = LONG2NUM((SIGNED_VALUE)func);
-#else
- send_arg = LL2NUM((SIGNED_VALUE)func);
-#endif
- send_arg = rb_ary_new3(2, S(opt_call_c_function), send_arg);
- ADD(send_arg);
- ADD(rb_ary_new3(1, S(leave)));
-#undef S
-#undef ADD
-
- rb_iseq_build_from_ary(iseq, misc, locals, params, exception, body);
- cleanup_iseq_build(iseq);
-
- rb_ary_clear(body);
- rb_ary_clear(send_arg);
-
- return iseqval;
-}
-
-VALUE
-rb_method_for_self_aset(VALUE name, VALUE arg, rb_insn_func_t func)
-{
- VALUE iseqval = iseq_alloc(rb_cISeq);
- rb_iseq_t *iseq;
- VALUE path, absolute_path;
- VALUE lineno = caller_location(&path, &absolute_path);
- VALUE parent = 0;
- VALUE misc, locals, params, exception, body, send_arg;
-
- GetISeqPtr(iseqval, iseq);
- iseq->self = iseqval;
- iseq->local_iseq = iseq;
-
- prepare_iseq_build(iseq, rb_sym2str(name), path, absolute_path,
- lineno, parent,
- ISEQ_TYPE_METHOD, &COMPILE_OPTION_DEFAULT);
-
- /* def name=(val); self[arg] = val; end */
-#define S(s) ID2SYM(rb_intern(#s))
-#define ADD(a) rb_ary_push(body, rb_obj_hide(a))
- misc = rb_hash_new(); /* empty */
- locals = rb_obj_hide(rb_ary_new3(1, S(val)));
- params = rb_hash_new();
- exception = rb_ary_tmp_new(0); /* empty */
- body = rb_ary_tmp_new(6);
-
- rb_hash_aset(params, S(lead_num), INT2FIX(1));
-
- ADD(lineno);
- ADD(rb_ary_new3(3, S(getlocal), INT2FIX(2), INT2FIX(0)));
- ADD(rb_ary_new3(2, S(putobject), arg));
-
-#if SIZEOF_VALUE <= SIZEOF_LONG
- send_arg = LONG2NUM((SIGNED_VALUE)func);
-#else
- send_arg = LL2NUM((SIGNED_VALUE)func);
-#endif
- send_arg = rb_ary_new3(2, S(opt_call_c_function), send_arg);
- ADD(send_arg);
-
- ADD(rb_ary_new3(1, S(pop)));
- ADD(rb_ary_new3(1, S(leave)));
-#undef S
-#undef ADD
-
- rb_iseq_build_from_ary(iseq, misc, locals, params, exception, body);
- cleanup_iseq_build(iseq);
-
- rb_ary_clear(body);
- rb_ary_clear(send_arg);
-
- return iseqval;
-}
-
/*
* :nodoc:
*/