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

yarv-diff:146

From: ko1 atdot.net
Date: 9 Dec 2005 19:00:26 -0000
Subject: [yarv-diff:146] r305 - in trunk: . template yarvtest

Author: ko1
Date: 2005-12-10 04:00:25 +0900 (Sat, 10 Dec 2005)
New Revision: 305

Modified:
   trunk/ChangeLog
   trunk/common.mk
   trunk/compile.c
   trunk/insns.def
   trunk/template/optinsn.inc.tmpl
   trunk/test.rb
   trunk/vm.c
   trunk/yarvtest/test_class.rb
Log:
	* common.mk : fix blockinlining.o build rule

	* insns.def : remove logic for zsuper

	* template/optinsn.inc.tmpl : 

	* vm.c : remove thread_yield_light_prepare, thread_yield_light_invoke

	* compile.c : support NODE_ZSUPER with optargs, restarg

	* yarvtest/test_class.rb : add tests for above



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2005-12-08 16:30:22 UTC (rev 304)
+++ trunk/ChangeLog	2005-12-09 19:00:25 UTC (rev 305)
@@ -4,6 +4,21 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2005-12-10(Sat) 03:57:20 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* common.mk : fix blockinlining.o build rule
+
+	* insns.def : remove logic for zsuper
+
+	* template/optinsn.inc.tmpl : 
+
+	* vm.c : remove thread_yield_light_prepare, thread_yield_light_invoke
+
+	* compile.c : support NODE_ZSUPER with optargs, restarg
+
+	* yarvtest/test_class.rb : add tests for above
+
+
 2005-12-09(Fri) 01:13:37 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* array.c, numeric.c, range.c : add prototype of

Modified: trunk/common.mk
===================================================================
--- trunk/common.mk	2005-12-08 16:30:22 UTC (rev 304)
+++ trunk/common.mk	2005-12-09 19:00:25 UTC (rev 305)
@@ -382,7 +382,7 @@
 yarvcore.$(OBJEXT): {$(VPATH)}yarvcore.c {$(VPATH)}yarvcore.h \
         {$(VPATH)}yarv_version.h {$(VPATH)}debug.h rev.inc
 debug.$(OBJEXT): {$(VPATH)}debug.h
-blockinlining.$(OBJEXT): {$(VPATH)}yarv.h {$(VPATH)}yarvcore.h 
+blockinlining.$(OBJEXT): {$(VPATH)}yarv.h {$(VPATH)}yarvcore.h vm_opts.h
 
 
 BASERUBY = ruby

Modified: trunk/compile.c
===================================================================
--- trunk/compile.c	2005-12-08 16:30:22 UTC (rev 304)
+++ trunk/compile.c	2005-12-09 19:00:25 UTC (rev 305)
@@ -119,8 +119,12 @@
   return COMPILE_OK;
 }
 
+
 #include "optinsn.inc"
+
+#if OPT_INSTRUCTIONS_UNIFICATION
 #include "optunifs.inc"
+#endif
 
 #define REWIND_DSIZE()  1
 #define MREWIND_DSIZE() 2
@@ -457,11 +461,13 @@
   return anchor->anchor.next;
 }
 
+/* 
 static LINK_ELEMENT *
 LAST_ELEMENT(LINK_ANCHOR *anchor)
 {
   return anchor->last;
 }
+ */
 
 static LINK_ELEMENT *
 POP_ELEMENT(LINK_ANCHOR *anchor)
@@ -530,7 +536,6 @@
   verify_list("swap1", anc1);
   verify_list("swap2", anc2);
 }
-#endif
 
 static LINK_ANCHOR *
 REVERSE_LIST(LINK_ANCHOR *anc)
@@ -562,6 +567,7 @@
   verify_list("reverse", anc);
   return anc;
 }
+#endif
 
 #if CPDEBUG > 0
 static void
