summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-10 08:04:52 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-10 08:04:52 +0000
commita6e3d19f3ac344613da68dff705fb411d9120d63 (patch)
tree7f16e466dd79c5750c740d3aac7a4704b924885e
parentd4662d49d925484f673969693f47cd4ac4338206 (diff)
* 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
-rw-r--r--ChangeLog13
-rw-r--r--compile.c13
-rw-r--r--eval.c11
-rw-r--r--include/ruby/intern.h1
-rw-r--r--insnhelper.ci85
-rw-r--r--insns.def15
-rw-r--r--vm.c53
-rw-r--r--yarvcore.c2
-rw-r--r--yarvcore.h1
9 files changed, 120 insertions, 74 deletions
diff --git a/ChangeLog b/ChangeLog
index 0d91856183..3f624ef92c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/compile.c b/compile.c
index 38c6e42d12..a2cef37613 100644
--- a/compile.c
+++ b/compile.c
@@ -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);
diff --git a/eval.c b/eval.c
index 6c3669054b..6edef41ff5 100644
--- a/eval.c
+++ b/eval.c
@@ -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) {
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 77663fd5f0..1e45f2d977 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -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);
diff --git a/insnhelper.ci b/insnhelper.ci
index 2fe540d1cb..2b33e6b1d6 100644
--- a/insnhelper.ci
+++ b/insnhelper.ci
@@ -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);
}
}
}
diff --git a/insns.def b/insns.def
index e1b28766cb..be67ab09e4 100644
--- a/insns.def
+++ b/insns.def
@@ -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);
diff --git a/vm.c b/vm.c
index e8507743fe..a952f5e029 100644
--- a/vm.c
+++ b/vm.c
@@ -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;
}
diff --git a/yarvcore.c b/yarvcore.c
index 72755198d8..194ca1a586 100644
--- a/yarvcore.c
+++ b/yarvcore.c
@@ -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;
}
diff --git a/yarvcore.h b/yarvcore.h
index 4931900848..d0ce781dd8 100644
--- a/yarvcore.h
+++ b/yarvcore.h
@@ -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;
};