* vm.c, insnhelper.ci: fix svar interface.

* compile.c (iseq_compile_each), yarvcore.h: fix to use new
  svar interface for flip flop.
* eval.c: ditto.
* insns.def: ditto.
* include/ruby/intern.h: remove "rb_svar()" declaration.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2007-07-10 08:04:52 +00:00
parent d4662d49d9
commit a6e3d19f3a
9 changed files with 120 additions and 74 deletions

View File

@ -1,3 +1,16 @@
Tue Jul 10 16:58:16 2007 Koichi Sasada <ko1@atdot.net>
* vm.c, insnhelper.ci: fix svar interface.
* compile.c (iseq_compile_each), yarvcore.h: fix to use new
svar interface for flip flop.
* eval.c: ditto.
* insns.def: ditto.
* include/ruby/intern.h: remove "rb_svar()" declaration.
Tue Jul 10 16:52:01 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Jul 10 16:52:01 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c (rb_iseq_compile): formatted if/else to switch statement. * compile.c (rb_iseq_compile): formatted if/else to switch statement.

View File

@ -4172,9 +4172,12 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
LABEL *lend = NEW_LABEL(nd_line(node)); LABEL *lend = NEW_LABEL(nd_line(node));
LABEL *lfin = NEW_LABEL(nd_line(node)); LABEL *lfin = NEW_LABEL(nd_line(node));
LABEL *ltrue = NEW_LABEL(nd_line(node)); LABEL *ltrue = NEW_LABEL(nd_line(node));
VALUE key = rb_sprintf("flipflag/%s-%p-%d",
RSTRING_PTR(iseq->name), iseq,
iseq->compile_data->flip_cnt++);
ADD_INSN2(ret, nd_line(node), getspecial, INT2FIX(node->nd_cnt), iseq_add_mark_object_compile_time(iseq, key);
INT2FIX(0)); ADD_INSN2(ret, nd_line(node), getspecial, key, INT2FIX(0));
ADD_INSNL(ret, nd_line(node), branchif, lend); ADD_INSNL(ret, nd_line(node), branchif, lend);
/* *flip == 0 */ /* *flip == 0 */
@ -4183,11 +4186,11 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
ADD_INSNL(ret, nd_line(node), branchunless, lfin); ADD_INSNL(ret, nd_line(node), branchunless, lfin);
if (nd_type(node) == NODE_FLIP3) { if (nd_type(node) == NODE_FLIP3) {
ADD_INSN(ret, nd_line(node), dup); ADD_INSN(ret, nd_line(node), dup);
ADD_INSN1(ret, nd_line(node), setspecial, INT2FIX(node->nd_cnt)); ADD_INSN1(ret, nd_line(node), setspecial, key);
ADD_INSNL(ret, nd_line(node), jump, lfin); ADD_INSNL(ret, nd_line(node), jump, lfin);
} }
else { else {
ADD_INSN1(ret, nd_line(node), setspecial, INT2FIX(node->nd_cnt)); ADD_INSN1(ret, nd_line(node), setspecial, key);
} }
/* *flip == 1 */ /* *flip == 1 */
@ -4195,7 +4198,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
COMPILE(ret, "flip2 end", node->nd_end); COMPILE(ret, "flip2 end", node->nd_end);
ADD_INSNL(ret, nd_line(node), branchunless, ltrue); ADD_INSNL(ret, nd_line(node), branchunless, ltrue);
ADD_INSN1(ret, nd_line(node), putobject, Qfalse); ADD_INSN1(ret, nd_line(node), putobject, Qfalse);
ADD_INSN1(ret, nd_line(node), setspecial, INT2FIX(node->nd_cnt)); ADD_INSN1(ret, nd_line(node), setspecial, key);
ADD_LABEL(ret, ltrue); ADD_LABEL(ret, ltrue);
ADD_INSN1(ret, nd_line(node), putobject, Qtrue); ADD_INSN1(ret, nd_line(node), putobject, Qtrue);

11
eval.c
View File