@@ -853,7 +859,6 @@
 static NODE*
 search_block_local_parameters(yarv_iseq_t *iseq, NODE *node)
 {
-  int i;
   NODE *nelem;
   VALUE local_vars = rb_ary_new();
   VALUE param_vars = rb_ary_new();
@@ -1061,14 +1066,6 @@
 }
 
 static int
-get_dyna_var_idx_at(VALUE self, ID id)
-{
-  yarv_iseq_t *iseq;
-  GetISeqVal(self, iseq);
-  return get_dyna_var_idx_at_raw(iseq, id);
-}
-
-static int
 get_dyna_var_idx(VALUE self, ID id, int *level, int *ls)
 {
   yarv_iseq_t *iseq;
@@ -1579,6 +1576,7 @@
   return COMPILE_OK;
 }
 
+#if OPT_INSTRUCTIONS_UNIFICATION
 static INSN*
 new_unified_insn(yarv_iseq_t *iseq,
                  int insn_id, int size, LINK_ELEMENT *seq_list)
@@ -1611,8 +1609,8 @@
   
   return new_insn_core(iseq, iobj->line_no, insn_id, argc, operands);
 }
+#endif
 
-
 /*
  * This scheme can get more performance if do this optimize with
  * label address resolving.
@@ -2054,7 +2052,6 @@
       case NODE_ARGSCAT:{
         NODE *ary = rhsn->nd_head;
         int idx = 0;
-        int rlen = rhsn->nd_head->nd_alen;
         
         while(ary){
           if(idx < llen || lhs_splat){
@@ -2315,7 +2312,6 @@
   DECL_ANCHOR(ensure);
   while(enlp){
     DECL_ANCHOR(ensure_part);
-    LINK_ANCHOR *t;
     LABEL *lstart = NEW_LABEL(0);
     LABEL *lend   = NEW_LABEL(0);
     add_ensure_range(iseq, enlp->erange, lstart, lend);
@@ -3324,10 +3320,10 @@
     debugp_param("call method",    ID2SYM(mid));
 
     switch(nd_type(node)){
-    NODE_VCALL:
+    case NODE_VCALL:
       flag |= VM_CALL_VCALL_BIT;
       /* VCALL is funcall, so fall through */
-    NODE_FCALL:
+    case NODE_FCALL:
       flag |= VM_CALL_FCALL_BIT;
     }
     
@@ -3359,10 +3355,9 @@
         else if(nd_type(node->nd_args) == NODE_ARGSCAT){
           compile_array(self, iseq, args, node->nd_args->nd_head, Qfalse);
           POP_ELEMENT(args);
-
-          argc = LIST_SIZE(args) + 1;
+          
+          argc = INT2FIX(LIST_SIZE(args) + 1);
           COMPILE(args, "args(cat: splat)", node->nd_args->nd_body);
-
           flag |= VM_CALL_ARGS_SPLAT_BIT;
         }
         else{
@@ -3386,10 +3381,25 @@
         int idx = liseq->local_size - i;
         ADD_INSN1(args, nd_line(node), getlocal, I2F(idx));
       }
-      /* optional arguments */
-
-      /* rest arguments */
-      
+      if(!liseq->arg_simple){
+        if(liseq->arg_opts){
+          /* optional arguments */
+          int j;
+          for(j=0; j<liseq->arg_opts-1; j++){
+            int idx = liseq->local_size - (i+j);
+            ADD_INSN1(args, nd_line(node), getlocal, I2F(idx));
+          }
+          i+=j;
+          argc = INT2FIX(i);
+        }
+        if(liseq->arg_rest){
+          /* rest arguments */
+          int idx = liseq->local_size - liseq->arg_rest + 1;
+          ADD_INSN1(args, nd_line(node), getlocal, I2F(idx));
+          argc = INT2FIX(liseq->arg_rest);
+          flag |= VM_CALL_ARGS_SPLAT_BIT;
+        }
+      }
     }
     
     ADD_INSN(ret, nd_line(node), putnil); /* dummy reciever */
