1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
ko1 2016-08-03 01:50:50 +00:00
parent 0cd7f5fe87
commit 03cad83593
11 changed files with 63 additions and 32 deletions

View file

@ -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.

2
cont.c
View file

@ -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 */

2
eval.c
View file

@ -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];
}

2
iseq.c
View file

@ -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;
}
}

8
proc.c
View file

@ -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];

15
vm.c
View file

@ -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));
/*

View file

@ -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 {

View file

@ -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)
{

View file

@ -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;
}

View file

@ -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");
}

View file

@ -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' */