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

yarv-diff:87

From: ko1 atdot.net
Date: 16 Aug 2005 01:26:28 -0000
Subject: [yarv-diff:87] r243 - in trunk: . lib

Author: ko1
Date: 2005-08-16 10:26:27 +0900 (Tue, 16 Aug 2005)
New Revision: 243

Added:
   trunk/lib/shellwords.rb
Modified:
   trunk/ChangeLog
   trunk/compile.c
   trunk/eval.c
   trunk/test1.rb
Log:
	* eval.c : support rb_yield_0 with 0 args



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2005-08-16 00:10:54 UTC (rev 242)
+++ trunk/ChangeLog	2005-08-16 01:26:27 UTC (rev 243)
@@ -4,6 +4,11 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2005-08-16(Tue) 10:25:29 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* eval.c : support rb_yield_0 with 0 args
+
+
 2005-08-16(Tue) 09:09:21 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* lib/fileutils.rb : imported

Modified: trunk/compile.c
===================================================================
--- trunk/compile.c	2005-08-16 00:10:54 UTC (rev 242)
+++ trunk/compile.c	2005-08-16 01:26:27 UTC (rev 243)
@@ -1685,8 +1685,10 @@
   return Qfalse;
 }
 
-static int make_masgn_lhs(VALUE self, yarv_iseq_t *iseqobj,
-                          LINK_ANCHOR *ret, NODE *node){
+static int
+make_masgn_lhs(VALUE self, yarv_iseq_t *iseqobj,
+               LINK_ANCHOR *ret, NODE *node)
+{
   
   switch(nd_type(node)){
   case NODE_ATTRASGN:{
@@ -2447,10 +2449,9 @@
   case NODE_MASGN:{
     NODE *rhsn = node->nd_value;
     NODE *lhsn = node->nd_head;
-    DECL_ANCHOR(mlhs_seq);
-    
     int rlen, llen, i, max, si = 0;
     VALUE lhs_splat = Qfalse;
+    DECL_ANCHOR(mlhs_seq);
 
     llen = 0;
     while(lhsn){
@@ -2463,13 +2464,14 @@
       make_masgn_lhs(self, iseqobj, mlhs_seq, node->nd_args);
       lhs_splat = Qtrue;
     }
-    
-    
+
+    if(rhsn != 0){
     switch(nd_type(rhsn)){
     case NODE_ARRAY:
       rlen = rhsn->nd_alen;
       max = rlen > llen ? rlen : llen;
       debugs("l: %d, r: %d\n", llen, rlen);
+
       for(i=0; i<max; i++){
         if(i<rlen && i<llen){
           /* a, b = c, d*/
@@ -2496,7 +2498,7 @@
           ADD_INSN(ret, nd_line(node), putnil);
         }
       }
-      
+
       if(lhs_splat){
         ADD_INSN1(ret, nd_line(node), newarray, I2F(si));
       }
@@ -2505,7 +2507,7 @@
       COMPILE  (ret, "rhs to ary", rhsn->nd_head);
       ADD_INSN2(ret, nd_line(node), expandarray, I2F(llen), lhs_splat);
       break;
-      
+
     case NODE_SPLAT:
       COMPILE  (ret, "rhs to ary (splat)", rhsn->nd_head);
       ADD_INSN2(ret, nd_line(node), expandarray, I2F(llen), lhs_splat);
@@ -2514,7 +2516,7 @@
     case NODE_ARGSCAT:{
       NODE *ary = rhsn->nd_head;
       int idx = 0;
-      
+
       while(ary){
         if(idx < llen || lhs_splat){
           COMPILE(ret, "rhs aggscat each head", ary->nd_head);
@@ -2539,6 +2541,10 @@
     default:
       rb_bug("unknown rhs: %s", node_name(nd_type(node->nd_value)));
     }
+    }
+    else{
+      printf("??");
+    }
     ADD_SEQ(ret, REVERSE_LIST(mlhs_seq));
 
     if(!poped){
@@ -2573,7 +2579,7 @@
     if(nd_type(node) == NODE_DASGN_CURR &&
        lv > 0 &&
        iseqobj->type != ISEQ_TYPE_RESCUE){
-      rb_bug("NODE_DASGN_CURR, but lv != 0 (%d)", lv);
+      rb_bug("NODE_DASGN_CURR, but lv == %d (line: %d)", lv, nd_line(node));
     }
     
     if(idx < 0){

Modified: trunk/eval.c
===================================================================
--- trunk/eval.c	2005-08-16 00:10:54 UTC (rev 242)
+++ trunk/eval.c	2005-08-16 01:26:27 UTC (rev 243)
@@ -3198,7 +3198,7 @@
                            RARRAY(val)->len, RARRAY(val)->ptr);
   }
   else{
-    int argc = 1;
+    int argc = (val == Qundef) ? 0 : 1;
     VALUE *argv = &val;
 
     if(argc == 1 && CLASS_OF(argv[0]) == rb_cValues){

Added: trunk/lib/shellwords.rb
===================================================================
--- trunk/lib/shellwords.rb	2005-08-16 00:10:54 UTC (rev 242)
+++ trunk/lib/shellwords.rb	2005-08-16 01:26:27 UTC (rev 243)
@@ -0,0 +1,60 @@
+#
+# shellwords.rb: Split text into an array of tokens a la UNIX shell
+#
+
+#
+# This module is originally a port of shellwords.pl, but modified to
+# conform to POSIX / SUSv3 (IEEE Std 1003.1-2001).
+#
+# Examples:
+#
+#   require 'shellwords'
+#   words = Shellwords.shellwords(line)
+#
+# or
+#
+#   require 'shellwords'
+#   include Shellwords
+#   words = shellwords(line)
+#
+module Shellwords
+
+  #
+  # Split text into an array of tokens in the same way the UNIX Bourne
+  # shell does.
+  #
+  # See the +Shellwords+ module documentation for an example.
+  #
+  def shellwords(line)
+    line = String.new(line) rescue
+      raise(ArgumentError, "Argument must be a string")
+    line.lstrip!
+    words = []
+    until line.empty?
+      field = ''
+      loop do
+	if line.sub!(/\A"(([^"\\]|\\.)*)"/, '') then
+	  snippet = $1.gsub(/\\(.)/, '\1')
+	elsif line =~ /\A"/ then
+	  raise ArgumentError, "Unmatched double quote: #{line}"
+	elsif line.sub!(/\A'([^']*)'/, '') then
+	  snippet = $1
+	elsif line =~ /\A'/ then
+	  raise ArgumentError, "Unmatched single quote: #{line}"
+	elsif line.sub!(/\A\\(.)?/, '') then
+	  snippet = $1 || '\\'
+	elsif line.sub!(/\A([^\s\\'"]+)/, '') then
+	  snippet = $1
+	else
+	  line.lstrip!
+	  break
+	end
+	field.concat(snippet)
+      end
+      words.push(field)
+    end
+    words
+  end
+
+  module_function :shellwords
+end

Modified: trunk/test1.rb
===================================================================
--- trunk/test1.rb	2005-08-16 00:10:54 UTC (rev 242)
+++ trunk/test1.rb	2005-08-16 01:26:27 UTC (rev 243)
@@ -1,30 +1,3 @@
-def iter args
-  yield args
-end
 
-iter([]){|a, b|
-  p [a, b]
-}
-iter([1]){|a, b|
-  p [a, b]
-}
-iter([1, 2]){|a, b|
-  p [a, b]
-}
-iter([1, 2, 3]){|a, b|
-  p [a, b]
-}
-
-iter([]){|a|
-  p [a]
-}
-iter([1]){|a|
-  p [a]
-}
-iter([1, 2]){|a|
-  p [a]
-}
-iter([1, 2, 3]){|a|
-  p [a]
-}
-
+a, (b, c) = [1, [2, 3]]
+p [a, b, c]


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

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