@@ -3569,7 +3579,6 @@
     if(!poped){
       idx = get_dyna_var_idx(self, node->nd_vid, &lv, &ls);
       if(idx < 0){
-        int *a = 0;
         rb_bug("unknown dvar (%s)", rb_id2name(node->nd_vid));
       }
       ADD_INSN2(ret, nd_line(node), getdynamic, I2F(ls - idx), I2F(lv));
@@ -4333,7 +4342,7 @@
     }
     default:
       /* ignore */
-      printf("%ld\n", FIX2INT(link->type));
+      printf("%ld\n", FIX2LONG(link->type));
       rb_bug("dump_disasm_list error");
     }
     link = link->next;

Modified: trunk/insns.def
===================================================================
--- trunk/insns.def	2005-12-08 16:30:22 UTC (rev 304)
+++ trunk/insns.def	2005-12-09 19:00:25 UTC (rev 305)
@@ -1233,8 +1233,6 @@
   recv  = TOPN(num);
   klass = CLASS_OF(recv);
 
-
-//  dpi(id);
   mn = eval_method_search(id, klass, ic, &noex);
 
 #if CURRENT_INSN_send || CURRENT_INSN_send_SC_xx_ax
@@ -1277,43 +1275,11 @@
       num   = tmp_num;
       recv  = GET_SELF();
       klass = eval_search_super_klass(ip->klass, recv);
-
       blockptr = tmp_blockptr;
       mn       = rb_method_node(klass, id);
       noex     = 0;
     }
   }
-  if(0){
-    LABEL_IS_SC(start_init_in_zsuper):
-    {
-      yarv_iseq_t *iseq = GET_ISEQ();
-      yarv_iseq_t *ip = iseq;
-      VALUE *sp, *lp;
-      int i;
-
-      while(ip->parent_iseq){
-        ip = ip->parent_iseq;
-      }
-
-      id = rb_to_id(ip->name);
-      num   = ip->argc;
-      recv  = GET_SELF();
-      klass = eval_search_super_klass(ip->klass, recv);
-
-      blockptr = tmp_blockptr;
-      mn       = rb_method_node(klass, id);
-      noex     = 0;
-
-      /* copy locals */
-      sp = GET_SP();
-      *sp = recv; sp++;
-      lp = GET_LFP() - ip->local_size;
-      for(i=0; i<num; i++, sp++, lp++){
-        *sp = *lp;
-      }
-      SET_SP(sp);
-    }
-  }
 #endif
 #endif
   macro_eval_invoke_method(recv, klass, id, num, mn, noex, blockptr);

Modified: trunk/template/optinsn.inc.tmpl
===================================================================
--- trunk/template/optinsn.inc.tmpl	2005-12-08 16:30:22 UTC (rev 304)
+++ trunk/template/optinsn.inc.tmpl	2005-12-09 19:00:25 UTC (rev 305)
@@ -12,7 +12,8 @@
   or rb/insns2vm.rb
  */
 
-static INSN *insn_optimize(INSN *insnobj){
+static INSN *
+insn_optimize(INSN *insnobj){
 #ifdef OPT_OPERANDS_UNIFICATION
   /* optimize rule */
   switch(insnobj->insn_id){

Modified: trunk/test.rb
===================================================================
--- trunk/test.rb	2005-12-08 16:30:22 UTC (rev 304)
+++ trunk/test.rb	2005-12-09 19:00:25 UTC (rev 305)
@@ -1,144 +1,4 @@
-1.times{
-  j = 0
-  1.times{
-    p j
-  }
-}
-__END__
-eval %q{
-  a = 0
-  1.times{
-    p a
-  }
-}
+$:.unshift '../yarv/lib'
+require 'test/unit'
 
-__END__
-a = 1
-1.times{
-  p a
-  a = 1
-}
 
-__END__
-class C
-  def m *args
-    p args
-  end
-end
-
-class D < C
-  def m a, b, c
-    super(a, b, c)
-    super
-  end
-end
-
-D.new.m(1, 2, 3)
-
-__END__
-
-def m arg
-  arg
-end
-  
-m(while true
-  class C
-    break :foo
-  end
-end)
-
-__END__
-
-p 1.times{
-  while true
-    class C
-      break
-    end
-  end
-  p :foo
-}
-p :bar
-__END__
-
-1.times{
-  class C
-    next
-  end
-}
-    
-__END__
-
-$a = []; begin; ; $a << 1
-      3.times{; $a << 2
-        class C; $a << 3
-          next; $a << 4
-        end; $a << 5
-      }; $a << 6
-    ; $a << 7
-; rescue Exception; $a << 99; end; $a
-__END__
-
-if false
-i=0
-while i<2
-  i+=1
-  class C
-    next 10
-  end
-end
-p 1
-else
-
-$a = []
-begin
-  i=0
-  while i<3
-    i+=1
-    class C
-      next 10
-    end
-  end
-  $a << 9
-rescue Exception
-end
-
-p $a
-end
-__END__
-
-$a = []
-begin
-  $a << 1
-  3.times{
-    $a << 2
-    class C
-      $a << 3
-      next
-      $a << 4
-    end
-    $a << 5
-  }
-  $a << 6
-  $a << 7
-rescue Exception
-  $a << 99
-end
-$a
-
-__END__
-
-[1].each{|e|
-  class C
-    next
-  end
-}
-
-__END__
-3.times{
-  class C
-    class D
-      next
-    end
-  end
-}
-

Modified: trunk/vm.c
===================================================================
--- trunk/vm.c	2005-12-08 16:30:22 UTC (rev 304)
+++ trunk/vm.c	2005-12-09 19:00:25 UTC (rev 305)
@@ -330,6 +330,8 @@
   return procval;
 }
 
+struct RObject *rb;
+
 VALUE
 th_make_proc(yarv_thread_t *th, yarv_control_frame_t *cfp, yarv_block_t *block)
 {
@@ -578,89 +580,6 @@
   return val;
 }
 
-
-VALUE
-thread_yield_light_prepare(VALUE self, int argc, VALUE *argv,
-                           struct yarv_yield_data *data)
-{
-  yarv_thread_t *th;
-  yarv_control_frame_t *cfp;
-  yarv_block_t *block;
-
-  GetThreadVal(self, th);
-  cfp = th->cfp;
-  
-  data->th    = th;
-  data->block = block = GC_GUARDED_PTR_REF(cfp->lfp[0]);
-
-  if(block == 0){
-    rb_bug("block is not given");
-  }
-  else{
-    if(BUILTIN_TYPE(block->iseq) != T_NODE){
-      int local_size = block->iseq->local_size;
-      th_set_finish_env(th);
-
-      if(block->iseq->argc < argc){
-        argc = block->iseq->argc;
-      }
-
-      th_set_env(th, block->iseq, FRAME_MAGIC_BLOCK,
-                 block->self, GC_GUARDED_PTR(block->dfp),
-                 block->iseq->iseq_encoded, th->cfp->sp, block->lfp,
-                 local_size, argc, argv);
-
-      data->local_size = block->iseq->local_size;
-      data->pc = block->iseq->iseq_encoded;
-      data->sp = th->cfp->sp;
-      data->argc = argc;
-#if OPT_STACK_CACHING != 1
-      data->spbuff = *(th->cfp->sp-1);
-#endif
-      th->cfp+=2; // pop, pop
-    }
-    else{
-      rb_bug("thread_yield_light_prepare: unsupported ifunc");
-      //val = th_invoke_yield_cfunc(th, block, argc, argv);
-    }
-  }
-  return Qtrue;
-}
-
-
-VALUE
-thread_yield_light_invoke(int argc, VALUE *argv,
-                          struct yarv_yield_data *data)
-{
-  VALUE val;
-  yarv_thread_t *th = data->th;
-  int i;
-  
-  if(BUILTIN_TYPE(data->block->iseq) != T_NODE){
-    th->cfp -= 2;
-    th->cfp->pc = data->pc;
-    // th->cfp->sp = data->sp;
-#if OPT_STACK_CACHING != 1
-    /* if not stack caching, "end" insn break dfp var.
-       so, this dfp var must be restore
-     */
-    *(th->cfp->sp-1) = data->spbuff;
-#endif
-    
-    for(i=0; i<data->argc; i++){
-      th->cfp->dfp[i - data->local_size] = argv[i];
-    }
-    val = th_eval_body(th);
-    (th->cfp-1)->pc--;
-  }
-  else{
-    rb_bug("unsupported\n");
-    val = Qundef;
-  }
-  return val;
-}
-
-
 static VALUE
 th_invoke_proc_under(yarv_thread_t *th, yarv_proc_t *proc,
                      int argc, VALUE *argv, VALUE self)
@@ -689,8 +608,6 @@
   }
 }
 
