Module: Trith::Core::Execution
- Defined in:
- lib/trith/core/execution.rb
Overview
Execution control operators.
Instance Method Summary (collapse)
- - (Machine) branch(cond, thenop, elseop) (also: #if)
- - (Machine) call(quot)
- - (Machine) halt
- - (Machine) loop(quot)
- - (Machine) nop
- - (Machine) quote
- - (Machine) reset
- - (Machine) thrice(quot)
- - (Machine) times(quot, count)
- - (Machine) twice(quot)
- - (Machine) unless(cond, quot)
- - (Machine) until(quot, cond)
- - (Machine) when(cond, quot)
- - (Machine) while(quot, cond)
Instance Method Details
- (Machine) branch(cond, thenop, elseop) Also known as: if
136 137 138 139 140 141 142 |
# File 'lib/trith/core/execution.rb', line 136 def branch(cond, thenop, elseop) case cond when false, nil then unshift(elseop, :call) else unshift(thenop, :call) end self end |
- (Machine) call(quot)
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/trith/core/execution.rb', line 38 def call(quot) case quot when Array unshift(*quot) when Symbol unshift(quot) # FIXME else # TODO: error end self end |
- (Machine) halt
15 16 17 18 |
# File 'lib/trith/core/execution.rb', line 15 def halt @queue.clear self end |
- (Machine) loop(quot)
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/trith/core/execution.rb', line 95 def loop(quot) case quot when Array unshift(quot, :call, quot, :loop) when Symbol unshift(quot, [quot], :loop) # FIXME else # TODO: error end self end |
- (Machine) nop
22 23 24 |
# File 'lib/trith/core/execution.rb', line 22 def nop self # do nothing end |
- (Machine) quote
30 31 32 |
# File 'lib/trith/core/execution.rb', line 30 def quote push([shift]) end |
- (Machine) reset
7 8 9 10 11 |
# File 'lib/trith/core/execution.rb', line 7 def reset @stack.clear @queue.clear self end |
- (Machine) thrice(quot)
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/trith/core/execution.rb', line 80 def thrice(quot) with_saved_continuation(:thrice) do case quot when Array 3.times { unshift(quot, :call) } when Symbol 3.times { unshift([quot], :call) } # FIXME else # TODO: error end end end |
- (Machine) times(quot, count)
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/trith/core/execution.rb', line 51 def times(quot, count) with_saved_continuation(:times) do case quot when Array count.to_i.times { unshift(quot, :call) } when Symbol count.to_i.times { unshift([quot], :call) } # FIXME else # TODO: error end end end |
- (Machine) twice(quot)
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/trith/core/execution.rb', line 65 def twice(quot) with_saved_continuation(:twice) do case quot when Array 2.times { unshift(quot, :call) } when Symbol 2.times { unshift([quot], :call) } # FIXME else # TODO: error end end end |
- (Machine) unless(cond, quot)
157 158 159 160 161 162 163 |
# File 'lib/trith/core/execution.rb', line 157 def unless(cond, quot) case cond when false, nil then unshift(quot, :call) else # nop end self end |
- (Machine) until(quot, cond)
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/trith/core/execution.rb', line 122 def until(quot, cond) with_saved_continuation(:until) do Kernel.loop do # FIXME execute(cond) case pop when false, nil then execute(quot) else break end end end end |
- (Machine) when(cond, quot)
147 148 149 150 151 152 153 |
# File 'lib/trith/core/execution.rb', line 147 def when(cond, quot) case cond when false, nil then # nop else unshift(quot, :call) end self end |
- (Machine) while(quot, cond)
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/trith/core/execution.rb', line 108 def while(quot, cond) with_saved_continuation(:while) do Kernel.loop do # FIXME execute(cond) case pop when false, nil then break else execute(quot) end end end end |