From 7c4ff2d3322753479b3974105e5100b6f4e43001 Mon Sep 17 00:00:00 2001 From: ko1 Date: Wed, 23 May 2007 22:52:19 +0000 Subject: * cont.c: support callcc which everyone love. incomplete. please give me bug reports. * common.mk, inits.c, thread.c: ditto. * yarvcore.c: export thread_mark(). * yarvcore.h: disable value cache option. * eval_intern.h: set th_get_ruby_level_cfp to inline. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread.c | 101 --------------------------------------------------------------- 1 file changed, 101 deletions(-) (limited to 'thread.c') diff --git a/thread.c b/thread.c index 230439b722..296e6eb146 100644 --- a/thread.c +++ b/thread.c @@ -2444,100 +2444,6 @@ rb_barrier_release(VALUE self) return n ? UINT2NUM(n) : Qfalse; } - -/* - * Document-class: Continuation - * - * Continuation objects are generated by - * Kernel#callcc. They hold a return address and execution - * context, allowing a nonlocal return to the end of the - * callcc block from anywhere within a program. - * Continuations are somewhat analogous to a structured version of C's - * setjmp/longjmp (although they contain more state, so - * you might consider them closer to threads). - * - * For instance: - * - * arr = [ "Freddie", "Herbie", "Ron", "Max", "Ringo" ] - * callcc{|$cc|} - * puts(message = arr.shift) - * $cc.call unless message =~ /Max/ - * - * produces: - * - * Freddie - * Herbie - * Ron - * Max - * - * This (somewhat contrived) example allows the inner loop to abandon - * processing early: - * - * callcc {|cont| - * for i in 0..4 - * print "\n#{i}: " - * for j in i*5...(i+1)*5 - * cont.call() if j == 17 - * printf "%3d", j - * end - * end - * } - * print "\n" - * - * produces: - * - * 0: 0 1 2 3 4 - * 1: 5 6 7 8 9 - * 2: 10 11 12 13 14 - * 3: 15 16 - */ - -VALUE rb_cCont; - -/* - * call-seq: - * callcc {|cont| block } => obj - * - * Generates a Continuation object, which it passes to the - * associated block. Performing a cont.call will - * cause the callcc to return (as will falling through the - * end of the block). The value returned by the callcc is - * the value of the block, or the value passed to - * cont.call. See class Continuation - * for more details. Also see Kernel::throw for - * an alternative mechanism for unwinding a call stack. - */ - -static VALUE -rb_callcc(VALUE self) -{ - rb_notimplement(); - return Qnil; -} - -/* - * call-seq: - * cont.call(args, ...) - * cont[args, ...] - * - * Invokes the continuation. The program continues from the end of the - * callcc block. If no arguments are given, the original - * callcc returns nil. If one argument is - * given, callcc returns it. Otherwise, an array - * containing args is returned. - * - * callcc {|cont| cont.call } #=> nil - * callcc {|cont| cont.call 1 } #=> 1 - * callcc {|cont| cont.call 1, 2, 3 } #=> [1, 2, 3] - */ - -static VALUE -rb_cont_call(int argc, VALUE *argv, VALUE cont) -{ - rb_notimplement(); - return Qnil; -} - /* variables for recursive traversals */ static ID recursive_key; @@ -3001,13 +2907,6 @@ Init_Thread(void) recursive_key = rb_intern("__recursive_key__"); rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError); - rb_cCont = rb_define_class("Continuation", rb_cObject); - rb_undef_alloc_func(rb_cCont); - rb_undef_method(CLASS_OF(rb_cCont), "new"); - rb_define_method(rb_cCont, "call", rb_cont_call, -1); - rb_define_method(rb_cCont, "[]", rb_cont_call, -1); - rb_define_global_function("callcc", rb_callcc, 0); - /* trace */ rb_define_global_function("set_trace_func", set_trace_func, 1); rb_define_method(rb_cThread, "set_trace_func", thread_set_trace_func_m, 1); -- cgit v1.2.3