2019-10-03 21:07:55 +03:00
|
|
|
module SlotMachine
|
2018-03-19 21:19:26 +05:30
|
|
|
|
2019-10-03 21:07:55 +03:00
|
|
|
# A base class for conditions in SlotMachine
|
2018-03-19 21:19:26 +05:30
|
|
|
# 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 21:07:55 +03:00
|
|
|
# of the SlotMachine names. But it's easier to understand (imho)
|
2018-03-19 21:19:26 +05:30
|
|
|
class Check < Instruction
|
2020-02-19 02:16:44 +07:00
|
|
|
attr_reader :false_label
|
|
|
|
|
|
|
|
def initialize(false_label)
|
|
|
|
set_label(false_label)
|
2018-03-19 21:19:26 +05:30
|
|
|
end
|
2020-02-19 02:16:44 +07:00
|
|
|
|
|
|
|
def set_label(false_label)
|
|
|
|
@false_label = false_label
|
2020-03-03 16:09:41 +02:00
|
|
|
raise "Jump target must be a label #{false_label}" unless false_label.is_a?(Label)
|
|
|
|
end
|
2018-03-19 21:19:26 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
end
|