summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-03 01:50:50 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-03 01:50:50 +0000
commit03cad835932205e9ca9e11bed1e6394272ca3f5c (patch)
treee99a0dbd528aa38d6b384eaa2518a9f0510e5838
parent0cd7f5fe87fb2d047a5423cd24c24f9fea530502 (diff)
* vm_core.h: introduce VM_FRAME_RUBYFRAME_P()
and VM_FRAME_CFRAME_P(). Most of case, RUBY_VM_NORMAL_ISEQ_P() is no longer needed. * vm_core.h: introduce rb_obj_is_iseq(). * cont.c, vm.c: VM_FRAME_MAGIC_DUMMY with VM_FRAME_FLAG_CFRAME. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--cont.c2
-rw-r--r--eval.c2
-rw-r--r--iseq.c2
-rw-r--r--proc.c8
-rw-r--r--vm.c15
-rw-r--r--vm_backtrace.c11
-rw-r--r--vm_core.h26
-rw-r--r--vm_dump.c11
-rw-r--r--vm_eval.c2
-rw-r--r--vm_insnhelper.c4
11 files changed, 63 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index dce2f41..a1789c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Wed Aug 3 10:47:07 2016 Koichi Sasada <ko1@atdot.net>
+
+ * vm_core.h: introduce VM_FRAME_RUBYFRAME_P()
+ and VM_FRAME_CFRAME_P().
+ Most of case, RUBY_VM_NORMAL_ISEQ_P() is no
+ longer needed.
+
+ * vm_core.h: introduce rb_obj_is_iseq().
+
+ * cont.c, vm.c: VM_FRAME_MAGIC_DUMMY with
+ VM_FRAME_FLAG_CFRAME.
+
Wed Aug 3 09:25:16 2016 Koichi Sasada <ko1@atdot.net>
* vm_core.h: rename macros and make them inline functions.
diff --git a/cont.c b/cont.c
index 528a0af..8119b5c 100644
--- a/cont.c
+++ b/cont.c
@@ -1221,7 +1221,7 @@ fiber_init(VALUE fibval, VALUE proc)
rb_vm_push_frame(th,
NULL,
- VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH,
+ VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_CFRAME,
Qnil, /* self */
VM_BLOCK_HANDLER_NONE,
0, /* specval */
diff --git a/eval.c b/eval.c
index d0f14b0..8c23603 100644
--- a/eval.c
+++ b/eval.c
@@ -1454,7 +1454,7 @@ errinfo_place(rb_thread_t *th)
rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(th);
while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
- if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
+ if (VM_FRAME_RUBYFRAME_P(cfp)) {
if (cfp->iseq->body->type == ISEQ_TYPE_RESCUE) {
return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
}
diff --git a/iseq.c b/iseq.c
index e4698f5..93be1ed 100644
--- a/iseq.c
+++ b/iseq.c
@@ -1651,7 +1651,7 @@ iseqw_s_of(VALUE klass, VALUE body)
if (rb_obj_is_proc(body)) {
iseq = vm_proc_iseq(body);
- if (!RUBY_VM_NORMAL_ISEQ_P(iseq)) {
+ if (!rb_obj_is_iseq((VALUE)iseq)) {
iseq = NULL;
}
}
diff --git a/proc.c b/proc.c
index f6f81c4..de85f0a 100644
--- a/proc.c
+++ b/proc.c
@@ -395,12 +395,12 @@ static const VALUE *
get_local_variable_ptr(const rb_env_t *env, ID lid)
{
do {
- const rb_iseq_t *iseq;
- unsigned int i;
+ if (!VM_ENV_FLAGS(env->ep, VM_FRAME_FLAG_CFRAME)) {
+ const rb_iseq_t *iseq = env->iseq;
+ unsigned int i;
- iseq = env->iseq;
+ VM_ASSERT(rb_obj_is_iseq((VALUE)iseq));
- if (iseq && RUBY_VM_NORMAL_ISEQ_P(iseq)) {
for (i=0; i<iseq->body->local_table_size; i++) {
if (iseq->body->local_table[i] == lid) {
return &env->env[i];
diff --git a/vm.c b/vm.c
index 9d596bb..b77cb77 100644
--- a/vm.c
+++ b/vm.c
@@ -484,7 +484,7 @@ rb_control_frame_t *
rb_vm_get_ruby_level_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp)
{
while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
- if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
+ if (VM_FRAME_RUBYFRAME_P(cfp)) {
return (rb_control_frame_t *)cfp;
}
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
@@ -495,14 +495,14 @@ rb_vm_get_ruby_level_next_cfp(const rb_thread_t *th, const rb_control_frame_t *c
static rb_control_frame_t *
vm_get_ruby_level_caller_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp)
{
- if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
+ if (VM_FRAME_RUBYFRAME_P(cfp)) {
return (rb_control_frame_t *)cfp;
}
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
- if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
+ if (VM_FRAME_RUBYFRAME_P(cfp)) {
return (rb_control_frame_t *)cfp;
}
@@ -662,7 +662,7 @@ vm_make_env_each(rb_thread_t *const th, rb_control_frame_t *const cfp)
}
}
- if (!RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
+ if (!VM_FRAME_RUBYFRAME_P(cfp)) {
local_size = VM_ENV_DATA_SIZE;
}
else {
@@ -689,14 +689,14 @@ vm_make_env_each(rb_thread_t *const th, rb_control_frame_t *const cfp)
#if 0
for (i = 0; i < local_size; i++) {
- if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
+ if (VM_FRAME_RUBYFRAME_P(cfp)) {
/* clear value stack for GC */
ep[-local_size + i] = 0;
}
}
#endif
- env_iseq = RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) ? cfp->iseq : NULL;
+ env_iseq = VM_FRAME_RUBYFRAME_P(cfp) ? cfp->iseq : NULL;
env_ep = &env_body[local_size - 1 /* specval */];
env = vm_env_new(env_ep, env_body, env_size, env_iseq);
@@ -2450,7 +2450,7 @@ th_init(rb_thread_t *th, VALUE self)
th->cfp = (void *)(th->stack + th->stack_size);
- vm_push_frame(th, 0 /* dummy iseq */, VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH /* dummy frame */,
+ vm_push_frame(th, 0 /* dummy iseq */, VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_CFRAME /* dummy frame */,
Qnil /* dummy self */, VM_BLOCK_HANDLER_NONE /* dummy block ptr */,
0 /* dummy cref/me */,
0 /* dummy pc */, th->stack, 0, 0);
@@ -3000,6 +3000,7 @@ Init_VM(void)
th->cfp->pc = iseq->body->iseq_encoded;
th->cfp->self = th->top_self;
+ VM_ENV_FLAGS_UNSET(th->cfp->ep, VM_FRAME_FLAG_CFRAME);
VM_STACK_ENV_WRITE(th->cfp->ep, VM_ENV_DATA_INDEX_ME_CREF, (VALUE)vm_cref_new(rb_cObject, METHOD_VISI_PRIVATE, FALSE, NULL, FALSE));
/*
diff --git a/vm_backtrace.c b/vm_backtrace.c
index bdc996d..cbde640 100644
--- a/vm_backtrace.c
+++ b/vm_backtrace.c
@@ -37,13 +37,12 @@ calc_lineno(const rb_iseq_t *iseq, const VALUE *pc)
int
rb_vm_get_sourceline(const rb_control_frame_t *cfp)
{
- int lineno = 0;
- const rb_iseq_t *iseq = cfp->iseq;
-
- if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
- lineno = calc_lineno(cfp->iseq, cfp->pc);
+ if (VM_FRAME_RUBYFRAME_P(cfp) && cfp->iseq) {
+ return calc_lineno(cfp->iseq, cfp->pc);
+ }
+ else {
+ return 0;
}
- return lineno;
}
typedef struct rb_backtrace_location_struct {
diff --git a/vm_core.h b/vm_core.h
index d7cf0bb..ccba902 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -1040,6 +1040,30 @@ VM_FRAME_BMETHOD_P(const rb_control_frame_t *cfp)
return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_BMETHOD) != 0;
}
+static inline int
+rb_obj_is_iseq(VALUE iseq)
+{
+ return RB_TYPE_P(iseq, T_IMEMO) && imemo_type(iseq) == imemo_iseq;
+}
+
+#if VM_CHECK_MODE > 0
+#define RUBY_VM_NORMAL_ISEQ_P(iseq) rb_obj_is_iseq((VALUE)iseq)
+#endif
+
+static inline int
+VM_FRAME_CFRAME_P(const rb_control_frame_t *cfp)
+{
+ int cframe_p = VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_CFRAME) != 0;
+ VM_ASSERT(RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) != cframe_p);
+ return cframe_p;
+}
+
+static inline int
+VM_FRAME_RUBYFRAME_P(const rb_control_frame_t *cfp)
+{
+ return !VM_FRAME_CFRAME_P(cfp);
+}
+
#define RUBYVM_CFUNC_FRAME_P(cfp) \
(VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC)
@@ -1153,8 +1177,6 @@ VALUE rb_vm_frame_block_handler(const rb_control_frame_t *cfp);
#define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \
(!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
-#define RUBY_VM_NORMAL_ISEQ_P(ptr) (RB_TYPE_P((VALUE)(ptr), T_IMEMO) && imemo_type((VALUE)ptr) == imemo_iseq && rb_iseq_check((rb_iseq_t *)ptr))
-
static inline int
VM_BH_ISEQ_BLOCK_P(VALUE block_handler)
{
diff --git a/vm_dump.c b/vm_dump.c
index 3e8d98e..c0f0685 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -240,16 +240,13 @@ vm_base_ptr(rb_control_frame_t *cfp)
static void
vm_stack_dump_each(rb_thread_t *th, rb_control_frame_t *cfp)
{
- int i;
-
+ int i, argc = 0, local_size = 0;
VALUE rstr;
VALUE *sp = cfp->sp;
VALUE *ep = cfp->ep;
- int argc = 0, local_size = 0;
- rb_iseq_t *iseq = cfp->iseq;
-
- if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
+ if (VM_FRAME_RUBYFRAME_P(cfp)) {
+ rb_iseq_t *iseq = cfp->iseq;
argc = iseq->body->param.lead_num;
local_size = iseq->body->local_size;
}
@@ -317,7 +314,7 @@ rb_vmdebug_debug_print_register(rb_thread_t *th)
ptrdiff_t ep = cfp->ep - th->stack;
ptrdiff_t cfpi;
- if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
+ if (VM_FRAME_RUBYFRAME_P(cfp)) {
pc = cfp->pc - cfp->iseq->body->iseq_encoded;
}
diff --git a/vm_eval.c b/vm_eval.c
index 8233c5d..18cd9dd 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -262,7 +262,7 @@ vm_call_super(rb_thread_t *th, int argc, const VALUE *argv)
rb_control_frame_t *cfp = th->cfp;
const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp);
- if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
+ if (VM_FRAME_RUBYFRAME_P(cfp)) {
rb_bug("vm_call_super: should not be reached");
}
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 16a467f..04a69cc 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1076,7 +1076,7 @@ vm_throw_start(rb_thread_t *const th, rb_control_frame_t *const reg_cfp, enum ru
}
if (lep == target_lep &&
- RUBY_VM_NORMAL_ISEQ_P(escape_cfp->iseq) &&
+ VM_FRAME_RUBYFRAME_P(escape_cfp) &&
escape_cfp->iseq->body->type == ISEQ_TYPE_CLASS) {
in_class_frame = 1;
target_lep = 0;
@@ -1360,7 +1360,7 @@ vm_base_ptr(const rb_control_frame_t *cfp)
{
const rb_control_frame_t *prev_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
- if (cfp->iseq && RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
+ if (cfp->iseq && VM_FRAME_RUBYFRAME_P(cfp)) {
VALUE *bp = prev_cfp->sp + cfp->iseq->body->local_table_size + VM_ENV_DATA_SIZE;
if (cfp->iseq->body->type == ISEQ_TYPE_METHOD) {
/* adjust `self' */