[#4076] Re: call/cc — shugo@... (Shugo Maeda)

51 messages 1999/01/08
[#4077] Re: [ruby-list:11512] Re: call/cc — maeda@... 1999/01/08

前田@リコーです。

[#4078] Re: call/cc — shugo@... (Shugo Maeda) 1999/01/08

[#4079] Re: call/cc — kjana@... (YANAGAWA Kazuhisa) 1999/01/08

In message <m0zyZO8-0003EbC@crunkey.chocolate.or.jp>

[#4098] Re: call/cc — shugo@... (Shugo Maeda) 1999/01/11

[#4105] Re: call/cc — EGUCHI Osamu <eguchi@...> 1999/01/12

えぐち@エスアンドイー です。

[#4144] Re: call/cc — shugo@... (Shugo Maeda) 1999/01/13

[#4090] finalizers — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

19 messages 1999/01/11

[#4095] Ruby on CYGWIN — TAKAHASHI Masayoshi <maki@...>

高橋です。久しぶりに書きます。

26 messages 1999/01/11
[#4111] Re: Ruby on CYGWIN — WATANABE Hirofumi <watanabe@...> 1999/01/12

わたなべです.

[#4115] Re: Ruby on CYGWIN — TAKAHASHI Masayoshi <maki@...> 1999/01/12

高橋です。Rubyのリンク集から見つけたのですが、sgmailって

[#4118] sgmail (Re: Ruby on CYGWIN) — Takahiro Maebashi <maebashi@...> 1999/01/12

前橋です。

[#4123] Tk? Gtk? (Re: sgmail) — TAKAHASHI Masayoshi <maki@...> 1999/01/13

高橋です。

[#4203] Compile via WATCOM C — ARIMA Yasuhiro <fit0298@...>

有馬です。

20 messages 1999/01/18
[#4204] Re: Compile via WATCOM C — KIMURA Koichi <kimura@...> 1999/01/18

[#4248] patch for ruby-mswin32 — Koji Oda <oda@...1.qnes.nec.co.jp>

小田@QNES です。

27 messages 1999/01/19
[#4254] Re: patch for ruby-mswin32 — matz@... (Yukihiro Matsumoto) 1999/01/19

まつもと ゆきひろです

[#4256] Re: patch for ruby-mswin32 — WATANABE Hirofumi <watanabe@...> 1999/01/19

わたなべです.

[#4258] Re: patch for ruby-mswin32 — matz@... (Yukihiro Matsumoto) 1999/01/19

まつもと ゆきひろです

[#4290] signed/unsigned char — ARIMA Yasuhiro <fit0298@...>

有馬です。

17 messages 1999/01/20
[#4292] Re: signed/unsigned char — EGUCHI Osamu <eguchi@...> 1999/01/20

えぐち@エスアンドイー です。

[#4293] Re: signed/unsigned char — ARIMA Yasuhiro <fit0298@...> 1999/01/20

Regard to "[ruby-dev:4292] Re: signed/unsigned char"

[#4295] Re: signed/unsigned char — EGUCHI Osamu <eguchi@...> 1999/01/20

えぐち@エスアンドイー です。

[#4327] pack("F") for bigendian float — gotoken@... (GOTO Kentaro)

ごとけんです。

25 messages 1999/01/22
[#4330] Re: pack("F") for bigendian float — gotoken@... (GOTO Kentaro) 1999/01/23

ごとけんです

[#4331] Re: pack("F") for bigendian float — gotoken@... (GOTO Kentaro) 1999/01/23

ごとけんです

[#4336] Re: pack("F") for bigendian float — matz@... (Yukihiro Matsumoto) 1999/01/24

まつもと ゆきひろです

[#4337] Re: pack("F") for bigendian float — gotoken@... (GOTO Kentaro) 1999/01/24

ごとけんです

[#4338] Re: pack("F") for bigendian float — Yamashita Junji (山下 純司) <ys_jyunji@...> 1999/01/24

山下 純司です。

[#4341] cascades on ruby — Kazunori NISHI <kazunori@...>

西@九大です。

51 messages 1999/01/25
[#4342] Re: cascades on ruby — Kazuhiro HIWADA <hiwada@...> 1999/01/25

ひわだです。

[#4343] Re: cascades on ruby — Kazunori NISHI <kazunori@...> 1999/01/25

西@九大です。

[#4344] Re: cascades on ruby — matz@... (Yukihiro Matsumoto) 1999/01/25

まつもと ゆきひろです

[#4386] Re: cascades on ruby — keiju@... (石塚圭樹 ) 1999/01/26

けいじゅ@日本ラショナルソフトウェアです.

[#4389] Re: cascades on ruby — matz@... (Yukihiro Matsumoto) 1999/01/26

まつもと ゆきひろです

[#4394] Re: cascades on ruby — keiju@... (石塚圭樹 ) 1999/01/26

けいじゅ@日本ラショナルソフトウェアです.

[#4396] keyword argument (Re: Re: cascades on ruby) — matz@... (Yukihiro Matsumoto) 1999/01/26

[#4399] Re: keyword argument (Re: Re: cascades on ruby) — keiju@... (石塚圭樹 ) 1999/01/26

けいじゅ@日本ラショナルソフトウェアです.

[#4400] Re: keyword argument (Re: Re: cascades on ruby) — matz@... (Yukihiro Matsumoto) 1999/01/26

まつもと ゆきひろです

[#4401] Re: keyword argument (Re: Re: cascades on ruby) — keiju@... (石塚圭樹 ) 1999/01/26

けいじゅ@日本ラショナルソフトウェアです.

[#4404] Re: keyword argument (Re: Re: cascades on ruby) — matz@... (Yukihiro Matsumoto) 1999/01/26

まつもと ゆきひろです

[#4410] Re: keyword argument (Re: Re: cascades on ruby) — keiju@... (石塚圭樹 ) 1999/01/26

けいじゅ@日本ラショナルソフトウェアです.

[#4412] Re: keyword argument (Re: Re: cascades on ruby) — matz@... (Yukihiro Matsumoto) 1999/01/26

まつもと ゆきひろです

[#4473] Re: keyword argument (Re: Re: cascades on ruby) — matz@... (Yukihiro Matsumoto) 1999/01/28

まつもと ゆきひろです

[#4495] Re: keyword argument (Re: Re: cascades on ruby) — shugo@... (Shugo Maeda) 1999/01/29

前田です。

[#4349] Re: [ruby-list:11707] Re: ruby 1.2.2 released — EGUCHI Osamu <eguchi@...>

えぐち@エスアンドイー です。

35 messages 1999/01/25
[#4353] Re: [ruby-list:11707] Re: ruby 1.2.2 released — EGUCHI Osamu <eguchi@...> 1999/01/25

えぐち@エスアンドイー です。

[#4357] --enable-shared/BSD (Re: ) — EGUCHI Osamu <eguchi@...> 1999/01/25

えぐち@エスアンドイー です。

[#4375] Re: --enable-shared/BSD (Re: ) — matz@... (Yukihiro Matsumoto) 1999/01/26

まつもと ゆきひろです

[#4387] Re: --enable-shared/BSD (Re: ) — EGUCHI Osamu <eguchi@...> 1999/01/26

えぐち@エスアンドイー です。

[#4391] Re: --enable-shared/BSD (Re: ) — matz@... (Yukihiro Matsumoto) 1999/01/26

まつもと ゆきひろです

[#4406] Re: --enable-shared/BSD (Re: ) — EGUCHI Osamu <eguchi@...> 1999/01/26

えぐち@エスアンドイー です。

[#4419] Re: module Precision — Inaba Hiroto <inaba@...>

21 messages 1999/01/26
[#4438] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/01/27

ごとけんです

[#4451] Re: module Precision — Inaba Hiroto <inaba@...> 1999/01/27

From: gotoken@math.sci.hokudai.ac.jp (GOTO Kentaro)

[#4453] new class for float of C (Re: module Precision) — gotoken@... (GOTO Kentaro) 1999/01/27

ごとけんです

[#4457] Re: new class for float of C (Re: module Precision) — matz@... (Yukihiro Matsumoto) 1999/01/28

まつもと ゆきひろです

[#4460] Re: new class for float of C (Re: module Precision) — gotoken@... (GOTO Kentaro) 1999/01/28

ごとけんです

[#4461] Re: new class for float of C (Re: module Precision) — matz@... (Yukihiro Matsumoto) 1999/01/28

まつもと ゆきひろです

[#4462] Re: new class for float of C (Re: module Precision) — gotoken@... (GOTO Kentaro) 1999/01/28

ごとけんです

[#4420] ruby 1.3.1-990126 — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

17 messages 1999/01/26

[#4452] permit to put a comma — Koji Arai <JCA02266@...>

新井です。

18 messages 1999/01/27
[#4484] Re: permit to put a comma — matz@... (Yukihiro Matsumoto) 1999/01/29

まつもと ゆきひろです

[#4518] Inf.0 — gotoken@... (GOTO Kentaro)

ごとけんです

17 messages 1999/01/30

[ruby-dev:4206] Re: callcc

From: shugo@... (Shugo Maeda)
Date: 1999-01-18 08:07:08 UTC
List: ruby-dev #4206
前田です。

shugo@aianet.ne.jp (Shugo Maeda) writes:

> > しかし、やっぱ、もっとうまい方法が欲しい気がしますね…。
> 
> ちょっと思うところがあるので試してみます。
> # 反応がなかったら失敗したと思ってください(^^;

callccを使わない場合には効率がほとんど落ちないようにしました。
とりあえず試した範囲ではうまく行っているようです。
# 他にもSCOPE_DONT_RECYCLEをセットしないといけないところが
# ありそうですけど...。

ruby-1.3からのパッチです。
# ついでにcall_ccからcallccに変えました。


-- 
前田 修吾 (mailto:shugo@aianet.ne.jp)

Attachments (1)

eval.c.diff (3.2 KB, text/x-diff)
--- eval.c.orig	Sat Jan 16 13:55:30 1999
+++ eval.c	Mon Jan 18 16:55:31 1999
@@ -641,15 +641,26 @@
     ruby_scope = _scope;		\
     scope_vmode = SCOPE_PUBLIC;
 
+#define SCOPE_DONT_RECYCLE FL_USER2
+
+static void scope_dup(struct SCOPE *);
+
 #define POP_SCOPE() \
     if (ruby_scope->flag == SCOPE_ALLOCA) {\
-	ruby_scope->local_vars = 0;\
-	ruby_scope->local_tbl  = 0;\
-	if (ruby_scope != top_scope)\
-            rb_gc_force_recycle((VALUE)ruby_scope);\
+	if (FL_TEST(ruby_scope, SCOPE_DONT_RECYCLE)) {\
+	    if (ruby_scope->flag == SCOPE_ALLOCA)\
+		scope_dup(ruby_scope);\
+	    FL_SET(_old, SCOPE_DONT_RECYCLE);\
+	}\
+	else {\
+	    ruby_scope->local_vars = 0;\
+	    ruby_scope->local_tbl  = 0;\
+	    if (ruby_scope != top_scope)\
+		rb_gc_force_recycle((VALUE)ruby_scope);\
+	}\
     }\
     else {\
-        ruby_scope->flag |= SCOPE_NOSTACK;\
+	ruby_scope->flag |= SCOPE_NOSTACK;\
     }\
     ruby_scope = _old;\
     scope_vmode = _vmode;\
@@ -3103,6 +3114,8 @@
     POP_VARS();
     ruby_block = block;
     ruby_frame = ruby_frame->prev;
+    if (FL_TEST(ruby_scope, SCOPE_DONT_RECYCLE))
+	FL_SET(old_scope, SCOPE_DONT_RECYCLE);
     ruby_scope = old_scope;
     if (state) JUMP_TAG(state);
     return result;
@@ -4084,6 +4097,8 @@
     rb_in_eval--;
     if (!NIL_P(scope)) {
 	ruby_frame = ruby_frame->prev;
+	if (FL_TEST(ruby_scope, SCOPE_DONT_RECYCLE))
+	    FL_SET(old_scope, SCOPE_DONT_RECYCLE);
 	ruby_scope = old_scope;
 	ruby_block = old_block;
 	ruby_calling_block = old_call_block;
@@ -6816,6 +6831,77 @@
     }
 }
 
+static VALUE rb_cContinuation;
+
+static VALUE
+rb_callcc(self)
+    VALUE self;
+{
+    thread_t th = ALLOC(struct thread);
+
+    th->status = THREAD_RUNNABLE;
+
+    th->status = 0;
+    th->result = 0;
+    th->rb_errinfo = Qnil;
+
+    th->stk_ptr = 0;
+    th->stk_len = 0;
+    th->stk_max = 0;
+    th->wait_for = 0;
+    th->fd = 0;
+    th->delay = 0.0;
+    th->join = 0;
+
+    th->frame = 0;
+    th->scope = 0;
+    th->klass = 0;
+    th->dyna_vars = 0;
+    th->block = 0;
+    th->iter = 0;
+    th->tag = 0;
+    th->rb_errinfo = 0;
+    th->last_status = 0;
+    th->last_line = 0;
+    th->last_match = 0;
+    th->abort = 0;
+
+    th->thread = Data_Wrap_Struct(rb_cContinuation, thread_mark,
+				  thread_free, th);
+
+    FL_SET(ruby_scope, SCOPE_DONT_RECYCLE);
+    rb_thread_save_context(th);
+    if (setjmp(th->context)) {
+	return th->result;
+    }
+    else {
+	return rb_yield(th->thread);
+    }
+}
+
+static VALUE
+rb_continuation_call(argc, argv, cont)
+    int argc;
+    VALUE *argv;
+    VALUE cont;
+{
+    thread_t th = rb_thread_check(cont);
+
+    switch (argc) {
+    case 0:
+	th->result = Qnil;
+	break;
+    case 1:
+	th->result = *argv;
+	break;
+    default:
+	th->result = rb_ary_new4(argc, argv);
+	break;
+    }
+    rb_thread_restore_context(th, 0);
+    return Qnil;
+}
+
 void
 Init_Thread()
 {
@@ -6855,6 +6941,11 @@
 
     /* allocate main thread */
     main_thread = rb_thread_alloc(rb_cThread);
+
+    rb_cContinuation = rb_define_class("Continuation", rb_cObject);
+    rb_undef_method(CLASS_OF(rb_cContinuation), "new");
+    rb_define_method(rb_cContinuation, "call", rb_continuation_call, -1);
+    rb_define_method(rb_mKernel, "callcc", rb_callcc, 0);
 }
 #endif
 

In This Thread