[#41918] [Feature #3647] Array#sample(n, replace=false) — Kenta Murata <redmine@...>

Feature #3647: Array#sample(n, replace=false)

11 messages 2010/08/03

[#41966] [Bug #3673] PTY.getpty with IO.pipe doesn't finish on FreeBSD — Yui NARUSE <redmine@...>

Bug #3673: PTY.getpty with IO.pipe doesn't finish on FreeBSD

9 messages 2010/08/10

[#41969] [Feature #3675] String#prepend, String#>> — Sora Harakami <redmine@...>

Feature #3675: String#prepend, String#>>

15 messages 2010/08/10
[#41976] Re: [Feature #3675] String#prepend, String#>> — Yukihiro Matsumoto <matz@...> 2010/08/10

まつもと ゆきひろです

[#41974] Re: [ruby-cvs:36157] Ruby:r28955 (trunk): * complex.c (nucomp_to_[ifr]): don't allow complex with in-exact — Yukihiro Matsumoto <matz@...>

まつもと ゆきひろです

7 messages 2010/08/10

[#42003] WEBrickに関するセキュリティ修正 (CVE-2010-0541) — Hideki Yamane <henrich@...>

12 messages 2010/08/11

[#42090] Math::atan2(0, 0) on ruby 1.9.2 — KUBO Takehiro <kubo@...>

久保です。

18 messages 2010/08/22
[#42092] Re: Math::atan2(0, 0) on ruby 1.9.2 — Kenta Murata <muraken@...> 2010/08/22

=1B$B$`$i$?$G$9!#=1B(B

[#42166] Ruby'sライセンスの、BSDLとのデュアルライセンスへの変更 — "NARUSE, Yui" <naruse@...>

Ruby's ライセンスは BSDL と Ruby's のデュアルライセンスになります。

14 messages 2010/08/31

[ruby-dev:42129] Re: [Feature:trunk] argument delegation

From: Yusuke ENDOH <mame@...>
Date: 2010-08-24 15:30:26 UTC
List: ruby-dev #42129
遠藤です。

2010年6月17日6:31 Yukihiro Matsumoto <matz@ruby-lang.org>:
> が、もともとの動機とは別として、「&」1文字でそのコンテキスト
> のブロックを渡すのは、面白いアイディアだと思います。この場合
> は、仮引数リストのブロック引数がなくても、ブロックを渡すこと
> になるんですかね。


パッチを書いてみました。思ったより小さく書けました。

  def foo
    yield
  end

  def bar
    foo(&)
  end

  bar { p 1 }  #=> 1


カッコを省略した場合、

  foo &
  bar

というのが foo & bar なのか foo(&); bar なのか曖昧という問題が
ありました。が、互換性重視で foo & bar と解釈するようになってい
ます。というか書いてみたらそうなった。conflict は出ません。


diff --git a/compile.c b/compile.c
index 2fd804c..3f8c331 100644
--- a/compile.c
+++ b/compile.c
@@ -2863,8 +2863,13 @@ setup_args(rb_iseq_t *iseq, LINK_ANCHOR *args,
NODE *argn, unsigned long *flag)
     INIT_ANCHOR(arg_block);
     INIT_ANCHOR(args_splat);
     if (argn && nd_type(argn) == NODE_BLOCK_PASS) {
-	COMPILE(arg_block, "block", argn->nd_body);
-	*flag |= VM_CALL_ARGS_BLOCKARG_BIT;
+	if ((VALUE)argn->nd_body != (VALUE)-1) {
+	    COMPILE(arg_block, "block", argn->nd_body);
+	    *flag |= VM_CALL_ARGS_BLOCKARG_BIT;
+	}
+	else {
+	    *flag |= VM_CALL_ARGS_BLOCKTRGH_BIT;
+	}
 	argn = argn->nd_head;
     }

diff --git a/node.c b/node.c
index 65bc541..85574b4 100644
--- a/node.c
+++ b/node.c
@@ -621,7 +621,12 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node)
 	ANN("example: foo(x, &blk)");
 	F_NODE(nd_head, "other arguments");
 	LAST_NODE;
-	F_NODE(nd_body, "block argument");
+	if ((VALUE)node->nd_body != (VALUE)-1) {
+	    F_NODE(nd_body, "block argument");
+	}
+	else {
+	    F_MSG(nd_body, "block argument", "-1 (anonymous)");
+	}
 	break;

       case NODE_DEFN:
diff --git a/parse.y b/parse.y
index e085088..b0b946b 100644
--- a/parse.y
+++ b/parse.y
@@ -2459,6 +2459,14 @@ block_arg	: tAMPER arg_value
 			$$ = $2;
 		    %*/
 		    }
+		| tAMPER
+		    {
+		    /*%%%*/
+			$$ = NEW_BLOCK_PASS(-1);
+		    /*%
+			$$ = dispatch0(anonymous_block_arg);
+		    %*/
+		    }
 		;

 opt_block_arg	: ',' block_arg
diff --git a/vm_core.h b/vm_core.h
index 7676b2f..f0fa3a3 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -544,6 +544,7 @@ typedef struct {
 #define VM_CALL_TAILRECURSION_BIT  (0x01 << 6)
 #define VM_CALL_SUPER_BIT          (0x01 << 7)
 #define VM_CALL_OPT_SEND_BIT       (0x01 << 8)
+#define VM_CALL_ARGS_BLOCKTRGH_BIT (0x01 << 9)

 #define VM_SPECIAL_OBJECT_VMCORE       0x01
 #define VM_SPECIAL_OBJECT_CBASE        0x02
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 985a2fb..2a127d7 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -261,6 +261,10 @@ caller_setup_args(const rb_thread_t *th,
rb_control_frame_t *cfp, VALUE flag,
 		*block = blockptr;
 	    }
 	}
+	else if (flag & VM_CALL_ARGS_BLOCKTRGH_BIT) {
+	    rb_control_frame_t *reg_cfp = cfp;
+	    *block = GET_BLOCK_PTR();
+	}
 	else if (blockiseq) {
 	    blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp);
 	    blockptr->iseq = blockiseq;

-- 
Yusuke Endoh <mame@tsg.ne.jp>

In This Thread