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

* 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>
* 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 *lfin = 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),
INT2FIX(0));
iseq_add_mark_object_compile_time(iseq, key);
ADD_INSN2(ret, nd_line(node), getspecial, key, INT2FIX(0));
ADD_INSNL(ret, nd_line(node), branchif, lend);
/* *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);
if (nd_type(node) == NODE_FLIP3) {
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);
}
else {
ADD_INSN1(ret, nd_line(node), setspecial, INT2FIX(node->nd_cnt));
ADD_INSN1(ret, nd_line(node), setspecial, key);
}
/* *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);
ADD_INSNL(ret, nd_line(node), branchunless, ltrue);
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_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);
}
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 */
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);
VALUE stored_self = pcfp->self;
NODE *stored_cref = 0;
NODE **pcref = 0;
rb_block_t block;
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);
}
pcref = (NODE **) vm_cfp_svar(cfp, -1);
stored_cref = *pcref;
*pcref = vm_cref_push(th, under, NOEX_PUBLIC);
stored_cref = vm_cfp_svar_get(th, cfp, -1);
vm_cfp_svar_set(th, cfp, -1, vm_cref_push(th, under, NOEX_PUBLIC));
PUSH_TAG();
if ((state = EXEC_TAG()) == 0) {
@ -1824,7 +1823,7 @@ exec_under(VALUE (*func) (VALUE), VALUE under, VALUE self, VALUE args)
POP_TAG();
/* restore environment */
*pcref = stored_cref;
vm_cfp_svar_set(th, cfp, -1, stored_cref);
pcfp->self = stored_self;
if (state) {

View file

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

View file

@ -747,42 +747,75 @@ new_value(void)
return val;
}
static VALUE *
lfp_svar(VALUE *lfp, int cnt)
static struct RValues *
lfp_svar_place(rb_thread_t *th, VALUE *lfp)
{
struct RValues *val;
rb_thread_t *th = GET_THREAD();
struct RValues *svar;
if (th->local_lfp != lfp) {
val = (struct RValues *)lfp[-1];
if ((VALUE)val == Qnil) {
val = new_value();
lfp[-1] = (VALUE)val;
svar = (struct RValues *)lfp[-1];
if ((VALUE)svar == Qnil) {
svar = new_value();
lfp[-1] = (VALUE)svar;
}
}
else {
val = (struct RValues *)th->local_svar;
if ((VALUE)val == Qnil) {
val = new_value();
th->local_svar = (VALUE)val;
svar = (struct RValues *)th->local_svar;
if ((VALUE)svar == Qnil) {
svar = new_value();
th->local_svar = (VALUE)svar;
}
}
switch (cnt) {
case -1:
return &val->basic.klass;
return svar;
}
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:
return &val->v1;
return svar->v1;
case 1:
return &val->v2;
default:{
VALUE ary;
if ((ary = val->v3) == Qnil) {
ary = val->v3 = rb_ary_new();
}
if (RARRAY_LEN(ary) <= cnt) {
rb_ary_store(ary, cnt, Qnil);
}
return &RARRAY_PTR(ary)[cnt];
return svar->v2;
default: {
VALUE hash = svar->v3;
if (hash == Qnil) {
return Qnil;
}
else {
return rb_hash_aref(hash, key);
}
}
}
}
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
getspecial
(rb_num_t idx, rb_num_t type)
(VALUE key, rb_num_t type)
()
(VALUE val)
{
if (type == 0) {
VALUE *pv = lfp_svar(GET_LFP(), idx);
val = *pv;
val = lfp_svar_get(th, GET_LFP(), key);
}
else {
VALUE backref = *lfp_svar(GET_LFP(), 1);
VALUE backref = lfp_svar_get(th, GET_LFP(), 1);
if (type & 0x01) {
switch (type >> 1) {
case '&':
@ -121,12 +121,11 @@ getspecial
*/
DEFINE_INSN
setspecial
(rb_num_t idx)
(VALUE key)
(VALUE obj)
()
{
VALUE *pv = lfp_svar(GET_LFP(), idx);
*pv = obj;
lfp_svar_set(th, GET_LFP(), key, obj);
}
/**
@ -939,7 +938,7 @@ defined
}
case DEFINED_REF:{
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) {
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 */
VALUE *
vm_cfp_svar(rb_control_frame_t *cfp, int cnt)
VALUE
vm_cfp_svar_get(rb_thread_t *th, rb_control_frame_t *cfp, VALUE key)
{
while (cfp->pc == 0) {
cfp++;
}
return lfp_svar(cfp->lfp, cnt);
return lfp_svar_get(th, cfp->lfp, key);
}
static VALUE *
vm_svar(rb_thread_t *th, int cnt)
void
vm_cfp_svar_set(rb_thread_t *th, rb_control_frame_t *cfp, VALUE key, VALUE val)
{
rb_control_frame_t *cfp = th->cfp;
return vm_cfp_svar(cfp, cnt);
while (cfp->pc == 0) {
cfp++;
}
lfp_svar_set(th, cfp->lfp, key, val);
}
VALUE *
rb_svar(int cnt)
static VALUE
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
rb_backref_get(void)
{
VALUE *var = rb_svar(1);
if (var) {
return *var;
}
return Qnil;
return vm_svar_get(1);
}
void
rb_backref_set(VALUE val)
{
VALUE *var = rb_svar(1);
*var = val;
vm_svar_set(1, val);
}
VALUE
rb_lastline_get(void)
{
VALUE *var = rb_svar(0);
if (var) {
return *var;
}
return Qnil;
return vm_svar_get(0);
}
void
rb_lastline_set(VALUE val)
{
VALUE *var = rb_svar(0);
*var = val;
vm_svar_set(0, val);
}
/* backtrace */
@ -823,9 +823,8 @@ lfp_set_special_cref(VALUE *lfp, NODE * cref)
old_cref = 0;
}
else {
pv = lfp_svar(lfp, -1);
old_cref = (NODE *) * pv;
*pv = (VALUE)cref;
old_cref = lfp_svar_get(GET_THREAD(), lfp, -1);
lfp_svar_set(GET_THREAD(), lfp, -1, cref);
}
return old_cref;
}

View file

@ -110,7 +110,7 @@ vm_compile_from_node(rb_thread_t *th, NODE * node, VALUE file)
}
else {
iseq = rb_iseq_new(node, rb_str_new2("<main>"), file,
Qfalse, ISEQ_TYPE_TOP);
Qfalse, ISEQ_TYPE_TOP);
}
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_current;
int last_line;
int flip_cnt;
const rb_compile_option_t *option;
};