[前][次][番号順一覧][スレッド一覧][生データ]

yarv-diff:194

From: ko1 atdot.net
Date: 3 Jan 2006 14:10:16 -0000
Subject: [yarv-diff:194] r352 - in trunk: . benchmark

Author: ko1
Date: 2006-01-03 23:10:15 +0900 (Tue, 03 Jan 2006)
New Revision: 352

Modified:
   trunk/ChangeLog
   trunk/benchmark/bmx_temp.rb
   trunk/disasm.c
   trunk/eval.c
   trunk/eval_intern.h
   trunk/eval_proc.c
   trunk/eval_thread.c
   trunk/gc.c
   trunk/insnhelper.h
   trunk/insns.def
   trunk/test.rb
   trunk/vm.c
   trunk/vm_macro.def
   trunk/yarvcore.c
   trunk/yarvcore.h
Log:
	* disasm.c (insn_operand_intern) : fix to add child iseq

	* eval.c, gc.c : remove obsolete static variables (ruby_scope,
	ruby_dyna_vars, ruby_frame)

	* eval.c (rb_mod_s_constants) : use ruby_cref()

	* eval.c (eval) : use th_restore_klass()

	* eval_proc.c (rb_f_binding) : use th_store_klass()

	* insns.def (concatarray) : fix insn ([expr, *nil] => [expr])

	* vm.c (th_set_env), insnhelper.h : remove macro

	* vm.c (eval_get_cvar_base) : use get_cref

	* vm.c (th_make_proc) : use th_store_klass()

	* vm_macro.def (macro_eval_invoke_func) : fix option args size

	* vm_macro.def (macro_eval_invoke_func) : raise stack overflow error

	* yarvcore.h : add yarv_stored_klass_t type



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/ChangeLog	2006-01-03 14:10:15 UTC (rev 352)
@@ -4,6 +4,36 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2006-01-03(Tue) 22:25:04 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* disasm.c (insn_operand_intern) : fix to add child iseq
+
+	* eval.c, gc.c : remove obsolete static variables (ruby_scope,
+	ruby_dyna_vars, ruby_frame)
+
+	* eval.c (rb_mod_s_constants) : use ruby_cref()
+
+	* eval.c (eval) : use th_restore_klass()
+
+	* eval_proc.c (rb_f_binding) : use th_store_klass()
+
+	* insns.def (concatarray) : fix insn ([expr, *nil] => [expr])
+
+	* vm.c (th_set_env), insnhelper.h : remove macro
+
+	* vm.c (eval_get_cvar_base) : use get_cref
+
+	* vm.c (th_make_proc) : use th_store_klass()
+
+	* vm_macro.def (macro_eval_invoke_func) : fix option args size
+
+	* vm_macro.def (macro_eval_invoke_func) : raise stack overflow error
+
+	* yarvcore.h : add yarv_stored_klass_t type
+
+	* yarvcore.c : fix mark functions around yarv_stored_klass_t
+
+
 2006-01-01(Sun) 05:14:26 +0900  Minero Aoki  <aamine loveruby.net>
 
 	* lib/benchmark.rb: new file (imported from original ruby, rev

Modified: trunk/benchmark/bmx_temp.rb
===================================================================
--- trunk/benchmark/bmx_temp.rb	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/benchmark/bmx_temp.rb	2006-01-03 14:10:15 UTC (rev 352)
@@ -1,4 +1,9 @@
-require 'erb'
-50000.times{|e|
-  a = ERB.new('<%= e %>').result(binding)
+
+$pr = proc{}
+def m
+  $pr.call
+end
+
+1000000.times{|e|
+  m
 }

Modified: trunk/disasm.c
===================================================================
--- trunk/disasm.c	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/disasm.c	2006-01-03 14:10:15 UTC (rev 352)
@@ -96,6 +96,9 @@
     op = ID2SYM(op);
   case TS_VALUE: /* VALUE */
     ret = rb_inspect(op);
+    if(CLASS_OF(op) == cYarvISeq){
+      rb_ary_push(child, op);
+    }
     break;
 
   case TS_BLOCKISEQ: /* block */
@@ -230,7 +233,6 @@
   size = iseqdat->size;
 
   rb_str_cat2  (str, "== disasm: ");
-  // dp(iseq_inspect(self));
   
   rb_str_concat(str, iseq_inspect(self));
   for(i=RSTRING(str)->len;i<72;i++){
@@ -311,9 +313,10 @@
   for(i=0; i<size; ){
     i+= iseq_disasm_insn(str, iseq, i, iseqdat, child);
   }
-  
+
   for(i=0; i<RARRAY(child)->len; i++){
-    rb_str_concat(str, iseq_disasm(RARRAY(child)->ptr[i]));
+    VALUE isv = rb_ary_entry(child, i);
+    rb_str_concat(str, iseq_disasm(isv));
   }
 
   return str;

Modified: trunk/eval.c
===================================================================
--- trunk/eval.c	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/eval.c	2006-01-03 14:10:15 UTC (rev 352)
@@ -14,11 +14,6 @@
 
 #include "eval_intern.h"
 
-/* for gc.c */
-struct SCOPE *ruby_scope = 0;
-struct RVarmap *ruby_dyna_vars = 0;
-struct FRAME *ruby_frame = 0;
-
 VALUE rb_cProc;
 VALUE rb_cBinding;
 
@@ -441,7 +436,7 @@
 static VALUE
 rb_mod_s_constants(void)
 {
-  VALUE cref = GET_THREAD()->cref_stack;
+  VALUE cref = ruby_cref();
   VALUE klass;
   VALUE cbase = 0;
   void *data = 0;
@@ -1903,9 +1898,13 @@
   volatile int safe = ruby_safe_level;
   int state;
   VALUE result;
+  VALUE envval;
   yarv_binding_t *bind = 0;
   yarv_thread_t *th = GET_THREAD();
-
+  yarv_stored_klass_t *stored_klass = 0;
+  VALUE stored_special_cref_stack;
+  yarv_env_t *env;
+  
   if (file == 0) {
     ruby_set_current_source();
     file = ruby_sourcefile;
@@ -1918,21 +1917,22 @@
     VALUE iseqval;
 
     if(scope != Qnil){
-      yarv_env_t *env;
       if(CLASS_OF(scope) == cYarvBinding){
         GetBindingVal(scope, bind);
-        scope = bind->env;
+        envval = bind->env;
+        stored_klass = &bind->stored_klass;
       }
       else if(CLASS_OF(scope) == cYarvProc){
         yarv_proc_t *proc;
         GetProcVal(scope, proc);
-        scope = proc->envval;
+        envval = proc->envval;
+        stored_klass = &proc->stored_klass;
       }
       else{
         rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Binding)",
                  rb_obj_classname(scope));
       }
-      GetEnvVal(scope, env);
+      GetEnvVal(envval, env);
       th->base_block = &env->block;
     }
     else{
@@ -1955,25 +1955,21 @@
       bind->env = th_make_env_object(th, th->cfp);
     }
 
-    if(bind){
-      rb_thread_push_klass(th, bind->klass, 0, bind->visibility);
-      if(bind->cref_stack){
-        /* TODO: */
-      }
+    /* push tag */
+    if(stored_klass){
+      stored_special_cref_stack =
+        th_restore_stored_klass(th, env->block.lfp, stored_klass);
     }
     
     /* kick */
     result = th_eval_body(th);
   }
   POP_TAG();
-  
-  if(bind){
-    rb_thread_pop_klass(th);
-    if(bind->cref_stack){
-      /* TODO: */
-    }
+
+  if(stored_klass){
+    th_restore_restored_klass(th, env->block.lfp, stored_special_cref_stack);
   }
-  
+
   if(state){
     if(state == TAG_RAISE){
       if(strcmp(file, "(eval)") == 0){
@@ -2071,7 +2067,7 @@
   }
 
   rb_thread_push_klass(th, under, cbase, NOEX_PUBLIC);
-  
+
   if(cbase && needcref){
     yarv_control_frame_t *cfp = th->cfp;
     while(!YARV_NORMAL_ISEQ_P(cfp->iseq)){
@@ -2094,7 +2090,7 @@
   }
   rb_thread_pop_klass(th);
   pcfp->self = stored_self;
-  
+
   if(state){
     JUMP_TAG(state);
   }
@@ -2165,8 +2161,7 @@
       }
       if (argc > 3) {
         rb_raise(rb_eArgError, "wrong number of arguments: %s(src) or %s{..}",
-                 rb_id2name(ruby_frame->callee),
-                 rb_id2name(ruby_frame->callee));
+                 rb_frame_callee(), rb_frame_callee());
       }
       if (argc > 2) line = NUM2INT(argv[2]);
       if (argc > 1) {

Modified: trunk/eval_intern.h
===================================================================
--- trunk/eval_intern.h	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/eval_intern.h	2006-01-03 14:10:15 UTC (rev 352)
@@ -288,11 +288,14 @@
 rb_thread_t rb_vm_curr_thread();
 VALUE th_compile(yarv_thread_t *th, VALUE str, VALUE file, VALUE line);
 
-VALUE th_get_special_cref(yarv_thread_t *th, yarv_control_frame_t *cfp);
+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);
 
-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)){

Modified: trunk/eval_proc.c
===================================================================
--- trunk/eval_proc.c	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/eval_proc.c	2006-01-03 14:10:15 UTC (rev 352)
@@ -70,9 +70,7 @@
   GetBindingVal(bindval, bind);
   bind->env = th_make_env_object(th, cfp);
 
-  bind->klass = rb_ary_entry(th->klass_stack, -1);
-  bind->visibility = rb_ary_entry(th->visibility_stack, -1);
-  bind->cref_stack = th_get_special_cref(th, cfp);
+  th_store_klass(th, cfp->lfp, &bind->stored_klass);
   return bindval;
 }
 

Modified: trunk/eval_thread.c
===================================================================
--- trunk/eval_thread.c	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/eval_thread.c	2006-01-03 14:10:15 UTC (rev 352)
@@ -744,16 +744,14 @@
 }
 
 void
-rb_thread_wait_fd(fd)
-    int fd;
+rb_thread_wait_fd(int fd)
 {
-  // TODO: fix me
+  
   return;
 }
 
 int
-rb_thread_fd_writable(fd)
-    int fd;
+rb_thread_fd_writable(int fd)
 {
   // TODO: fix me
   return Qfalse;

Modified: trunk/gc.c
===================================================================
--- trunk/gc.c	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/gc.c	2006-01-03 14:10:15 UTC (rev 352)
@@ -1286,19 +1286,6 @@
 
   init_mark_stack();
 
-  /* mark frame stack */
-  for (frame = ruby_frame; frame; frame = frame->prev) {
-    rb_gc_mark_frame(frame);
-    if (frame->tmp) {
-      struct FRAME *tmp = frame->tmp;
-      while (tmp) {
-        rb_gc_mark_frame(tmp);
-        tmp = tmp->prev;
-      }
-    }
-  }
-  gc_mark((VALUE)ruby_scope, 0);
-  gc_mark((VALUE)ruby_dyna_vars, 0);
   if (finalizer_table) {
     mark_tbl(finalizer_table, 0);
   }

Modified: trunk/insnhelper.h
===================================================================
--- trunk/insnhelper.h	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/insnhelper.h	2006-01-03 14:10:15 UTC (rev 352)
@@ -18,24 +18,8 @@
  * deal with control frame pointer
  */
 
-#define PUSH_CONTROL_STACK_FRAME(th, pc_, sp_, bp_, iseq_, magic_, self_, lfp_, dfp_) \
-{                              \
-  yarv_control_frame_t *cfp;   \
-  (th)->cfp--;                 \
-  cfp        = (th)->cfp;      \
-  cfp->pc    = (pc_);          \
-  cfp->sp    = (sp_);          \
-  cfp->bp    = (bp_);          \
-  cfp->iseq  = (iseq_);        \
-  cfp->magic = (magic_);       \
-  cfp->self  = (self_);        \
-  cfp->lfp   = (lfp_);         \
-  cfp->dfp   = (dfp_);         \
-}
-
 #define POP_CONTROL_STACK_FRAME(th) INC_CFP()
 
-
 /**********************************************************/
 /* deal with stack                                        */
 /**********************************************************/

Modified: trunk/insns.def
===================================================================
--- trunk/insns.def	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/insns.def	2006-01-03 14:10:15 UTC (rev 352)
@@ -568,10 +568,9 @@
 
   if(ary2 == Qnil){
     ary = ary1;
-    rb_ary_push(ary, Qnil);
   }
   else{
-    if(CLASS_OF(ary2) != rb_cArray){
+    if(TYPE(ary2) != T_ARRAY){
       ary2 = rb_Array(ary2);
     }
     ary = rb_ary_concat(ary1, ary2);
@@ -881,7 +880,7 @@
 {
   VALUE klass;
   NODE *newbody;
-  yarv_iseq_t *iseq;
+  yarv_iseq_t *siseq;
   int noex = NOEX_PUBLIC;
 
   if(FIXNUM_P(obj) || SYMBOL_P(obj)){
@@ -905,10 +904,10 @@
     }
   }
   
-  GetISeqVal(body, iseq);
-  rb_ary_replace(iseq->cref_stack, th->cref_stack);
+  GetISeqVal(body, siseq);
+  rb_ary_replace(siseq->cref_stack, th->cref_stack);
   
-  iseq->klass = CLASS_OF(obj);
+  siseq->klass = CLASS_OF(obj);
   
   newbody = NEW_NODE(YARV_METHOD_NODE, NOEX_PUBLIC, body, 0);
 
@@ -1084,7 +1083,7 @@
   yarv_iseq_t *klass_iseq;
   int i;
   VALUE klass;
-  
+
   if(super == Qnil){
     super = rb_cObject;
   }
@@ -1121,11 +1120,11 @@
              klass_iseq->iseq_encoded, GET_SP(), 0,
              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);
-  
+
   INC_VM_STATE_VERSION();
   NEXT_INSN();
 }

Modified: trunk/test.rb
===================================================================
--- trunk/test.rb	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/test.rb	2006-01-03 14:10:15 UTC (rev 352)
@@ -1,166 +1,95 @@
 
-
-__END__
-b = proc{
-  a = 1
-  binding
-}.call
-a = 3
-
-#eval('p a', b)
-
-__END__
-
-
 def m
-  b = proc{
-    a = 0x1000
-    binding
-  }.call
-  a = 0x2000
-  p eval("x=1; a", b)
+  m
 end
 
-m
-
-__END__
-
-
-require 'fileutils'
-__END__
-class C
-  def method_missing *args, &b
-    b.call(args)
-  end
+begin
+  m
+rescue SystemStackError
+  retry
 end
 
-C.new.foo(1){|args|
-  p args
-}
 
-__END__
 
-10000.times{
-  Thread.new {}
-  Thread.pass
-}
 
 __END__
 
-p eval('a', $b)
-
-
+class A
+        class B
+          Const = 1
+          class C
+p            (1..2).map{
+              Const
+            }
+          end
+        end
+      end
 __END__
-Const = :top
+
+Const = :Top
 class C
   Const = :C
-  def m
-    binding
-  end
+  $pr = proc{
+    def m
+      p Const
+    end
+  }
 end
 
-eval('Const', C.new.m)
-__END__
-$ans = []
-      def m
-        $b = binding
-      end
-      m
-      $ans << eval(%q{
-        $ans << eval(%q{
-          a
-        }, $b)
-        a = 1
-      }, $b)
-p      $ans
+$pr.call
+C.new.m
 
+
 __END__
 
 class C
-  @@cvar = 1
+  $pr = proc{
+    class D
+    end
+  }
 end
 
-C.new.instance_eval %{
-  p @@cvar
-}
-__END__
-class Fixnum
-  @@cvar = 1
-end
+$pr.call
 
-1.instance_eval %{
-  p @@cvar
-}
+p C::D
 __END__
 
-class Base
-  def initialize(p1, p2 = 1)
-    p [p1, p2]
+C.module_eval %{
+  class D
+    class E
+    end
   end
-end
-
-class Derived < Base
-  def initialize(p1, p2 = 2)
-    super
-  end
-end
-
-Derived.new(0)
+}
+p C::D::E
 __END__
-require 'erb'
 
-ERB.new(<<EOS).run(binding)
-<% 3.times do |n| %>
-% n = 0
-* <%= n%>
-<% end %>
-EOS
 
-__END__
-
-
 class C
+  $pr = lambda{
+    def m
+      p :m
+    end
+  }
 end
 
 class D
-  C.class_eval{
-    def m1
-      p :OK
-    end
-    eval %{
-      def m2
-        p :OK
-      end
-    }
-  }
+  $pr.call
 end
 
-C.new.m1 #=> :OK
-#D.new.m2 #=> :OK
-C.new.m2 #=> NoMethodError
+p Module.nesting
+D.new.m
 
+
 __END__
-class C
-#  private
-  $pr = proc{
-    def m
-    end
-  }
+def a
+  :a
 end
+def m
+  binding
+end
 
-$pr.call
-C.new.m
+eval('p a',   b=m)
+eval('a = 1', b)
+eval('p a',   b)
 
-__END__
 
-Const = :top
-class C
-  Const = :C
-end
-C.class_eval %{
-  Const
-  def m
-     Const
-  end
-}
-C.new.m

Modified: trunk/vm.c
===================================================================
--- trunk/vm.c	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/vm.c	2006-01-03 14:10:15 UTC (rev 352)
@@ -8,6 +8,7 @@
 #include "insnhelper.h"
 #include "vm_macro.inc"
 #include "insns.inc"
+#include "eval_intern.h"
 
 #define PROCDEBUG 0
 
@@ -76,34 +77,39 @@
            int local_size, int argc, const VALUE *argv)
 {
   VALUE *dfp;
+  yarv_control_frame_t *cfp;
   int i;
 
+  /* copy args */
   for(i=0; i<argc; i++){
     *sp = *argv;
     sp++; argv++;
   }
 
+  /* nil initialize */
   for(; i<local_size; i++){
     *sp = Qnil;
     sp++;
   }
 
+  /* set special val */
   *sp = GC_GUARDED_PTR(specval);
   dfp = sp;
+
   if(lfp == 0){
     lfp = sp;
   }
-  PUSH_CONTROL_STACK_FRAME(th,
-                           pc,            // pc
-                           sp+1,          // sp
-                           sp+1,          // bp
-                           iseq,          // iseq
-                           magic,         // magic
-                           self,          // self
-                           lfp,           // lfp
-                           dfp            // dfp
-                           );
-
+  
+  cfp        = th->cfp = th->cfp - 1;
+  cfp->pc    = pc;
+  cfp->sp    = sp + 1;
+  cfp->bp    = sp + 1;
+  cfp->iseq  = iseq;
+  cfp->magic = magic;
+  cfp->self  = self;
+  cfp->lfp   = lfp;
+  cfp->dfp   = dfp;
+  
   return Qtrue;
 }
 
@@ -136,7 +142,8 @@
 }
 
 VALUE
-th_set_eval_stack(yarv_thread_t *th, VALUE iseqval){
+th_set_eval_stack(yarv_thread_t *th, VALUE iseqval)
+{
   yarv_iseq_t *iseq;
   yarv_block_t *block = th->base_block;
   GetISeqVal(iseqval, iseq);
@@ -174,7 +181,6 @@
     }
     else{
       while(pcfp->dfp != penvptr){
-        // printf("pcfp: %p (%p)\n", pcfp->dfp, penvptr);
         pcfp++;
         if(pcfp->dfp == 0){
           SDR();
@@ -367,8 +373,7 @@
   proc->block.proc   = procval;
   proc->envval       = envval;
 
-  /* set cref */
-  // TODO: store cref?
+  th_store_klass(th, proc->block.lfp, &proc->stored_klass);
   return procval;
 }
 
@@ -603,38 +608,37 @@
 VALUE
 th_invoke_proc(yarv_thread_t *th, yarv_proc_t *proc, int argc, VALUE *argv)
 {
-  if(BUILTIN_TYPE(proc->block.iseq) == T_NODE){
-    return th_invoke_yield_cfunc(th, &proc->block, argc, argv);
+  VALUE val;
+  int state;
+  yarv_stored_klass_t sk;
+  VALUE stored_special_cref_stack;
+
+  stored_special_cref_stack = th_restore_stored_klass(th, proc->block.lfp, &proc->stored_klass);
+  
+  TH_PUSH_TAG(th);
+  if((state = EXEC_TAG()) == 0){
+    if(BUILTIN_TYPE(proc->block.iseq) == T_NODE){
+      val = th_invoke_yield_cfunc(th, &proc->block, argc, argv);
+    }
+    else{
+      val = th_invoke_proc_under(th, proc, argc, argv, proc->block.self);
+    }
   }
   else{
-    return th_invoke_proc_under(th, proc, argc, argv, proc->block.self);
   }
-}
-
-VALUE
-thread_invoke_proc_call(VALUE self, VALUE procval, int argc, VALUE *argv)
-{
-  yarv_thread_t *th;
-  yarv_proc_t *proc;
-  GetThreadVal(self, th);
-  GetProcVal(procval, proc);
   
-  return th_invoke_proc(th, proc, argc, argv);
+  th_restore_restored_klass(th, proc->block.lfp, stored_special_cref_stack);
+  TH_POP_TAG();
+  return val;
 }
 
-VALUE *
-th_cfp_svar(yarv_control_frame_t *cfp, int cnt)
+static VALUE *
+lfp_svar(VALUE *lfp, int cnt)
 {
-  NODE *node;
+  NODE *node = (NODE*)lfp[-1];
 
-  while(cfp->pc == 0){
-    cfp++;
-  }
-  
-  node = (NODE*)cfp->lfp[-1];
-
   if((VALUE)node == Qnil){
-    cfp->lfp[-1] = (VALUE)(node = NEW_IF(Qnil, Qnil, 0));
+    lfp[-1] = (VALUE)(node = NEW_IF(Qnil, Qnil, 0));
     node->nd_file = 0;
   }
   
@@ -660,6 +664,16 @@
 }
 
 VALUE *
+th_cfp_svar(yarv_control_frame_t *cfp, int cnt)
+{
+  NODE *node;
+  while(cfp->pc == 0){
+    cfp++;
+  }
+  return lfp_svar(cfp->lfp, cnt);
+}
+
+VALUE *
 th_svar(yarv_thread_t *th, int cnt)
 {
   yarv_control_frame_t *cfp = th->cfp;
@@ -766,10 +780,10 @@
 
 
 VALUE
-th_get_special_cref(yarv_thread_t *th, yarv_control_frame_t *cfp)
+lfp_get_special_cref(VALUE *lfp)
 {
   NODE *node;
-  if(((VALUE)(node = (NODE*)cfp->lfp[-1])) != Qnil &&
+  if(((VALUE)(node = (NODE*)lfp[-1])) != Qnil &&
      node->nd_file){
     return (VALUE)node->nd_file;
   }
@@ -778,33 +792,52 @@
   }
 }
 
-VALUE
-th_get_cref(yarv_thread_t *th, yarv_iseq_t *iseq, yarv_control_frame_t *cfp)
+static VALUE
+lfp_set_special_cref(VALUE *lfp, VALUE cref)
 {
+  NODE *node = (NODE*)lfp[-1];
+  VALUE *pv;
+  VALUE scref;
+  if(cref == 0 && ((VALUE)node == Qnil || node->nd_file == 0)){
+    scref = 0;
+  }
+  else{
+    pv = lfp_svar(lfp, -1);
+    scref = *pv;
+    *pv = cref;
+  }
+  return scref;
+}
+
+static VALUE
+get_cref(yarv_iseq_t *iseq, VALUE *lfp)
+{
   VALUE cref;
-  NODE *node;
-
-  if((cref = th_get_special_cref(th, cfp))){
+  if((cref = lfp_get_special_cref(lfp)) != 0){
     /* */
   }
-  else if(iseq->cref_stack){
-    cref = iseq->cref_stack;
+  else if((cref = iseq->cref_stack) != 0){
+    /* */
   }
   else{
-    cref = th->cref_stack;
-    dp(cref);
-    rb_bug("th_get_cref: unreachable");
+    rb_bug("get_cref: unreachable");
   }
   return cref;
 }
 
+VALUE
+th_get_cref(yarv_thread_t *th, yarv_iseq_t *iseq, yarv_control_frame_t *cfp)
+{
+  return get_cref(iseq, cfp->lfp);
+}
+
 static VALUE
 th_get_cbase(yarv_thread_t *th){
   int i;
   VALUE cref = th->cref_stack;
   VALUE klass;
   for(i=0; i<RARRAY(cref)->len; i++){
-    if((klass = rb_ary_entry(th->cref_stack, -(1+i))) != 0){
+    if((klass = rb_ary_entry(cref, -(1+i))) != 0){
       break;
     }
   }
@@ -817,6 +850,46 @@
   return FIX2INT(rb_ary_entry(th->visibility_stack, -1));
 }
 
+void
+rb_thread_push_klass(yarv_thread_t *th, VALUE klass, VALUE cref, int noex)
+{
+  rb_ary_push(th->klass_stack, klass);
+  rb_ary_push(th->cref_stack, cref);
+  rb_ary_push(th->visibility_stack, INT2FIX(noex));
+}
+
+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);
+}
+
+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)
@@ -825,7 +898,7 @@
   
   if(klass == Qnil){
     /* in current lexical scope */
-    VALUE cref = th_get_cref(th, iseq, th->cfp);
+    VALUE cref = get_cref(iseq, th->cfp->lfp);
     int i;
 
     for(i = 0; i<RARRAY(cref)->len; i++){
@@ -888,7 +961,7 @@
 
 EVALBODY_HELPER_FUNCTION VALUE
 eval_get_cvar_base(yarv_thread_t *th, yarv_iseq_t *iseq){
-  VALUE cref = th_get_cref(th, iseq, th->cfp);
+  VALUE cref = get_cref(iseq, th->cfp->lfp);
   VALUE klass = Qnil;
   int i;
   
@@ -1018,38 +1091,15 @@
   return mn;
 }
 
-void
-rb_thread_push_klass(yarv_thread_t *th, VALUE klass, VALUE cref, int noex)
-{
-  rb_ary_push(th->klass_stack, klass);
-  rb_ary_push(th->cref_stack, cref);
-  rb_ary_push(th->visibility_stack, INT2FIX(noex));
-}
-
-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);
-}
-
 static void
 call_yarv_end_proc(VALUE data)
 {
   rb_proc_call(data, rb_ary_new2(0));
 }
 
-
 /*********************************************************/
 /*********************************************************/
-/* import from ruby1.9/eval.c                            */
 
-#include "eval_intern.h"
-
-/*********************************************************/
-/*********************************************************/
-
 NORETURN(static void localjump_error(const char*, VALUE, int));
 static void
 localjump_error(mesg, value, reason)

Modified: trunk/vm_macro.def
===================================================================
--- trunk/vm_macro.def	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/vm_macro.def	2006-01-03 14:10:15 UTC (rev 352)
@@ -88,7 +88,8 @@
     /* check optional arguments */
     if(niseq->arg_opts){
       int iseq_argc = niseq->argc;
-      int opts = niseq->arg_opts;
+      int opts = niseq->arg_opts - 1;
+
       if(num < iseq_argc ||
          (niseq->arg_rest == 0 && num > iseq_argc + opts)){
         if(0){
@@ -105,12 +106,12 @@
       }
       if(num - iseq_argc < opts){
         opt_pc = niseq->arg_opt_tbl[num - iseq_argc];
-        sp  += opts - (num - iseq_argc) - 1;
-        num += opts - (num - iseq_argc) - 1;
-        clear_local_size = niseq->local_size - (iseq_argc + opts - 1);
+        sp  += opts - (num - iseq_argc);
+        num += opts - (num - iseq_argc);
+        clear_local_size = niseq->local_size - (iseq_argc + opts);
       }
       else{
-        opt_pc = niseq->arg_opt_tbl[opts-1];
+        opt_pc = niseq->arg_opt_tbl[opts];
       }
     }
     /* check rest */
@@ -177,7 +178,7 @@
   }
   /* stack overflow check */
   if(CHECK_STACK_OVERFLOW(th, GET_CFP(), niseq->stack_max + 0x100)){
-    rb_bug("stack overflow");
+    rb_exc_raise(sysstack_error);
   }
   
   for(i=0; i<clear_local_size; i++){

Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/yarvcore.c	2006-01-03 14:10:15 UTC (rev 352)
@@ -730,8 +730,7 @@
 
   th_init(th);
   th->self = self;
-
-  th->vm       = vm;
+  th->vm   = vm;
   return self;
 }
 
@@ -832,14 +831,11 @@
   yarv_proc_t *proc;
   MARK_REPORT("-> proc", 1);
   if(ptr){
-    
     proc = ptr;
-    //GC_INFO("env\n");
     MARK_UNLESS_NULL(proc->envval);
-    //GC_INFO("blockval\n");
     MARK_UNLESS_NULL(proc->blockprocval);
-    MARK_UNLESS_NULL(proc->cref_stack);
-    //GC_INFO("iseq\n");
+    MARK_UNLESS_NULL(proc->stored_klass.klass);
+    MARK_UNLESS_NULL(proc->stored_klass.cref_stack);
     if(proc->block.iseq && YARV_IFUNC_P(proc->block.iseq)){
       MARK_UNLESS_NULL((VALUE)(proc->block.iseq));
     }
@@ -854,10 +850,7 @@
   yarv_proc_t *proc;
   obj = Data_Make_Struct(klass, yarv_proc_t,
                          proc_mark, proc_free, proc);
-  proc->envval = 0;
-  proc->blockprocval = 0;
-  proc->block.iseq = 0;
-  proc->is_lambda = 0;
+  MEMZERO(proc, yarv_proc_t, 1);
   return obj;
 }
 
@@ -941,7 +934,8 @@
   if(ptr){
     bind = ptr;
     MARK_UNLESS_NULL(bind->env);
-    MARK_UNLESS_NULL(bind->cref_stack);
+    MARK_UNLESS_NULL(bind->stored_klass.klass);
+    MARK_UNLESS_NULL(bind->stored_klass.cref_stack);
   }
   MARK_REPORT("<- binding", 0);
 }
@@ -953,7 +947,7 @@
   yarv_binding_t *bind;
   obj = Data_Make_Struct(klass, yarv_binding_t,
                          binding_mark, binding_free, bind);
-  bind->cref_stack = 0;
+  MEMZERO(bind, yarv_binding_t, 1);
   return obj;
 }
 

Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h	2005-12-31 20:15:27 UTC (rev 351)
+++ trunk/yarvcore.h	2006-01-03 14:10:15 UTC (rev 352)
@@ -417,10 +417,17 @@
   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;
-  VALUE cref_stack;
   int safe_level;
   int is_lambda;
   int visibility;
@@ -442,10 +449,7 @@
 
 typedef struct{
   VALUE env;
-  
-  VALUE klass;
-  VALUE cref_stack;
-  int visibility;
+  yarv_stored_klass_t stored_klass;
 } yarv_binding_t;
 
 
@@ -457,12 +461,9 @@
 #define VM_CALL_TAILCALL_BIT       0x10
 #define VM_CALL_TAILRECURSION_BIT  0x20
 
-
-VALUE thread_invoke_proc_call(VALUE self, VALUE proc, int argc, VALUE *args);
 VALUE thread_eval_body(VALUE self);
 VALUE iseq_inspect(VALUE self);
 
-
 /* inline method cache */
 #define NEW_INLINE_CACHE_ENTRY() NEW_WHILE(Qundef, 0, 0)
 #define ic_klass  u1.value
@@ -516,10 +517,14 @@
 #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_push_klass(yarv_thread_t *th, VALUE klass, VALUE cref, int noex);
 void rb_thread_pop_klass(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

[前][次][番号順一覧][スレッド一覧][生データ]