Class: Mapleseed::OpRing
Overview
command ring for whirl operations
Instance Attribute Summary
Attributes inherited from Ring
#commands, #direction, #position, #value
Instance Method Summary collapse
-
#asc_io ⇒ Object
if ring value is 0, set memory value to character input, otherwise print memory value as an character.
-
#d_add ⇒ Object
change location in memory.
-
#exit ⇒ Object
exit the program.
-
#if ⇒ Object
if value in memory is not 0, add ring value to program position.
-
#initialize(interpreter) ⇒ OpRing
constructor
initialize commands for operation ring.
-
#int_io ⇒ Object
if ring value is 0, set memory value to integer input, otherwise print memory value as an integer.
-
#load ⇒ Object
set the ring value to the current memory value.
-
#logic ⇒ Object
logical AND.
-
#noop ⇒ Object
do nothing.
-
#one ⇒ Object
set the ring value to 1.
-
#p_add ⇒ Object
change location in the program.
-
#store ⇒ Object
set the current value in memory to the ring value.
-
#zero ⇒ Object
set the ring value to 0.
Methods inherited from Ring
#execute, #rotate, #switch_direction
Constructor Details
#initialize(interpreter) ⇒ OpRing
initialize commands for operation ring
42 43 44 45 |
# 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 |
Instance Method Details
#asc_io ⇒ Object
if ring value is 0, set memory value to character input, otherwise print memory value as an character
119 120 121 122 123 124 125 126 |
# 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 ⇒ Object
change location in memory
86 87 88 |
# File 'lib/mapleseed/ring.rb', line 86 def d_add @interpreter.memory_position += @value end |
#exit ⇒ Object
exit the program
53 54 55 |
# File 'lib/mapleseed/ring.rb', line 53 def exit throw :quit end |
#if ⇒ Object
if value in memory is not 0, add ring value to program position
100 101 102 103 104 |
# File 'lib/mapleseed/ring.rb', line 100 def if if @interpreter.memory.get(@interpreter.memory_position) != 0 p_add end end |
#int_io ⇒ Object
if ring value is 0, set memory value to integer input, otherwise print memory value as an integer
108 109 110 111 112 113 114 115 |
# 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 ⇒ Object
set the ring value to the current memory value
68 69 70 |
# File 'lib/mapleseed/ring.rb', line 68 def load @value = @interpreter.memory.get(@interpreter.memory_position) end |
#logic ⇒ Object
logical AND
91 92 93 94 95 96 97 |
# 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 ⇒ Object
do nothing
48 49 50 |
# File 'lib/mapleseed/ring.rb', line 48 def noop #... end |
#one ⇒ Object
set the ring value to 1
58 59 60 |
# File 'lib/mapleseed/ring.rb', line 58 def one @value = 1 end |
#p_add ⇒ Object
change location in the program
78 79 80 81 82 83 |
# 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 ⇒ Object
set the current value in memory to the ring value
73 74 75 |
# File 'lib/mapleseed/ring.rb', line 73 def store @interpreter.memory.set(@interpreter.memory_position, @value) end |
#zero ⇒ Object
set the ring value to 0
63 64 65 |
# File 'lib/mapleseed/ring.rb', line 63 def zero @value = 0 end |