From 7c2e1de6fc464da4928710af516983f0d607da9b Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 21 Dec 2003 07:28:54 +0000 Subject: Add file.c comments (and necessary support in parse_c.rb) git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@5234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- eval.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 6369df802..10d52d651 100644 --- a/eval.c +++ b/eval.c @@ -10134,8 +10134,70 @@ rb_thread_atfork() curr_thread->prev = curr_thread; } + +/* + * 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 + */ + static 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(self) VALUE self; @@ -10169,6 +10231,22 @@ rb_callcc(self) } } +/* + * 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(argc, argv, cont) int argc; -- cgit