2019-10-03 21:07:55 +03:00
|
|
|
module SlotMachine
|
2017-08-30 17:21:13 +03:00
|
|
|
|
2018-03-19 21:19:26 +05:30
|
|
|
# The funny thing about the ruby truth is that it is anything but false or nil
|
2017-08-30 17:21:13 +03:00
|
|
|
#
|
|
|
|
# To implement the normal ruby logic, we check for false or nil and jump
|
|
|
|
# to the false branch. true_block follows implicitly
|
|
|
|
#
|
2017-09-04 21:00:08 +03:00
|
|
|
class TruthCheck < Check
|
|
|
|
attr_reader :condition
|
2017-08-30 17:21:13 +03:00
|
|
|
|
2020-02-19 02:16:44 +07:00
|
|
|
def initialize(condition , false_label)
|
|
|
|
super(false_label)
|
2017-09-06 12:08:44 +03:00
|
|
|
@condition = condition
|
2020-02-17 14:26:50 +07:00
|
|
|
raise "condition must be slot_definition #{condition}" unless condition.is_a?(Slotted)
|
2017-08-30 17:21:13 +03:00
|
|
|
end
|
2018-03-13 16:16:06 +05:30
|
|
|
|
2018-04-20 19:38:33 +03:00
|
|
|
def to_s
|
2020-02-19 02:16:44 +07:00
|
|
|
"TruthCheck #{@condition} -> #{false_label}"
|
2018-04-20 19:38:33 +03:00
|
|
|
end
|
|
|
|
|
2018-03-13 16:16:06 +05:30
|
|
|
def to_risc(compiler)
|
2020-02-19 02:16:44 +07:00
|
|
|
false_label = @false_label.risc_label(compiler)
|
2018-08-19 13:18:25 +03:00
|
|
|
condition_reg = @condition.to_register(compiler,self)
|
2020-03-03 16:09:41 +02:00
|
|
|
|
2020-03-01 18:07:42 +02:00
|
|
|
compiler.build(self.to_s) do
|
|
|
|
object = load_object Parfait.object_space.false_object
|
2018-08-19 13:18:25 +03:00
|
|
|
object.op :- , condition_reg
|
2018-08-16 20:28:42 +03:00
|
|
|
if_zero false_label
|
2020-03-01 18:07:42 +02:00
|
|
|
object = load_object Parfait.object_space.nil_object
|
2018-08-19 13:18:25 +03:00
|
|
|
object.op :- , condition_reg
|
2018-08-16 20:28:42 +03:00
|
|
|
if_zero false_label
|
|
|
|
end
|
2018-03-13 16:16:06 +05:30
|
|
|
end
|
|
|
|
|
2017-08-30 17:21:13 +03:00
|
|
|
end
|
|
|
|
end
|