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

yarv-diff:60

From: ko1 atdot.net
Date: 29 Jul 2005 11:18:39 -0000
Subject: [yarv-diff:60] r215 - in trunk: . test

Author: ko1
Date: 2005-07-29 20:18:39 +0900 (Fri, 29 Jul 2005)
New Revision: 215

Modified:
   trunk/ChangeLog
   trunk/compile.c
   trunk/insns.def
   trunk/test/test_block.rb
   trunk/vm.c
   trunk/yarvcore.c
Log:
	* compile.c : make_name_for_block and make_name_with_str
	are added

	* insns.def : fix if unmatched size arg size to yield

	* test/test_block.rb : add test for above fix

	* vm.c : add th_backtrace_each and fix backtrace notation

	* yarvcore.c : set top level iseq name to "<main>"



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2005-07-29 04:28:52 UTC (rev 214)
+++ trunk/ChangeLog	2005-07-29 11:18:39 UTC (rev 215)
@@ -4,6 +4,20 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2005-07-29(Fri) 20:14:11 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* compile.c : make_name_for_block and make_name_with_str
+	are added
+
+	* insns.def : fix if unmatched size arg size to yield
+
+	* test/test_block.rb : add test for above fix
+
+	* vm.c : add th_backtrace_each and fix backtrace notation
+
+	* yarvcore.c : set top level iseq name to "<main>"
+
+
 2005-07-29(Fri) 13:20:19 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* yarvcore.h : fix yarv_iseq_t to pass VC (cl)

Modified: trunk/compile.c
===================================================================
--- trunk/compile.c	2005-07-29 04:28:52 UTC (rev 214)
+++ trunk/compile.c	2005-07-29 11:18:39 UTC (rev 215)
@@ -1769,8 +1769,40 @@
   return 0;
 }
 
+#define BUFSIZE 0x100
 
+static
+VALUE make_name_for_block(yarv_iseq_t *iseq){
+  char buf[BUFSIZE];
+  if(iseq->parent_iseqobj == 0){
+    snprintf(buf, BUFSIZE, "block in %s", RSTRING(iseq->name)->ptr);
+  }
+  else{
+    int level = 1;
+    yarv_iseq_t *ip = iseq;
+    while(1){
+      if(ip->parent_iseqobj){
+        ip = ip->parent_iseqobj;
+      }
+      else{
+        break;
+      }
+      level++;
+    }
+    snprintf(buf, BUFSIZE, "block (%d levels) in %s", level,
+             RSTRING(ip->name)->ptr);
+  }
+  return rb_str_new2(buf);
+}
 
+static
+VALUE make_name_with_str(char *fmt, char *str){
+  char buf[BUFSIZE];
+  snprintf(buf, BUFSIZE, fmt, str);
+  return rb_str_new2(buf);
+}
+
+
 /**
   compile each node
 
@@ -2050,8 +2082,9 @@
     LABEL * retry_end_l = NEW_LABEL(nd_line(node));
     VALUE name = rb_str_new2("b@");
     rb_str_concat(name, iseqobj->name);
-    iseqobj->compile_data->current_block = NEW_CHILD_ISEQOBJ(node, name,
-                                                             self, ISEQ_TYPE_BLOCK);
+    iseqobj->compile_data->current_block =
+      NEW_CHILD_ISEQOBJ(node, make_name_for_block(iseqobj),
+                        self, ISEQ_TYPE_BLOCK);
     ADD_LABEL(ret, retry_label);
     if(nd_type(node) == NODE_FOR){
       COMPILE(ret, "iter caller (for)", node->nd_iter);
@@ -2186,7 +2219,7 @@
     break;
   }
   case NODE_ENSURE:{
-    VALUE ensure = NEW_CHILD_ISEQOBJ(node->nd_ensr, rb_str_new2("ensure clause"),
+    VALUE ensure = NEW_CHILD_ISEQOBJ(node->nd_ensr, rb_str_new2("ensure"),
                                      self, ISEQ_TYPE_ENSURE);
     LABEL * lstart = NEW_LABEL(nd_line(node));
     LABEL * lend   = NEW_LABEL(nd_line(node));
@@ -3178,8 +3211,10 @@
     break;
   }
   case NODE_CLASS:{
-    VALUE iseq = NEW_ISEQOBJ(node->nd_body, rb_str_new2("class"),
-                             ISEQ_TYPE_CLASS);
+    VALUE iseq =
+      NEW_ISEQOBJ(node->nd_body,
+                  make_name_with_str("<class:%s>", rb_id2name(node->nd_cpath->nd_mid)),
+                  ISEQ_TYPE_CLASS);
     
     COMPILE(ret, "cbase", node->nd_cpath->nd_head);
     COMPILE(ret, "super", node->nd_super);
@@ -3192,8 +3227,11 @@
     break;
   }
   case NODE_MODULE:{
-    VALUE iseq = NEW_ISEQOBJ(node->nd_body, rb_str_new2("module"),
-                             ISEQ_TYPE_CLASS);
+    VALUE iseq =
+      NEW_ISEQOBJ(node->nd_body,
+                  make_name_with_str("<module:%s>", rb_id2name(node->nd_cpath->nd_mid)),
+                  ISEQ_TYPE_CLASS);
+    
     COMPILE  (ret, "mbase", node->nd_cpath->nd_head);
     ADD_INSN2(ret, nd_line(node), moduledef, ID2SYM(node->nd_cpath->nd_mid), iseq);
     ADD_INSN (ret, nd_line(node), popcref);

Modified: trunk/insns.def
===================================================================
--- trunk/insns.def	2005-07-29 04:28:52 UTC (rev 214)
+++ trunk/insns.def	2005-07-29 11:18:39 UTC (rev 215)
@@ -1194,20 +1194,24 @@
   VALUE  prev_self;
   
   yarv_iseq_t *iseq;
-  int i;
+  int i, argc = num;
   
   if(block == 0){
     localjump_error("no block given", Qnil, 0);
   }
 
   iseq = block->iseq;
-
+  
   if(BUILTIN_TYPE(iseq) != T_NODE){
+    if(argc > iseq->argc){
+      INC_SP(iseq->argc - argc);
+      argc -= num - iseq->argc;
+    }
     th_set_env(th, iseq,
                FRAME_MAGIC_BLOCK, block->self, (VALUE)block->dfp,
                iseq->ISEQ_MEMBER, block->lfp,
-               iseq->local_size - num, 0, 0);
-    reg_cfp->sp -= num;
+               iseq->local_size - argc, 0, 0);
+    reg_cfp->sp -= argc;
     RESTORE_REGS();
     NEXT_INSN();
     /* unreachable */

Modified: trunk/test/test_block.rb
===================================================================
--- trunk/test/test_block.rb	2005-07-29 04:28:52 UTC (rev 214)
+++ trunk/test/test_block.rb	2005-07-29 11:18:39 UTC (rev 215)
@@ -273,5 +273,25 @@
       sum
     }
   end
-  
+
+  def test_unmatched_params
+    ae %q{
+      def iter
+        yield 1,2,3
+      end
+
+      iter{|i, j|
+        [i, j]
+      }
+    }
+    ae %q{
+      def iter
+        yield 1
+      end
+
+      iter{|i, j|
+        [i, j]
+      }
+    }
+  end
 end

Modified: trunk/vm.c
===================================================================
--- trunk/vm.c	2005-07-29 04:28:52 UTC (rev 214)
+++ trunk/vm.c	2005-07-29 11:18:39 UTC (rev 215)
@@ -230,6 +230,7 @@
   return procval;
 }
 
+
 VALUE th_call0(yarv_thread_t *th, VALUE klass, VALUE recv,
                VALUE id, ID oid, int argc, const VALUE *argv,
                NODE *body, int nosuper){
@@ -409,6 +410,7 @@
       th->cfp+=2; // pop, pop
     }
     else{
+      rb_bug("thread_yield_light_prepare: unsupported ifunc");
       //val = thread_invoke_yield_cfunc(th, block, argc, argv);
     }
   }
