[#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:4084] Re: call/cc

From: shugo@... (Shugo Maeda)
Date: 1999-01-09 14:44:27 UTC
List: ruby-dev #4084
前田です。

matz@netlab.co.jp (Yukihiro Matsumoto) writes:

> たぶんコンテキストの情報量は一緒です.普通はcall/ccのある言
> 語ではこれを使ってスレッドを実装するのは簡単なんですが,逆も
> 出来るかな.

以下の変更でとりあえず動きました。
# しかし問題が...。


call_cc {|c| $cont = c}
print "Hello, World!\n" 
$cont.call

のようなスクリプトを実行すると無限ループになります。

これはSchemeと同じ動作ではないのですが、それはさておき、irb上で、

irb(main):001:0> call_cc {|c| $cont = c}
#<Continuation:0x4015f7e0>
irb(main):002:0> print "Hello!\n"
Hello!
nil
irb(main):003:0> $cont.call
nil
irb(main):004:0> $cont
#<nil:0x4015f7e0>

などという不穏な動作をします。
# Continuationがnilになっている?

更に、

irb(main):001:0> cont = call_cc {|c| c}
#<Continuation:0x4015fc18>
irb(main):002:0> cont.call(cont)
/home/shugo/bin/irb.rb:417: [BUG] class path is not set properly
Aborted

とすると落ちてしまいます:-(

一体どこがまずいのでしょうか。

# irbでcall_ccした時に何が起こっているのか考えいたら頭がいたく
# なってきました。

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

Attachments (1)

eval.c.diff (1.91 KB, text/x-diff)
--- eval.c.orig	Fri Jan  8 16:09:02 1999
+++ eval.c	Sat Jan  9 23:17:34 1999
@@ -6816,6 +6816,77 @@
     }
 }
 
+static VALUE rb_cContinuation;
+
+static VALUE
+rb_call_cc(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_SHARED);
+    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 th->result;
+}
+
 void
 Init_Thread()
 {
@@ -6855,6 +6926,13 @@
 
     /* 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, "call_with_current_continuation",
+		     rb_call_cc, 0);
+    rb_define_alias(rb_mKernel, "call_cc", "call_with_current_continuation");
 }
 #endif
 

In This Thread