Module: Torc

Defined in:
lib/torc.rb,
lib/torc/version.rb

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Instance Method Details

#recur(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/torc.rb', line 14

def recur(*args)
  name = binding.of_caller(1).eval('__method__')
  if _torc_state[:loop_stack].last == name
    _torc_state[:finished] = false
    return args
  else
    _torc_state[:loop_stack].push name
    begin
      begin
        _torc_state[:finished] = true
        args = __send__ name, *args
        if _torc_state[:swap_to]
          name, args = _torc_state[:swap_to]
          _torc_state[:swap_to] = nil
        end
      end until _torc_state[:finished]
      return args
    ensure
      _torc_state[:loop_stack].pop
    end
  end
end

#tail_call(name, *args) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/torc.rb', line 5

def tail_call(name, *args)
  if _torc_state[:loop_stack].empty?
    recur name, *args
  else
    _torc_state[:swap_to] = [name, args]
    _torc_state[:finished] = false
  end
end