2016-12-11 13:06:09 +01:00
|
|
|
module Register
|
2016-12-25 17:11:58 +01:00
|
|
|
# Setter is a base class for set instructions (RegToSlot and RegToByte , possibly more coming)
|
2016-12-11 13:06:09 +01:00
|
|
|
#
|
2016-12-11 13:12:35 +01:00
|
|
|
# The instruction that is modelled is loading data from a register into an array
|
2016-12-11 13:06:09 +01:00
|
|
|
#
|
|
|
|
# Setter has a
|
2016-12-11 13:12:35 +01:00
|
|
|
# - Register that the data is comes from
|
|
|
|
# - an array where the data goes
|
2016-12-11 13:06:09 +01:00
|
|
|
# - and (array) index
|
2016-12-11 13:12:35 +01:00
|
|
|
|
|
|
|
# Getter and Setter api follow the pattern from -> to
|
|
|
|
|
2016-12-11 13:06:09 +01:00
|
|
|
class Setter < Instruction
|
|
|
|
|
|
|
|
# If you had a c array and index offset
|
|
|
|
# the instruction would do array[index] = register
|
|
|
|
# So Setter means the register (first argument) moves to the slot (array and index)
|
|
|
|
def initialize source , register , array , index
|
|
|
|
super(source)
|
|
|
|
@register = register
|
|
|
|
@array = array
|
|
|
|
@index = index
|
|
|
|
raise "index 0 " if index == 0
|
|
|
|
raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RegisterValue.look_like_reg(index)
|
|
|
|
raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
|
|
|
|
raise "Not register #{array}" unless RegisterValue.look_like_reg(array)
|
|
|
|
end
|
|
|
|
attr_accessor :register , :array , :index
|
|
|
|
|
2016-12-15 23:30:26 +01:00
|
|
|
def to_s
|
|
|
|
"#{self.class.name}: #{array}[#{index}] -> #{register}"
|
|
|
|
end
|
|
|
|
|
2016-12-11 13:06:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|