-
-
 VALUE
 thread_invoke_proc_call(VALUE self, VALUE procval, int argc, VALUE *argv)
 {
@@ -737,7 +654,6 @@
   }
 }
 
-
 VALUE *
 thread_svar(VALUE self, int cnt)
 {

Modified: trunk/yarvtest/test_class.rb
===================================================================
--- trunk/yarvtest/test_class.rb	2005-12-08 16:30:22 UTC (rev 304)
+++ trunk/yarvtest/test_class.rb	2005-12-09 19:00:25 UTC (rev 305)
@@ -188,13 +188,13 @@
 
       class D < C
         def m arg
-          super(*arg)
+          super(*arg) + super(1, arg.shift)
         end
       end
 
       D.new.m([1, 2])
     }
-
+    
     ae %q{
       class C
         def m
@@ -301,6 +301,99 @@
         :top
       }
     }
+    ae %q{
+      class C
+        def m(a, b, c, d)
+          a+b+c+d
+        end
+      end
+
+      class D < C
+        def m(a, b=1, c=2, *d)
+          d[0] ||= 0.1
+          [super,
+            begin
+              a *= 2
+              b *= 3
+              c *= 4
+              d[0] *= 5
+              super
+            end
+          ]
+        end
+      end
+      ary = []
+      ary << D.new.m(10, 20, 30, 40)
+      if false # On current ruby, these programs don't work
+        ary << D.new.m(10, 20, 30)
+        ary << D.new.m(10, 20)
+        ary << D.new.m(10)
+      end
+      ary
+    }
+    ae %q{
+      class C
+        def m(a, b, c, d)
+          a+b+c+d
+        end
+      end
+
+      class D < C
+        def m(a, b=1, c=2, d=3)
+          [super,
+            begin
+              a *= 2
+              b *= 3
+              c *= 4
+              d *= 5
+              super
+            end
+          ]
+        end
+      end
+      ary = []
+      ary << D.new.m(10, 20, 30, 40)
+      ary << D.new.m(10, 20, 30)
+      ary << D.new.m(10, 20)
+      ary << D.new.m(10)
+      ary
+    }
+    ae %q{
+      class C
+        def m(a, b, c, d, &e)
+          a+b+c+d+e.call
+        end
+        def n(a, b, c, d, &e)
+          a+b+c+d+e.call
+        end
+      end
+
+      class D < C
+        def m(a, b=1, c=2, *d, &e)
+          super
+        end
+        def n(a, b=1, c=2, d=3, &e)
+          super
+        end
+      end
+      ary = []
+      ary << D.new.m(1, 2, 3, 4){
+        5
+      }
+      ary << D.new.m(1, 2, 3, 4, &lambda{
+        5
+      })
+      ary << D.new.n(1, 2, 3){
+        5
+      }
+      ary << D.new.n(1, 2){
+        5
+      }
+      ary << D.new.n(1){
+        5
+      }
+      ary
+    }
   end
 
   def test_const_in_other_scope


-- 
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml

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