2017-08-30 17:21:13 +03:00
|
|
|
module Mom
|
|
|
|
|
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
|
|
|
|
2018-03-16 12:33:11 +05:30
|
|
|
def initialize(condition , false_jump)
|
|
|
|
super(false_jump)
|
2017-09-06 12:08:44 +03:00
|
|
|
@condition = condition
|
2018-03-16 12:33:11 +05:30
|
|
|
raise "condition must be slot_definition #{condition}" unless condition.is_a?(SlotDefinition)
|
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
|
|
|
|
"TruthCheck #{@condition} -> #{false_jump}"
|
|
|
|
end
|
|
|
|
|
2018-03-13 16:16:06 +05:30
|
|
|
def to_risc(compiler)
|
2018-08-29 21:06:29 +03:00
|
|
|
false_label = @false_jump.risc_label(compiler)
|
2018-08-19 13:18:25 +03:00
|
|
|
builder = compiler.builder("TruthCheck")
|
|
|
|
condition_reg = @condition.to_register(compiler,self)
|
|
|
|
builder.build do
|
2018-08-16 20:28:42 +03:00
|
|
|
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
|
|
|
|
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
|