module Affect::Cont
Public Instance Methods
abort(v)
click to toggle source
# File lib/affect/cont.rb, line 16 def abort(v) (@@stack.pop)[1].(v) end
capture(&block)
click to toggle source
# File lib/affect/cont.rb, line 20 def capture(&block) callcc { |outer| @@stack << [true, outer] abort(block.()) } end
escape() { |cont_proc| ... }
click to toggle source
# File lib/affect/cont.rb, line 27 def escape callcc do |esc| unwound_continuations = unwind_stack cont_proc = lambda { |v| callcc do |ret| @@stack << [true, ret] unwound_continuations.each { |c| @@stack << [nil, c] } esc.call(v) end } abort(yield(cont_proc)) end end
unwind_stack()
click to toggle source
# File lib/affect/cont.rb, line 41 def unwind_stack unwound = [] while @@stack.last && !(@@stack.last)[0] unwound << (@@stack.pop)[1] end unwound.reverse end