class Mapleseed::OpRing
command ring for whirl operations
Public Class Methods
new(interpreter)
click to toggle source
initialize commands for operation ring
Calls superclass method
Mapleseed::Ring::new
# File lib/mapleseed/ring.rb, line 42 def initialize(interpreter) super(interpreter) @commands = [:noop, :exit, :one, :zero, :load, :store, :p_add, :d_add, :logic, :if, :int_io, :asc_io] end
Public Instance Methods
asc_io()
click to toggle source
if ring value is 0, set memory value to character input, otherwise print memory value as an character
# File lib/mapleseed/ring.rb, line 119 def asc_io if @value == 0 str = @interpreter.input_stream.getc @interpreter.memory.set(@interpreter.memory_position, str) else @interpreter.output_stream.putc @interpreter.memory.get(@interpreter.memory_position) end end
d_add()
click to toggle source
change location in memory
# File lib/mapleseed/ring.rb, line 86 def d_add @interpreter.memory_position += @value end
exit()
click to toggle source
exit the program
# File lib/mapleseed/ring.rb, line 53 def exit throw :quit end
if()
click to toggle source
if value in memory is not 0, add ring value to program position
# File lib/mapleseed/ring.rb, line 100 def if if @interpreter.memory.get(@interpreter.memory_position) != 0 p_add end end
int_io()
click to toggle source
if ring value is 0, set memory value to integer input, otherwise print memory value as an integer
# File lib/mapleseed/ring.rb, line 108 def int_io if @value == 0 str = @interpreter.input_stream.gets.chomp @interpreter.memory.set(@interpreter.memory_position, str.to_i) else @interpreter.output_stream.print @interpreter.memory.get(@interpreter.memory_position) end end
load()
click to toggle source
set the ring value to the current memory value
# File lib/mapleseed/ring.rb, line 68 def load @value = @interpreter.memory.get(@interpreter.memory_position) end
logic()
click to toggle source
logical AND
# File lib/mapleseed/ring.rb, line 91 def logic if @interpreter.memory.get(@interpreter.memory_position) != 0 and @value != 0 @value = 1 else @value = 0 end end
noop()
click to toggle source
do nothing
# File lib/mapleseed/ring.rb, line 48 def noop #... end
one()
click to toggle source
set the ring value to 1
# File lib/mapleseed/ring.rb, line 58 def one @value = 1 end
p_add()
click to toggle source
change location in the program
# File lib/mapleseed/ring.rb, line 78 def p_add @interpreter.program_position += @value - 1 if @interpreter.program_position < 0 @interpreter.program_position = 0 end end
store()
click to toggle source
set the current value in memory to the ring value
# File lib/mapleseed/ring.rb, line 73 def store @interpreter.memory.set(@interpreter.memory_position, @value) end
zero()
click to toggle source
set the ring value to 0
# File lib/mapleseed/ring.rb, line 63 def zero @value = 0 end