@ -1781,7 +1781,8 @@ rb_f_eval(int argc, VALUE *argv, VALUE self)
return eval(self, src, scope, file, line); return eval(self, src, scope, file, line);
} }
VALUE *vm_cfp_svar(rb_control_frame_t *cfp, int idx); VALUE vm_cfp_svar_get(rb_thread_t *th, rb_control_frame_t *cfp, VALUE key);
void vm_cfp_svar_set(rb_thread_t *th, rb_control_frame_t *cfp, VALUE key, VALUE val);
/* function to call func under the specified class/module context */ /* function to call func under the specified class/module context */
static VALUE static VALUE
@ -1793,7 +1794,6 @@ exec_under(VALUE (*func) (VALUE), VALUE under, VALUE self, VALUE args)
rb_control_frame_t *pcfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); rb_control_frame_t *pcfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
VALUE stored_self = pcfp->self; VALUE stored_self = pcfp->self;
NODE *stored_cref = 0; NODE *stored_cref = 0;
NODE **pcref = 0;
rb_block_t block; rb_block_t block;
rb_block_t *blockptr; rb_block_t *blockptr;
@ -1813,9 +1813,8 @@ exec_under(VALUE (*func) (VALUE), VALUE under, VALUE self, VALUE args)
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
} }
pcref = (NODE **) vm_cfp_svar(cfp, -1); stored_cref = vm_cfp_svar_get(th, cfp, -1);
stored_cref = *pcref; vm_cfp_svar_set(th, cfp, -1, vm_cref_push(th, under, NOEX_PUBLIC));
*pcref = vm_cref_push(th, under, NOEX_PUBLIC);
PUSH_TAG(); PUSH_TAG();
if ((state = EXEC_TAG()) == 0) { if ((state = EXEC_TAG()) == 0) {
@ -1824,7 +1823,7 @@ exec_under(VALUE (*func) (VALUE), VALUE under, VALUE self, VALUE args)
POP_TAG(); POP_TAG();
/* restore environment */ /* restore environment */
*pcref = stored_cref; vm_cfp_svar_set(th, cfp, -1, stored_cref);
pcfp->self = stored_self; pcfp->self = stored_self;
if (state) { if (state) {

View File

@ -228,7 +228,6 @@ void rb_attr(VALUE,ID,int,int,int);
int rb_method_boundp(VALUE, ID, int); int rb_method_boundp(VALUE, ID, int);
void rb_dvar_asgn(ID, VALUE); void rb_dvar_asgn(ID, VALUE);
void rb_dvar_push(ID, VALUE); void rb_dvar_push(ID, VALUE);
VALUE *rb_svar(int);
VALUE rb_eval_cmd(VALUE, VALUE, int); VALUE rb_eval_cmd(VALUE, VALUE, int);
int rb_obj_respond_to(VALUE, ID, int); int rb_obj_respond_to(VALUE, ID, int);
int rb_respond_to(VALUE, ID); int rb_respond_to(VALUE, ID);

View File

@ -747,42 +747,75 @@ new_value(void)
return val; return val;
} }
static VALUE * static struct RValues *
lfp_svar(VALUE *lfp, int cnt) lfp_svar_place(rb_thread_t *th, VALUE *lfp)
{ {
struct RValues *val; struct RValues *svar;
rb_thread_t *th = GET_THREAD();
if (th->local_lfp != lfp) { if (th->local_lfp != lfp) {
val = (struct RValues *)lfp[-1]; svar = (struct RValues *)lfp[-1];
if ((VALUE)val == Qnil) { if ((VALUE)svar == Qnil) {
val = new_value(); svar = new_value();
lfp[-1] = (VALUE)val; lfp[-1] = (VALUE)svar;
} }
} }
else { else {
val = (struct RValues *)th->local_svar; svar = (struct RValues *)th->local_svar;
if ((VALUE)val == Qnil) { if ((VALUE)svar == Qnil) {
val = new_value(); svar = new_value();
th->local_svar = (VALUE)val; th->local_svar = (VALUE)svar;
} }
} }
switch (cnt) { return svar;
case -1: }
return &val->basic.klass;
static VALUE
lfp_svar_get(rb_thread_t *th, VALUE *lfp, VALUE key)
{
struct RValues *svar = lfp_svar_place(th, lfp);
switch (key) {
case (VALUE)-1:
return svar->basic.klass;
case 0: case 0:
return &val->v1; return svar->v1;
case 1: case 1:
return &val->v2; return svar->v2;
default:{ default: {
VALUE ary; VALUE hash = svar->v3;
if ((ary = val->v3) == Qnil) {
ary = val->v3 = rb_ary_new(); if (hash == Qnil) {
} return Qnil;
if (RARRAY_LEN(ary) <= cnt) { }
rb_ary_store(ary, cnt, Qnil); else {
} return rb_hash_aref(hash, key);
return &RARRAY_PTR(ary)[cnt]; }
}
}
}
static void
lfp_svar_set(rb_thread_t *th, VALUE *lfp, VALUE key, VALUE val)
{
struct RValues *svar = lfp_svar_place(th, lfp);
switch (key) {
case (VALUE)-1:
svar->basic.klass = val;
return;
case 0:
svar->v1 = val;
return;
case 1:
svar->v2 = val;
return;
default: {
VALUE hash = svar->v3;
if (hash == Qnil) {
svar->v3 = hash = rb_hash_new();
}
rb_hash_aset(hash, key, val);
} }
} }
} }

View File

@ -80,16 +80,16 @@ setlocal
*/ */
DEFINE_INSN DEFINE_INSN
getspecial getspecial
(rb_num_t idx, rb_num_t type) (VALUE key, rb_num_t type)
() ()
(VALUE val) (VALUE val)
{ {
if (type == 0) { if (type == 0) {
VALUE *pv = lfp_svar(GET_LFP(), idx); val = lfp_svar_get(th, GET_LFP(), key);
val = *pv;
} }
else { else {
VALUE backref = *lfp_svar(GET_LFP(), 1); VALUE backref = lfp_svar_get(th, GET_LFP(), 1);
if (type & 0x01) { if (type & 0x01) {
switch (type >> 1) { switch (type >> 1) {
case '&': case '&':
@ -121,12 +121,11 @@ getspecial
*/ */
DEFINE_INSN DEFINE_INSN
setspecial setspecial
(rb_num_t idx) (VALUE key)
(VALUE obj) (VALUE obj)
() ()
{ {
VALUE *pv = lfp_svar(GET_LFP(), idx); lfp_svar_set(th, GET_LFP(), key, obj);
*pv = obj;
} }
/** /**
@ -939,7 +938,7 @@ defined
} }
case DEFINED_REF:{ case DEFINED_REF:{
int nth = FIX2INT(obj); int nth = FIX2INT(obj);
VALUE backref = *lfp_svar(GET_LFP(), 1); VALUE backref = lfp_svar_get(th, GET_LFP(), 1);
if (rb_reg_nth_match(nth, backref) != Qnil) { if (rb_reg_nth_match(nth, backref) != Qnil) {
snprintf(buf, 0x10, "$%d", nth); snprintf(buf, 0x10, "$%d", nth);

53
vm.c
View File

@ -651,60 +651,60 @@ vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc,
/* special variable */ /* special variable */
VALUE * VALUE
vm_cfp_svar(rb_control_frame_t *cfp, int cnt) vm_cfp_svar_get(rb_thread_t *th, rb_control_frame_t *cfp, VALUE key)
{ {
while (cfp->pc == 0) { while (cfp->pc == 0) {
cfp++; cfp++;
} }
return lfp_svar(cfp->lfp, cnt); return lfp_svar_get(th, cfp->lfp, key);
} }
static VALUE * void
vm_svar(rb_thread_t *th, int cnt) vm_cfp_svar_set(rb_thread_t *th, rb_control_frame_t *cfp, VALUE key, VALUE val)
{ {
rb_control_frame_t *cfp = th->cfp; while (cfp->pc == 0) {
return vm_cfp_svar(cfp, cnt); cfp++;
}
lfp_svar_set(th, cfp->lfp, key, val);
} }
VALUE * static VALUE
rb_svar(int cnt) vm_svar_get(VALUE key)
{ {
return vm_svar(GET_THREAD(), cnt); rb_thread_t *th = GET_THREAD();
return vm_cfp_svar_get(th, th->cfp, key);
}
static void
vm_svar_set(VALUE key, VALUE val)
{
rb_thread_t *th = GET_THREAD();
vm_cfp_svar_set(th, th->cfp, key, val);
} }
VALUE VALUE
rb_backref_get(void) rb_backref_get(void)
{ {
VALUE *var = rb_svar(1); return vm_svar_get(1);
if (var) {
return *var;
}
return Qnil;
} }
void void
rb_backref_set(VALUE val) rb_backref_set(VALUE val)
{ {
VALUE *var = rb_svar(1); vm_svar_set(1, val);
*var = val;
} }
VALUE VALUE
rb_lastline_get(void) rb_lastline_get(void)
{ {
VALUE *var = rb_svar(0); return vm_svar_get(0);
if (var) {
return *var;
}
return Qnil;
} }
void void
rb_lastline_set(VALUE val) rb_lastline_set(VALUE val)
{ {
VALUE *var = rb_svar(0); vm_svar_set(0, val);
*var = val;
} }
/* backtrace */ /* backtrace */
@ -823,9 +823,8 @@ lfp_set_special_cref(VALUE *lfp, NODE * cref)
old_cref = 0; old_cref = 0;
} }
else { else {
pv = lfp_svar(lfp, -1); old_cref = lfp_svar_get(GET_THREAD(), lfp, -1);
old_cref = (NODE *) * pv; lfp_svar_set(GET_THREAD(), lfp, -1, cref);
*pv = (VALUE)cref;
} }
return old_cref; return old_cref;
} }

View File

@ -110,7 +110,7 @@ vm_compile_from_node(rb_thread_t *th, NODE * node, VALUE file)
} }
else { else {
iseq = rb_iseq_new(node, rb_str_new2("<main>"), file, iseq = rb_iseq_new(node, rb_str_new2("<main>"), file,
Qfalse, ISEQ_TYPE_TOP); Qfalse, ISEQ_TYPE_TOP);
} }
return iseq; return iseq;
} }

View File

@ -211,6 +211,7 @@ struct iseq_compile_data {
struct iseq_compile_data_storage *storage_head; struct iseq_compile_data_storage *storage_head;
struct iseq_compile_data_storage *storage_current; struct iseq_compile_data_storage *storage_current;
int last_line; int last_line;
int flip_cnt;
const rb_compile_option_t *option; const rb_compile_option_t *option;
}; };