Class: Mapleseed::MathRing

Inherits:
Ring
  • Object
show all
Defined in:
lib/mapleseed/ring.rb

Overview

command ring for whirl math operations

Instance Attribute Summary

Attributes inherited from Ring

#commands, #direction, #position, #value

Instance Method Summary collapse

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

#addObject

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

#divObject

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

#equalObject

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

#gtObject

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

#loadObject

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

#ltObject

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

#multObject

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

#negObject

inverse ring value



210
211
212
# File 'lib/mapleseed/ring.rb', line 210

def neg
	@value *= -1
end

#noopObject

do nothing



139
140
141
# File 'lib/mapleseed/ring.rb', line 139

def noop
	#...
end

#notObject

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

#storeObject

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

#zeroObject

set ring value to 0



169
170
171
# File 'lib/mapleseed/ring.rb', line 169

def zero
	@value = 0
end