2019-10-03 20:07:55 +02:00
|
|
|
module SlotMachine
|
2017-09-14 15:07:02 +02:00
|
|
|
|
2019-10-03 20:07:55 +02:00
|
|
|
# SlotMachine internal check, as the name says to see if two values are not the same
|
2017-09-14 15:07:02 +02:00
|
|
|
# In other words, we this checks identity, bit-values, pointers
|
|
|
|
#
|
2020-02-11 10:19:52 +01:00
|
|
|
# The values that are compared are defined as Slots, ie can be anything
|
2017-09-14 15:07:02 +02:00
|
|
|
# available to the machine through frame message or self
|
|
|
|
#
|
2019-10-03 20:07:55 +02:00
|
|
|
# Acording to SlotMachine::Check logic, we jump to the given label is the values are the same
|
2018-03-24 16:54:15 +01:00
|
|
|
#
|
2017-09-14 15:07:02 +02:00
|
|
|
class NotSameCheck < Check
|
|
|
|
attr_reader :left , :right
|
|
|
|
|
2018-03-21 08:08:28 +01:00
|
|
|
def initialize(left, right , label)
|
|
|
|
super(label)
|
2017-09-14 15:07:02 +02:00
|
|
|
@left , @right = left , right
|
|
|
|
end
|
2018-03-13 11:46:06 +01:00
|
|
|
|
2018-04-17 19:26:15 +02:00
|
|
|
def to_s
|
|
|
|
"NotSameCheck: #{left}:#{right}"
|
|
|
|
end
|
|
|
|
|
2018-03-24 16:54:15 +01:00
|
|
|
# basically move both left and right values into register
|
|
|
|
# subtract them and see if IsZero comparison
|
2018-03-21 08:08:28 +01:00
|
|
|
def to_risc(compiler)
|
2018-08-19 12:18:25 +02:00
|
|
|
l_reg = left.to_register(compiler, self)
|
|
|
|
r_reg = right.to_register(compiler, self)
|
|
|
|
compiler.add_code Risc.op( self , :- , l_reg , r_reg)
|
2018-08-29 20:06:29 +02:00
|
|
|
compiler.add_code Risc::IsZero.new( self, false_jump.risc_label(compiler))
|
2018-03-13 11:46:06 +01:00
|
|
|
end
|
2017-09-14 15:07:02 +02:00
|
|
|
end
|
|
|
|
end
|