yarv-diff:225
From: ko1 atdot.net
Date: 11 Feb 2006 20:08:55 -0000
Subject: [yarv-diff:225] r382 - trunk
Author: ko1
Date: 2006-02-12 05:08:54 +0900 (Sun, 12 Feb 2006)
New Revision: 382
Modified:
trunk/
trunk/ChangeLog
trunk/eval.c
trunk/eval_intern.h
trunk/eval_load.c
trunk/eval_proc.c
trunk/insnhelper.h
trunk/insns.def
trunk/node.h
trunk/test.rb
trunk/vm.c
trunk/yarvcore.c
trunk/yarvcore.h
Log:
r558@leremita: ko1 | 2006-02-12 05:08:30 +0900
* eval.c, eval_intern.h, eval_load.c, eval_proc.c, node.h,
insnhelper.h, insns.def, vm.c, yarvcore.c, yarvcore.h :
change cref data structure and unify ruby_class and ruby_cbase
and some refoctoring
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:556
+ 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:558
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/ChangeLog 2006-02-11 20:08:54 UTC (rev 382)
@@ -4,6 +4,14 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2006-02-12(Sun) 05:05:02 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * eval.c, eval_intern.h, eval_load.c, eval_proc.c, node.h,
+ insnhelper.h, insns.def, vm.c, yarvcore.c, yarvcore.h :
+ change cref data structure and unify ruby_class and ruby_cbase
+ and some refoctoring
+
+
2006-02-11(Sat) 23:41:11 +0900 Koichi Sasada <ko1 atdot.net>
* insns.def (methoddef) : fix method declaration in method
Modified: trunk/eval.c
===================================================================
--- trunk/eval.c 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/eval.c 2006-02-11 20:08:54 UTC (rev 382)
@@ -397,14 +397,14 @@
rb_mod_nesting(void)
{
VALUE ary = rb_ary_new();
- VALUE cref = ruby_cref();
- int i;
-
- for(i=0; i<RARRAY(cref)->len-1 /* exclude Object */; i++){
- VALUE klass = rb_ary_entry(cref, -(i+1));
+ NODE *cref = ruby_cref();
+
+ while(cref && cref->nd_next){
+ VALUE klass = cref->nd_clss;
if(!NIL_P(klass)){
rb_ary_push(ary, klass);
}
+ cref = cref->nd_next;
}
return ary;
}
@@ -426,21 +426,23 @@
static VALUE
rb_mod_s_constants(void)
{
- VALUE cref = ruby_cref();
+ NODE *cref = ruby_cref();
VALUE klass;
VALUE cbase = 0;
void *data = 0;
int i;
-
- for(i=0; i<RARRAY(cref)->len; i++){
- klass = rb_ary_entry(cref, -(i+1));
+
+ while(cref){
+ klass = cref->nd_clss;
if(!NIL_P(klass)){
- data = rb_mod_const_at(klass, data);
- if(cbase == 0){
+ data = rb_mod_const_at(cref->nd_clss, data);
+ if(!cbase){
cbase = klass;
}
}
+ cref = cref->nd_next;
}
+
if(cbase){
data = rb_mod_const_of(cbase, data);
}
@@ -1913,7 +1915,7 @@
yarv_binding_t *bind = 0;
yarv_thread_t *th = GET_THREAD();
yarv_env_t *env = NULL;
- volatile yarv_stored_klass_t *stored_klass = 0;
+ NODE *stored_cref_stack = 0;
volatile VALUE stored_special_cref_stack = Qundef;
if (file == 0) {
@@ -1930,13 +1932,15 @@
if(CLASS_OF(scope) == cYarvBinding){
GetBindingVal(scope, bind);
envval = bind->env;
- stored_klass = &bind->stored_klass;
+ stored_cref_stack = bind->cref_stack;
}
else if(CLASS_OF(scope) == cYarvProc){
yarv_proc_t *proc;
GetProcVal(scope, proc);
envval = proc->envval;
- stored_klass = &proc->stored_klass;
+ if(proc->special_cref_stack){
+ stored_cref_stack = proc->special_cref_stack;
+ }
}
else{
rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Binding)",
@@ -1966,18 +1970,17 @@
}
/* push tag */
- if(stored_klass){
- stored_special_cref_stack =
- th_restore_stored_klass(th, env->block.lfp, (void *)stored_klass);
+ if(stored_cref_stack){
+ stored_cref_stack =
+ th_set_special_cref(th, env->block.lfp, stored_cref_stack);
}
-
/* kick */
result = th_eval_body(th);
}
POP_TAG();
- if(stored_klass){
- th_restore_restored_klass(th, env->block.lfp, stored_special_cref_stack);
+ if(stored_cref_stack){
+ th_set_special_cref(th, env->block.lfp, stored_cref_stack);
}
if(state){
@@ -2053,15 +2056,15 @@
/* function to call func under the specified class/module context */
static VALUE
-exec_under(VALUE (*func) (VALUE), VALUE under, VALUE cbase, VALUE self,
- VALUE args, VALUE needcref)
+exec_under(VALUE (*func) (VALUE), VALUE under, VALUE self, VALUE args)
{
VALUE val = Qnil; /* OK */
yarv_thread_t *th = GET_THREAD();
- yarv_control_frame_t *pcfp = YARV_PREVIOUS_CONTROL_FRAME(th->cfp);
+ yarv_control_frame_t *cfp = th->cfp;
+ yarv_control_frame_t *pcfp = YARV_PREVIOUS_CONTROL_FRAME(cfp);
VALUE stored_self = pcfp->self;
- VALUE stored_cref = 0;
- VALUE *pcref = 0;
+ NODE *stored_cref = 0;
+ NODE **pcref = 0;
yarv_block_t block;
yarv_block_t *blockptr;
@@ -2071,22 +2074,21 @@
pcfp->self = self;
if((blockptr = GC_GUARDED_PTR_REF(*th->cfp->lfp)) != 0){
/* copy block info */
+ // TODO: why?
block = *blockptr;
block.self = self;
*th->cfp->lfp = GC_GUARDED_PTR(&block);
}
- rb_thread_push_klass(th, under, cbase, NOEX_PUBLIC);
-
- if(cbase && needcref){
- yarv_control_frame_t *cfp = th->cfp;
+ rb_thread_push_cref(th, under, NOEX_PUBLIC);
+ {
while(!YARV_NORMAL_ISEQ_P(cfp->iseq)){
cfp = YARV_PREVIOUS_CONTROL_FRAME(cfp);
}
- pcref = th_cfp_svar(cfp, -1);
+ pcref = (NODE **)th_cfp_svar(cfp, -1);
stored_cref = *pcref;
/* this cause GC error */
- *pcref = rb_ary_dup(th->cref_stack);
+ *pcref = th->cref_stack;
}
PUSH_TAG(PROT_NONE);
@@ -2099,7 +2101,7 @@
if(pcref){
*pcref = stored_cref;
}
- rb_thread_pop_klass(th);
+ rb_thread_pop_cref(th);
pcfp->self = stored_self;
if(state){
@@ -2118,7 +2120,7 @@
static VALUE
yield_under(VALUE under, VALUE self)
{
- return exec_under(yield_under_i, under, 0, self, self, Qfalse);
+ return exec_under(yield_under_i, under, self, self);
}
static VALUE
@@ -2144,7 +2146,7 @@
args[1] = src;
args[2] = (VALUE)file;
args[3] = (VALUE)line;
- return exec_under(eval_under_i, under, under, self, (VALUE)args, Qtrue);
+ return exec_under(eval_under_i, under, self, (VALUE)args);
}
static VALUE
Modified: trunk/eval_intern.h
===================================================================
--- trunk/eval_intern.h 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/eval_intern.h 2006-02-11 20:08:54 UTC (rev 382)
@@ -246,12 +246,11 @@
static int scope_vmode;
#define SCOPE_TEST(f) \
- (FIX2INT(rb_ary_entry(GET_THREAD()->visibility_stack, -1)) == f)
+ (ruby_cref()->nd_visi == (f))
#define SCOPE_SET(f) \
{ \
- yarv_thread_t *th = GET_THREAD(); \
- rb_ary_store(th->visibility_stack, -1, INT2FIX(f)); \
+ ruby_cref()->nd_visi = (f); \
}
struct ruby_env {
@@ -289,14 +288,11 @@
rb_thread_t rb_vm_curr_thread();
VALUE th_compile(yarv_thread_t *th, VALUE str, VALUE file, VALUE line);
-VALUE lfp_get_special_cref(VALUE *lfp);
-VALUE th_get_cref(yarv_thread_t *th, yarv_iseq_t *iseq, yarv_control_frame_t *cfp);
-void th_store_klass(yarv_thread_t *th, VALUE *lfp, yarv_stored_klass_t *sk);
-VALUE th_restore_stored_klass(yarv_thread_t *th, VALUE *lfp, yarv_stored_klass_t *sk);
-void th_restore_restored_klass(yarv_thread_t *th, VALUE *lfp, VALUE scref);
+NODE *th_get_cref(yarv_thread_t *th, yarv_iseq_t *iseq, yarv_control_frame_t *cfp);
+NODE *th_set_special_cref(yarv_thread_t *th, VALUE *lfp, NODE *cref_stack);
-static yarv_control_frame_t *th_get_ruby_level_cfp(yarv_thread_t *th,
- yarv_control_frame_t *cfp)
+static yarv_control_frame_t *
+th_get_ruby_level_cfp(yarv_thread_t *th, yarv_control_frame_t *cfp)
{
yarv_iseq_t *iseq = 0;
while(!YARV_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)){
@@ -312,7 +308,7 @@
return cfp;
}
-static VALUE
+static NODE*
ruby_cref()
{
yarv_thread_t *th = GET_THREAD();
@@ -320,19 +316,12 @@
return th_get_cref(th, cfp->iseq, cfp);
}
+VALUE th_get_cbase(yarv_thread_t *th);
+
static VALUE
ruby_cbase()
{
- VALUE cref = ruby_cref();
- int i;
-
- for(i=0; i<RARRAY(cref)->len; i++){
- VALUE klass = rb_ary_entry(cref, -(i+1));
- if(klass){
- return klass;
- }
- }
- return Qnil;
+ return th_get_cbase(GET_THREAD());
}
#endif /* EVAL_INTERN_H_INCLUDED */
Modified: trunk/eval_load.c
===================================================================
--- trunk/eval_load.c 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/eval_load.c 2006-02-11 20:08:54 UTC (rev 382)
@@ -115,15 +115,9 @@
int state;
volatile ID callee, this_func;
volatile VALUE self = ruby_top_self;
- volatile VALUE stored_klass_stack;
- volatile VALUE stored_cref_stack;
- volatile VALUE stored_visibility_stack;
yarv_thread_t *th = GET_THREAD();
+ NODE *stored_cref_stack = th->cref_stack;
- stored_klass_stack = th->klass_stack;
- stored_cref_stack = th->cref_stack;
- stored_visibility_stack = th->visibility_stack;
-
/* default visibility is private at loading toplevel */
th_klass_init(th);
@@ -152,9 +146,7 @@
POP_TAG();
- th->klass_stack = stored_klass_stack;
- th->cref_stack = stored_cref_stack;
- th->visibility_stack = stored_visibility_stack;
+ th->cref_stack = stored_cref_stack;
if (ruby_nerrs > 0) {
ruby_nerrs = 0;
Modified: trunk/eval_proc.c
===================================================================
--- trunk/eval_proc.c 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/eval_proc.c 2006-02-11 20:08:54 UTC (rev 382)
@@ -69,8 +69,7 @@
GetBindingVal(bindval, bind);
bind->env = th_make_env_object(th, cfp);
-
- th_store_klass(th, cfp->lfp, &bind->stored_klass);
+ bind->cref_stack = ruby_cref();
return bindval;
}
Modified: trunk/insnhelper.h
===================================================================
--- trunk/insnhelper.h 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/insnhelper.h 2006-02-11 20:08:54 UTC (rev 382)
@@ -108,8 +108,6 @@
#define GET_GLOBAL(entry) rb_gvar_get((struct global_entry*)entry)
#define SET_GLOBAL(entry, val) rb_gvar_set((struct global_entry*)entry, val)
-#define GET_KLASS() rb_ary_entry(th->klass_stack, -1)
-
/**********************************************************/
/* deal with values */
/**********************************************************/
@@ -121,6 +119,12 @@
/* deal with control flow 2: method/iterator */
/**********************************************************/
+#define COPY_CREF(c1, c2) { \
+ c1->nd_clss = c2->nd_clss; \
+ c1->nd_visi = c2->nd_visi; \
+ c1->nd_next = c2->nd_next; \
+}
+
/* block */
#define GET_BLOCK_PTR() \
((yarv_block_t *)(GC_GUARDED_PTR_REF(GET_LFP()[0])))
Modified: trunk/insns.def
===================================================================
--- trunk/insns.def 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/insns.def 2006-02-11 20:08:54 UTC (rev 382)
@@ -811,11 +811,12 @@
NODE *newbody;
VALUE klass;
yarv_iseq_t *miseq;
- int noex = th_get_visibility(th);
+ NODE *cref = get_cref(GET_ISEQ(), GET_LFP());
+ int noex = cref->nd_visi;
/* dup */
GetISeqVal(body, miseq);
- rb_ary_replace(miseq->cref_stack, th->cref_stack);
+ COPY_CREF(miseq->cref_stack, cref);
miseq->klass = th_get_cbase(th);
/* make new node */
@@ -831,7 +832,7 @@
klass = CLASS_OF(GET_SELF());
}
else{
- klass = GET_KLASS();
+ klass = cref->nd_clss;
}
rb_add_method(klass, id, newbody, noex);
@@ -882,8 +883,7 @@
}
GetISeqVal(body, siseq);
- rb_ary_replace(siseq->cref_stack, th->cref_stack);
-
+ COPY_CREF(siseq->cref_stack, th->cref_stack);
siseq->klass = CLASS_OF(obj);
newbody = NEW_NODE(YARV_METHOD_NODE, NOEX_PUBLIC, body, 0);
@@ -911,7 +911,7 @@
rb_alias_variable(id1, id2);
}
else{
- klass = GET_KLASS();
+ klass = get_cref(GET_ISEQ(), GET_LFP())->nd_clss;
rb_alias(klass, id1, id2);
}
}
@@ -928,7 +928,7 @@
()
()
{
- VALUE klass = GET_KLASS();
+ VALUE klass = get_cref(GET_ISEQ(), GET_LFP())->nd_clss;
rb_undef(klass, id);
INC_VM_STATE_VERSION();
}
@@ -962,7 +962,7 @@
}
break;
case DEFINED_CVAR:
- klass = GET_KLASS();
+ klass = get_cref(GET_ISEQ(), GET_LFP())->nd_clss;
if(rb_cvar_defined(klass, SYM2ID(obj))){
expr_type = "class variable";
}
@@ -1137,8 +1137,8 @@
RESTORE_REGS();
/* others */
- rb_thread_push_klass(th, klass, klass, NOEX_PUBLIC);
- rb_ary_replace(klass_iseq->cref_stack, th->cref_stack);
+ rb_thread_push_cref(th, klass, NOEX_PUBLIC);
+ COPY_CREF(klass_iseq->cref_stack, th->cref_stack);
INC_VM_STATE_VERSION();
NEXT_INSN();
@@ -1170,8 +1170,8 @@
klass_iseq->local_size, 0, 0);
RESTORE_REGS();
/* others */
- rb_thread_push_klass(th, klass, klass, NOEX_PUBLIC);
- rb_ary_replace(klass_iseq->cref_stack, th->cref_stack);
+ rb_thread_push_cref(th, klass, NOEX_PUBLIC);
+ COPY_CREF(klass_iseq->cref_stack, th->cref_stack);
INC_VM_STATE_VERSION();
NEXT_INSN();
@@ -1221,9 +1221,9 @@
RESTORE_REGS();
/* others */
- rb_thread_push_klass(th, module, module, NOEX_PUBLIC);
- rb_ary_replace(module_iseq->cref_stack, th->cref_stack);
-
+ rb_thread_push_cref(th, module, NOEX_PUBLIC);
+ COPY_CREF(module_iseq->cref_stack, th->cref_stack);
+
INC_VM_STATE_VERSION();
NEXT_INSN();
}
@@ -1239,7 +1239,7 @@
()
()
{
- rb_thread_pop_klass(th);
+ rb_thread_pop_cref(th);
}
Modified: trunk/node.h
===================================================================
--- trunk/node.h 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/node.h 2006-02-11 20:08:54 UTC (rev 382)
@@ -238,6 +238,8 @@
#define nd_tag u1.id
#define nd_tval u2.value
+#define nd_visi u2.argc
+
#define NEW_NODE(t,a0,a1,a2) rb_node_newnode((t),(VALUE)(a0),(VALUE)(a1),(VALUE)(a2))
#define NEW_METHOD(n,x,v) NEW_NODE(NODE_METHOD,x,n,v)
Modified: trunk/test.rb
===================================================================
--- trunk/test.rb 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/test.rb 2006-02-11 20:08:54 UTC (rev 382)
@@ -1,3 +1,46 @@
+ class C
+ $b = binding
+ end
+ eval %q{
+ def m
+ :ok
+ end
+ }, $b
+ p C.new.m
+__END__
+
+class C
+ def m
+ yield
+ end
+ end
+
+ class D < C
+ def m
+ super{
+ :D
+ }
+ end
+ end
+
+p D.new.m{
+ :top
+ }
+__END__
+
+class C
+ Const = 1
+ def m
+ 1.times{
+ p Const
+ }
+ end
+end
+
+C.new.m
+
+__END__
+
class A
def m
def a
Modified: trunk/vm.c
===================================================================
--- trunk/vm.c 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/vm.c 2006-02-11 20:08:54 UTC (rev 382)
@@ -31,6 +31,8 @@
yarv_block_t *block, int argc, VALUE *argv);
VALUE th_eval_body(yarv_thread_t *th);
+static NODE *lfp_get_special_cref(VALUE *lfp);
+static NODE *lfp_set_special_cref(VALUE *lfp, NODE *cref);
#if OPT_STACK_CACHING
static VALUE yarv_finish_insn_seq[1] = {BIN(finish_SC_ax_ax)};
@@ -374,7 +376,7 @@
proc->block.proc = procval;
proc->envval = envval;
- th_store_klass(th, proc->block.lfp, &proc->stored_klass);
+ proc->special_cref_stack = lfp_get_special_cref(block->lfp);
return procval;
}
@@ -612,11 +614,12 @@
{
VALUE val = Qundef;
int state;
- volatile yarv_stored_klass_t sk;
- volatile VALUE stored_special_cref_stack;
+ NODE* stored_special_cref_stack = 0;
- stored_special_cref_stack =
- th_restore_stored_klass(th, proc->block.lfp, &proc->stored_klass);
+ if(proc->special_cref_stack){
+ stored_special_cref_stack =
+ lfp_set_special_cref(proc->block.lfp, proc->special_cref_stack);
+ }
TH_PUSH_TAG(th);
if((state = EXEC_TAG()) == 0){
@@ -630,10 +633,12 @@
else{
// TODO
}
-
- th_restore_restored_klass(th, proc->block.lfp, stored_special_cref_stack);
TH_POP_TAG();
+ if(stored_special_cref_stack){
+ lfp_set_special_cref(proc->block.lfp, stored_special_cref_stack);
+ }
+
if(state){
JUMP_TAG(state);
}
@@ -803,40 +808,46 @@
*/
-VALUE
+static NODE *
lfp_get_special_cref(VALUE *lfp)
{
NODE *node;
if(((VALUE)(node = (NODE*)lfp[-1])) != Qnil &&
node->nd_file){
- return (VALUE)node->nd_file;
+ return (NODE *)node->nd_file;
}
else{
return 0;
}
}
-static VALUE
-lfp_set_special_cref(VALUE *lfp, VALUE cref)
+static NODE *
+lfp_set_special_cref(VALUE *lfp, NODE *cref)
{
NODE *node = (NODE*)lfp[-1];
VALUE *pv;
- VALUE scref;
+ NODE *old_cref;
if(cref == 0 && ((VALUE)node == Qnil || node->nd_file == 0)){
- scref = 0;
+ old_cref = 0;
}
else{
pv = lfp_svar(lfp, -1);
- scref = *pv;
- *pv = cref;
+ old_cref = (NODE *)*pv;
+ *pv = (VALUE)cref;
}
- return scref;
+ return old_cref;
}
-static VALUE
+NODE *
+th_set_special_cref(yarv_thread_t *th, VALUE *lfp, NODE *cref_stack)
+{
+ return lfp_set_special_cref(lfp, cref_stack);
+}
+
+static NODE*
get_cref(yarv_iseq_t *iseq, VALUE *lfp)
{
- VALUE cref;
+ NODE *cref;
if((cref = lfp_get_special_cref(lfp)) != 0){
/* */
}
@@ -849,22 +860,23 @@
return cref;
}
-VALUE
+NODE *
th_get_cref(yarv_thread_t *th, yarv_iseq_t *iseq, yarv_control_frame_t *cfp)
{
return get_cref(iseq, cfp->lfp);
}
-static VALUE
+VALUE
th_get_cbase(yarv_thread_t *th)
{
int i;
- VALUE cref = th->cref_stack;
+ NODE* cref = th->cref_stack;
VALUE klass = Qundef;
- for(i = 0; i < RARRAY(cref)->len; i++){
- if((klass = rb_ary_entry(cref, -(1+i))) != 0){
+ while(cref){
+ if((klass = cref->nd_clss) != 0){
break;
}
+ cref = cref->nd_next;
}
return klass;
}
@@ -872,49 +884,22 @@
static int
th_get_visibility(yarv_thread_t *th)
{
- return FIX2INT(rb_ary_entry(th->visibility_stack, -1));
+ return th->cref_stack->nd_visi;
}
void
-rb_thread_push_klass(yarv_thread_t *th, VALUE klass, VALUE cref, int noex)
+rb_thread_push_cref(yarv_thread_t *th, VALUE klass, int noex)
{
- rb_ary_push(th->klass_stack, klass);
- rb_ary_push(th->cref_stack, cref);
- rb_ary_push(th->visibility_stack, INT2FIX(noex));
+ NODE *cref = th->cref_stack;
+ th->cref_stack = NEW_NODE(NODE_BLOCK, klass, noex, cref);
}
void
-rb_thread_pop_klass(yarv_thread_t *th)
-{
- rb_ary_pop(th->klass_stack);
- rb_ary_pop(th->cref_stack);
- rb_ary_pop(th->visibility_stack);
+rb_thread_pop_cref(yarv_thread_t *th){
+ th->cref_stack = th->cref_stack->nd_next;
}
-void
-th_store_klass(yarv_thread_t *th, VALUE *lfp, yarv_stored_klass_t *sk)
-{
- sk->klass = rb_ary_entry(th->klass_stack, -1);
- sk->visibility = rb_ary_entry(th->visibility_stack, -1);
- sk->cref_stack = lfp_get_special_cref(lfp);
-}
-VALUE
-th_restore_stored_klass(yarv_thread_t *th, VALUE *lfp, yarv_stored_klass_t *sk)
-{
- rb_ary_push(th->klass_stack, sk->klass);
- rb_ary_push(th->visibility_stack, sk->visibility);
- return lfp_set_special_cref(lfp, sk->cref_stack);
-}
-
-void
-th_restore_restored_klass(yarv_thread_t *th, VALUE *lfp, VALUE scref)
-{
- rb_ary_pop(th->klass_stack);
- rb_ary_pop(th->visibility_stack);
- lfp_set_special_cref(lfp, scref);
-}
-
EVALBODY_HELPER_FUNCTION VALUE
eval_get_ev_const(yarv_thread_t *th, yarv_iseq_t *iseq,
VALUE klass, ID id, int is_defined)
@@ -923,11 +908,13 @@
if(klass == Qnil){
/* in current lexical scope */
- VALUE cref = get_cref(iseq, th->cfp->lfp);
+ NODE *cref = get_cref(iseq, th->cfp->lfp);
int i;
- for(i = 0; i<RARRAY(cref)->len; i++){
- klass = rb_ary_entry(cref, -(1+i));
+ while(cref && cref->nd_next){
+ klass = cref->nd_clss;
+ cref = cref->nd_next;
+
if(klass == 0){
continue;
}
@@ -958,7 +945,7 @@
}
}
}
- klass = rb_ary_entry(cref, -1);
+ klass = cref->nd_clss;
if(is_defined){
return rb_const_defined(klass, id);
}
@@ -987,17 +974,19 @@
EVALBODY_HELPER_FUNCTION VALUE
eval_get_cvar_base(yarv_thread_t *th, yarv_iseq_t *iseq)
{
- VALUE cref = get_cref(iseq, th->cfp->lfp);
+ NODE *cref = get_cref(iseq, th->cfp->lfp);
VALUE klass = Qnil;
- int i;
-
- for(i=0; i<RARRAY(cref)->len; i++){
- klass = rb_ary_entry(cref, -(i+1));
+
+ while(cref){
+ klass = cref->nd_clss;
+ cref = cref->nd_next;
+
if(cref == 0){
continue;
}
- if(NIL_P(cref) || FL_TEST(klass, FL_SINGLETON)){
- if(RARRAY(cref)->len == i+1){
+
+ if(NIL_P(klass) || FL_TEST(klass, FL_SINGLETON)){
+ if(cref->nd_next == 0){
rb_warn("class variable access from toplevel singleton method");
}
continue;
@@ -1473,7 +1462,7 @@
else{
/* pop cref */
if(cfp->iseq->type == ISEQ_TYPE_CLASS){
- rb_thread_pop_klass(th);
+ rb_thread_pop_cref(th);
}
th->cfp++;
Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/yarvcore.c 2006-02-11 20:08:54 UTC (rev 382)
@@ -397,7 +397,7 @@
MARK_UNLESS_NULL(iseq->iseq_mark_ary);
MARK_UNLESS_NULL(iseq->name);
MARK_UNLESS_NULL(iseq->file_name);
- MARK_UNLESS_NULL(iseq->cref_stack);
+ MARK_UNLESS_NULL((VALUE)iseq->cref_stack);
MARK_UNLESS_NULL(iseq->klass);
MARK_UNLESS_NULL(iseq->catch_table_ary);
MARK_UNLESS_NULL((VALUE)iseq->node);
@@ -441,11 +441,11 @@
/* set class nest stack */
if(type == ISEQ_TYPE_TOP){
- iseq->cref_stack = rb_ary_push(rb_ary_new(), rb_cObject);
+ iseq->cref_stack = NEW_BLOCK(rb_cObject);
}
else if(type == ISEQ_TYPE_METHOD ||
type == ISEQ_TYPE_CLASS){
- iseq->cref_stack = rb_ary_new();
+ iseq->cref_stack = NEW_BLOCK(0);
}
else if(parent){
yarv_iseq_t *piseq;
@@ -653,9 +653,7 @@
}
/* mark ruby objects */
- MARK_UNLESS_NULL(th->klass_stack);
- MARK_UNLESS_NULL(th->cref_stack);
- MARK_UNLESS_NULL(th->visibility_stack);
+ MARK_UNLESS_NULL((VALUE)th->cref_stack);
MARK_UNLESS_NULL(th->first_proc);
MARK_UNLESS_NULL(th->first_args);
@@ -715,9 +713,8 @@
void
th_klass_init(yarv_thread_t *th)
{
- th->klass_stack = rb_ary_push(rb_ary_new(), rb_cObject);
- th->cref_stack = rb_ary_push(rb_ary_new(), rb_cObject);
- th->visibility_stack = rb_ary_push(rb_ary_new(), INT2FIX(NOEX_PRIVATE));
+ th->cref_stack = NEW_BLOCK(rb_cObject);
+ th->cref_stack->nd_visi = NOEX_PRIVATE;
}
static void
@@ -841,8 +838,7 @@
proc = ptr;
MARK_UNLESS_NULL(proc->envval);
MARK_UNLESS_NULL(proc->blockprocval);
- MARK_UNLESS_NULL(proc->stored_klass.klass);
- MARK_UNLESS_NULL(proc->stored_klass.cref_stack);
+ MARK_UNLESS_NULL((VALUE)proc->special_cref_stack);
if(proc->block.iseq && YARV_IFUNC_P(proc->block.iseq)){
MARK_UNLESS_NULL((VALUE)(proc->block.iseq));
}
@@ -942,8 +938,7 @@
if(ptr){
bind = ptr;
MARK_UNLESS_NULL(bind->env);
- MARK_UNLESS_NULL(bind->stored_klass.klass);
- MARK_UNLESS_NULL(bind->stored_klass.cref_stack);
+ MARK_UNLESS_NULL((VALUE)bind->cref_stack);
}
MARK_REPORT("<- binding", 0);
}
Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h 2006-02-11 14:43:26 UTC (rev 381)
+++ trunk/yarvcore.h 2006-02-11 20:08:54 UTC (rev 382)
@@ -249,7 +249,7 @@
int stack_max;
/* klass/module nest information stack (cref) */
- VALUE cref_stack; /* Array */
+ NODE *cref_stack;
VALUE klass;
/* catch table */
@@ -364,9 +364,7 @@
yarv_block_t *passed_block;
/* klass/module nest information stack */
- VALUE klass_stack;
- VALUE cref_stack;
- VALUE visibility_stack;
+ NODE *cref_stack;
/* passed via parse.y, eval.c (rb_scope_setup_local_tbl) */
ID *top_local_tbl;
@@ -443,20 +441,14 @@
Data_Get_Struct(obj, yarv_proc_t, iobj)
typedef struct{
- VALUE klass;
- VALUE visibility;
- VALUE cref_stack; /* special cref stack */
-} yarv_stored_klass_t;
-
-typedef struct{
yarv_block_t block;
- yarv_stored_klass_t stored_klass;
-
+
VALUE envval; /* for GC mark */
VALUE blockprocval;
int safe_level;
int is_lambda;
- int visibility;
+
+ NODE *special_cref_stack;
} yarv_proc_t;
#define GetEnvVal(obj, iobj) \
@@ -475,7 +467,7 @@
typedef struct{
VALUE env;
- yarv_stored_klass_t stored_klass;
+ NODE *cref_stack;
} yarv_binding_t;
@@ -549,14 +541,9 @@
#define SDR() vm_stack_dump_raw(GET_THREAD(), GET_THREAD()->cfp)
#define SDR2(cfp) vm_stack_dump_raw(GET_THREAD(), (cfp))
-void rb_thread_push_klass(yarv_thread_t *th, VALUE klass, VALUE cref, int noex);
-void rb_thread_pop_klass(yarv_thread_t *th);
+void rb_thread_push_cref(yarv_thread_t *th, VALUE klass, int noex);
+void rb_thread_pop_cref(yarv_thread_t *th);
-void rb_thread_store_klass(yarv_thread_t *th, yarv_control_frame_t *cfp,
- yarv_stored_klass_t *ks);
-void rb_thread_restore_klass(yarv_thread_t *th, yarv_control_frame_t *cfp,
- yarv_stored_klass_t *ks);
-
/* for thread */
#include "yarv.h"
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml