Class: Mapleseed::MathRing
Overview
command ring for whirl math operations
Instance Attribute Summary
Attributes inherited from Ring
#commands, #direction, #position, #value
Instance Method Summary collapse
-
#add ⇒ Object
set ring value += memory value.
-
#div ⇒ Object
set ring value /= memory value.
-
#equal ⇒ Object
if ring value is equal to memory value, set value to 1, otherwise 0.
-
#gt ⇒ Object
if ring value is greater than memory value, set value to 1, otherwise 0.
-
#initialize(interpreter) ⇒ MathRing
constructor
initialize commands for math ring.
-
#load ⇒ Object
set the ring value to the current memory value.
-
#lt ⇒ Object
if ring value is less than memory value, set value to 1, otherwise 0.
-
#mult ⇒ Object
set ring value *= memory value.
-
#neg ⇒ Object
inverse ring value.
-
#noop ⇒ Object
do nothing.
-
#not ⇒ Object
if ring value is not 0, set value to 1, otherwise 0.
-
#store ⇒ Object
set the current value in memory to the ring value.
-
#zero ⇒ Object
set ring value to 0.
Methods inherited from Ring
#execute, #rotate, #switch_direction
Constructor Details
#initialize(interpreter) ⇒ MathRing
initialize commands for math ring
133 134 135 136 |
# File 'lib/mapleseed/ring.rb', line 133 def initialize(interpreter) super(interpreter) @commands = [:noop, :load, :store, :add, :mult, :div, :zero, :lt, :gt, :equal, :not, :neg] end |
Instance Method Details
#add ⇒ Object
set ring value += memory value
154 155 156 |
# File 'lib/mapleseed/ring.rb', line 154 def add @value += @interpreter.memory.get(@interpreter.memory_position) end |
#div ⇒ Object
set ring value /= memory value
164 165 166 |
# File 'lib/mapleseed/ring.rb', line 164 def div @value /= @interpreter.memory.get(@interpreter.memory_position) end |
#equal ⇒ Object
if ring value is equal to memory value, set value to 1, otherwise 0
192 193 194 195 196 197 198 |
# File 'lib/mapleseed/ring.rb', line 192 def equal if @value == @interpreter.memory.get(@interpreter.memory_position) @value = 1 else @value = 0 end end |
#gt ⇒ Object
if ring value is greater than memory value, set value to 1, otherwise 0
183 184 185 186 187 188 189 |
# File 'lib/mapleseed/ring.rb', line 183 def gt if @value > @interpreter.memory.get(@interpreter.memory_position) @value = 1 else @value = 0 end end |
#load ⇒ Object
set the ring value to the current memory value
144 145 146 |
# File 'lib/mapleseed/ring.rb', line 144 def load @value = @interpreter.memory.get(@interpreter.memory_position) end |
#lt ⇒ Object
if ring value is less than memory value, set value to 1, otherwise 0
174 175 176 177 178 179 180 |
# File 'lib/mapleseed/ring.rb', line 174 def lt if @value < @interpreter.memory.get(@interpreter.memory_position) @value = 1 else @value = 0 end end |
#mult ⇒ Object
set ring value *= memory value
159 160 161 |
# File 'lib/mapleseed/ring.rb', line 159 def mult @value *= @interpreter.memory.get(@interpreter.memory_position) end |
#neg ⇒ Object
inverse ring value
210 211 212 |
# File 'lib/mapleseed/ring.rb', line 210 def neg @value *= -1 end |
#noop ⇒ Object
do nothing
139 140 141 |
# File 'lib/mapleseed/ring.rb', line 139 def noop #... end |
#not ⇒ Object
if ring value is not 0, set value to 1, otherwise 0
201 202 203 204 205 206 207 |
# File 'lib/mapleseed/ring.rb', line 201 def not if @value == 0 @value = 1 else @value = 0 end end |
#store ⇒ Object
set the current value in memory to the ring value
149 150 151 |
# File 'lib/mapleseed/ring.rb', line 149 def store @interpreter.memory.set(@interpreter.memory_position, @value) end |
#zero ⇒ Object
set ring value to 0
169 170 171 |
# File 'lib/mapleseed/ring.rb', line 169 def zero @value = 0 end |