rubyx/lib/slot_machine/instruction/check.rb

22 lines
882 B
Ruby
Raw Normal View History

2019-10-03 20:07:55 +02:00
module SlotMachine
2018-03-19 16:49:26 +01:00
2019-10-03 20:07:55 +02:00
# A base class for conditions in SlotMachine
2018-03-19 16:49:26 +01:00
# Checks (if in code, compare in assm) jump or not, depending
# The logic we choose is closer to the code logic (the asm is reversed)
# When we write an if, the true is the next code, so the Check logic is
# that if the check passes, no jump happens
# This means you need to pass the false label, where to jump to if the
# check does not pass
# Note: In assembler a branch on 0 does just that, it branches if the condition
# is met. This means that the asm implementation is somewhat the reverse
2019-10-03 20:07:55 +02:00
# of the SlotMachine names. But it's easier to understand (imho)
2018-03-19 16:49:26 +01:00
class Check < Instruction
attr_reader :false_jump
def initialize(false_jump)
@false_jump = false_jump
raise "Jump target must be a label #{false_jump}" unless false_jump.is_a?(Label)
end
end
end