2019-10-03 20:07:55 +02:00
|
|
|
module SlotMachine
|
2017-08-30 16:21:13 +02:00
|
|
|
|
2018-03-19 16:49:26 +01:00
|
|
|
# The funny thing about the ruby truth is that it is anything but false or nil
|
2017-08-30 16:21:13 +02: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 20:00:08 +02:00
|
|
|
class TruthCheck < Check
|
|
|
|
attr_reader :condition
|
2017-08-30 16:21:13 +02:00
|
|
|
|
2018-03-16 08:03:11 +01:00
|
|
|
def initialize(condition , false_jump)
|
|
|
|
super(false_jump)
|
2017-09-06 11:08:44 +02:00
|
|
|
@condition = condition
|
2020-02-11 10:19:52 +01:00
|
|
|
raise "condition must be slot_definition #{condition}" unless condition.is_a?(Slot)
|
2017-08-30 16:21:13 +02:00
|
|
|
end
|
2018-03-13 11:46:06 +01:00
|
|
|
|
2018-04-20 18:38:33 +02:00
|
|
|
def to_s
|
|
|
|
"TruthCheck #{@condition} -> #{false_jump}"
|
|
|
|
end
|
|
|
|
|
2018-03-13 11:46:06 +01:00
|
|
|
def to_risc(compiler)
|
2018-08-29 20:06:29 +02:00
|
|
|
false_label = @false_jump.risc_label(compiler)
|
2018-08-19 12:18:25 +02:00
|
|
|
builder = compiler.builder("TruthCheck")
|
|
|
|
condition_reg = @condition.to_register(compiler,self)
|
|
|
|
builder.build do
|
2018-08-16 19:28:42 +02:00
|
|
|
object! << Parfait.object_space.false_object
|
2018-08-19 12:18:25 +02:00
|
|
|
object.op :- , condition_reg
|
2018-08-16 19:28:42 +02:00
|
|
|
if_zero false_label
|
|
|
|
object << Parfait.object_space.nil_object
|
2018-08-19 12:18:25 +02:00
|
|
|
object.op :- , condition_reg
|
2018-08-16 19:28:42 +02:00
|
|
|
if_zero false_label
|
|
|
|
end
|
2018-03-13 11:46:06 +01:00
|
|
|
end
|
|
|
|
|
2017-08-30 16:21:13 +02:00
|
|
|
end
|
|
|
|
end
|