[#24536] 「Rubyの落し方」 v.s. ruby_1_8 — akira yamada / やまだあきら <akira@...>

<URL:http://jp.rubyist.net/magazine/?0002-RubyCore>

40 messages 2004/10/20
[#24541] Re: 「Rubyの落し方」 v.s. ruby_1_8 — Yukihiro Matsumoto <matz@...> 2004/10/20

まつもと ゆきひろです

[#24599] 1.8.2 preview3? — akira yamada / やまだあきら <akira@...> 2004/10/26

2004-10-20 (水) の 21:38 +0900 に Yukihiro Matsumoto さんは書きました:

[#24605] Re: 1.8.2 preview3? — akira yamada / やまだあきら <akira@...> 2004/10/27

2004-10-26 (火) の 16:16 +0900 に akira yamada / やまだあきら さんは書きました:

[#24606] Re: 1.8.2 preview3? — Yukihiro Matsumoto <matz@...> 2004/10/27

まつもと ゆきひろです

[#24608] Re: 1.8.2 preview3? — akira yamada / やまだあきら <akira@...> 2004/10/27

2004-10-27 (水) の 11:48 +0900 に Yukihiro Matsumoto さんは書きました:

[#24620] Re: 1.8.2 preview3? — akira yamada / やまだあきら <akira@...> 2004/10/27

2004-10-27 (水) の 12:42 +0900 に akira yamada / やまだあきら さんは書きました:

[#24629] Re: 1.8.2 preview3? — Tanaka Akira <akr@...17n.org> 2004/10/29

In article <1098888819.9446.14.camel@rice.p.arika.org>,

[ruby-dev:24407] omitting call

From: nobu@...
Date: 2004-10-03 14:37:03 UTC
List: ruby-dev #24407
なかだです。

http://www.rubyist.net/~matz/20040910.html#p02 を実装してみまし
た。しかし、動かなくなるコードも意外とありそうな気がします。


Index: parse.y
===================================================================
RCS file: /cvs/ruby/src/ruby/parse.y,v
retrieving revision 1.348
diff -U2 -p -d -r1.348 parse.y
--- parse.y	2 Oct 2004 11:34:13 -0000	1.348
+++ parse.y	3 Oct 2004 09:00:09 -0000
@@ -242,5 +242,6 @@ static NODE *ret_args();
 static NODE *arg_blk_pass();
 static NODE *new_call();
-static NODE *new_fcall();
+static NODE *new_fcall_gen _((struct parser_params*,ID,NODE*));
+#define new_fcall(id,args) new_fcall_gen(parser,id,args)
 static NODE *new_super();
 static NODE *new_yield();
@@ -526,4 +527,5 @@ static void ripper_compile_error _((stru
 %token tSTAR		/* * */
 %token tAMPER		/* & */
+%token tCALL		/* () */
 %token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG
 %token tSTRING_DBEG tSTRING_DVAR tSTRING_END
@@ -1560,4 +1562,5 @@ op		: '|'		{ $$ = symbol('|'); }
 		| tASET		{ $$ = symbol(tASET); }
 		| '`'		{ $$ = symbol('`'); }
+		| tCALL		{ $$ = symbol(tCALL); }
 		;
 
@@ -2539,5 +2542,5 @@ primary		: literal
 		    {
 		    /*%%%*/
-			$2->nd_iter = NEW_FCALL($1, 0);
+			$2->nd_iter = new_fcall($1, 0);
 			$$ = $2;
 			fixpos($2->nd_iter, $2);
@@ -6005,4 +6008,9 @@ parser_yylex(parser)
 	    c = tLPAREN;
 	}
+	else if (lex_state == EXPR_FNAME && peek(')')) {
+	    nextc();
+	    lex_state = EXPR_ARG;
+	    return tCALL;
+	}
 	else if (space_seen) {
 	    if (lex_state == EXPR_CMDARG) {
@@ -7535,8 +7543,17 @@ new_call(r,m,a)
 
 static NODE*
-new_fcall(m,a)
+new_fcall_gen(parser, m, a)
+    struct parser_params *parser;
     ID m;
     NODE *a;
 {
+    if (is_local_id(m)) {
+	if (dyna_in_block() && rb_dvar_defined(m)) {
+	    return new_call(NEW_DVAR(m), tCALL, a);
+	}
+	if (local_id(m)) {
+	    return new_call(NEW_LVAR(m), tCALL, a);
+	}
+    }
     if (a && nd_type(a) == NODE_BLOCK_PASS) {
 	a->nd_iter = NEW_FCALL(m,a->nd_head);
@@ -7852,4 +7869,5 @@ static struct {
     {tCOLON2,	"::"},
     {'`',	"`"},
+    {tCALL,	"()"},
     {0,	0}
 };
Index: sample/test.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/sample/test.rb,v
retrieving revision 1.89
diff -U2 -p -d -r1.89 test.rb
--- sample/test.rb	25 May 2004 02:54:22 -0000	1.89
+++ sample/test.rb	3 Oct 2004 08:45:12 -0000
@@ -1122,9 +1122,9 @@ test_ok(block.clone.call == 11)
 test_ok(get_block(&block).class == Proc)
 
-lambda = lambda{44}
-test_ok(lambda.class == Proc)
-test_ok(lambda.to_proc.class == Proc)
-test_ok(lambda.clone.call == 44)
-test_ok(get_block(&lambda).class == Proc)
+l = lambda{44}
+test_ok(l.class == Proc)
+test_ok(l.to_proc.class == Proc)
+test_ok(l.clone.call == 44)
+test_ok(get_block(&l).class == Proc)
 
 test_ok(Proc.new{|a,| a}.call(1,2,3) == 1)
@@ -1326,6 +1326,6 @@ test_ok(test_b15{|e| break 155 } == 155)
 
 def marity_test(m)
-  method = method(m)
-  test_ok(method.arity == method.to_proc.arity, 2)
+  m = method(m)
+  test_ok(m.arity == m.to_proc.arity, 2)
 end
 marity_test(:test_ok)
Index: test/ruby/test_iterator.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/test/ruby/test_iterator.rb,v
retrieving revision 1.15
diff -U2 -p -d -r1.15 test_iterator.rb
--- test/ruby/test_iterator.rb	18 Mar 2004 10:08:24 -0000	1.15
+++ test/ruby/test_iterator.rb	3 Oct 2004 09:19:47 -0000
@@ -246,9 +246,9 @@ class TestIterator < Test::Unit::TestCas
     assert_instance_of(Proc, get_block(&block))
 
-    lambda = lambda{44}
-    assert_instance_of(Proc, lambda)
-    assert_instance_of(Proc, lambda.to_proc)
-    assert_equal(lambda.clone.call, 44)
-    assert_instance_of(Proc, get_block(&lambda))
+    lmd = lambda{44}
+    assert_instance_of(Proc, lmd)
+    assert_instance_of(Proc, lmd.to_proc)
+    assert_equal(lmd.clone.call, 44)
+    assert_instance_of(Proc, get_block(&lmd))
 
     assert_equal(1, Proc.new{|a,| a}.call(1,2,3))
@@ -311,16 +311,22 @@ class TestIterator < Test::Unit::TestCas
 
     block = get_block{11}
-    lambda = lambda{44}
     assert_equal(0, block.arity)
-    assert_equal(0, lambda.arity)
+    assert_equal(0, lambda{44}.arity)
     assert_equal(0, lambda{||}.arity)
     assert_equal(1, lambda{|a|}.arity)
     assert_equal(1, lambda{|a,|}.arity)
     assert_equal(2, lambda{|a,b|}.arity)
+    begin
+      get_block{break 45}.call
+    rescue LocalJumpError => e
+      assert_equal(45, e.exit_value)
+    else
+      assert(false)
+    end
   end
 
   def marity_test(m)
-    method = method(m)
-    assert_equal(method.arity, method.to_proc.arity)
+    m = method(m)
+    assert_equal(m.arity, m.to_proc.arity)
   end
 


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread

Prev Next