@@ -486,7 +488,6 @@
   }
   else{
     VALUE ary;
-    exit(0);
     if((ary = node->u3.value) == 0){
       ary = node->u3.value = rb_ary_new();
     }
@@ -506,9 +507,54 @@
 
 
 static
+VALUE th_backtrace_each(yarv_thread_t *th, yarv_control_frame_t *cfp,
+                        char *file, int line_no, VALUE ary){
+  VALUE str = 0;
+  char buf[BUFSIZE];
+
+  if(cfp->iseq != 0){
+    if(cfp->pc != 0){
+      int i;
+      int pos = cfp->pc - cfp->iseq->ISEQ_MEMBER;
+
+      for(i=0; i<cfp->iseq->insn_info_size; i++){
+        if(cfp->iseq->insn_info_tbl[i].position == pos){
+          line_no = cfp->iseq->insn_info_tbl[i-1].line_no;
+          // sendpos = iseq->insn_info_tbl[i-1].position;
+          goto found;
+        }
+      }
+      rb_bug("thread_backtrace: unkown instruction (%d)", pos);
+    found:
+      snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
+               file = RSTRING(cfp->iseq->file_name)->ptr,
+               line_no, RSTRING(cfp->iseq->name)->ptr);
+    }
+    else{
+      struct cmethod_info *cmi = (void *)cfp->iseq;
+      snprintf(buf, BUFSIZE, "%s:%d:in `%s'",
+               file, line_no, rb_id2name(cmi->id));
+    }
+    str = rb_str_new2(buf);
+  }
+  else if(0 && cfp->magic == FRAME_MAGIC_IFUNC){
+    snprintf(buf, BUFSIZE, "::in `<ifunc>'", // ""%s:%d:in `<ifunc>'",
+             file, line_no);
+    str = rb_str_new2(buf);
+  }
+
+  if(th->cfp != cfp){
+    th_backtrace_each(th, cfp-1, file, line_no, ary);
+  }
+  if(str){
+    rb_ary_push(ary, str);
+  }
+  return str;
+}
+
+static
 VALUE th_backtrace(yarv_thread_t *th, int lev){
-  VALUE ary = rb_ary_new();
-  char buf[BUFSIZE];
+  VALUE ary;
   yarv_control_frame_t *cfp = th->cfp;
   yarv_control_frame_t *top_of_cfp = (void *)(th->stack + th->stack_size);
   top_of_cfp--;
@@ -529,46 +575,7 @@
     ary = rb_ary_new();
   }
 
-  while(cfp < top_of_cfp){
-    if(cfp->iseq != 0){
-      if(cfp->pc != 0){
-        int line_no, i;
-        int pos = cfp->pc - cfp->iseq->ISEQ_MEMBER;
-
-        for(i=0; i<cfp->iseq->insn_info_size; i++){
-          if(cfp->iseq->insn_info_tbl[i].position == pos){
-            line_no = cfp->iseq->insn_info_tbl[i-1].line_no;
-            // sendpos = iseq->insn_info_tbl[i-1].position;
-            goto found;
-          }
-        }
-        rb_bug("thread_backtrace: unkown instruction (%d)", pos);
-      found:
-        if(cfp->magic != FRAME_MAGIC_TOP
-           //&& cfp->magic != FRAME_MAGIC_BLOCK
-           ){
-          snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
-                   RSTRING(cfp->iseq->file_name)->ptr,
-                   line_no, RSTRING(cfp->iseq->name)->ptr);
-        }
-        else{
-          /* top */
-          snprintf(buf, BUFSIZ, "%s:%d",
-                   RSTRING(cfp->iseq->file_name)->ptr, line_no);
-        }
-      }
-      else{
-        /* TODO */
-        struct cmethod_info *cmi = (void *)cfp->iseq;
-        snprintf(buf, BUFSIZE, "::in `%s'", //"%s:%d:in `%s'",
-                 // "(c)", 0,
-                 rb_id2name(cmi->id));
-      }
-      rb_ary_push(ary, rb_str_new2(buf));
-    }
-    cfp++;
-  }
-
+  th_backtrace_each(th, top_of_cfp, "", 0, ary);
   return ary;
 }
 

Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c	2005-07-29 04:28:52 UTC (rev 214)
+++ trunk/yarvcore.c	2005-07-29 11:18:39 UTC (rev 215)
@@ -233,7 +233,7 @@
   volatile VALUE iseq;
   
   argv[0] = node;
-  argv[1] = rb_str_new2("main");
+  argv[1] = rb_str_new2("<main>");
   argv[2] = file;
   argv[3] = Qfalse;
   argv[4] = ISEQ_TYPE_TOP;
@@ -777,7 +777,7 @@
 
   symIFUNC = ID2SYM(rb_intern("<IFUNC>"));
   symCFUNC = ID2SYM(rb_intern("<CFUNC>"));
-  
+
   /* for optimize */
   idPLUS = rb_intern("+");
   idMINUS= rb_intern("-");


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

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