Fix comparison macro
which leaves a definite need for instruction level testing
This commit is contained in:
@ -69,7 +69,6 @@ module SlotMachine
|
||||
while( instruction )
|
||||
raise "whats this a #{instruction}" unless instruction.is_a?(SlotMachine::Instruction)
|
||||
#puts "adding slot #{instruction.to_s}:#{instruction.next.to_s}"
|
||||
risc_compiler.reset_regs
|
||||
instruction.to_risc( risc_compiler )
|
||||
#puts "adding risc #{risc.to_s}:#{risc.next.to_s}"
|
||||
instruction = instruction.next
|
||||
|
@ -3,26 +3,36 @@ module SlotMachine
|
||||
attr_reader :operator
|
||||
def initialize(name , operator)
|
||||
super(name)
|
||||
#TODO check operator to be in valid range
|
||||
@operator = operator.value
|
||||
end
|
||||
|
||||
# basically use subtract to subtract left from right (or right from left)
|
||||
# and load true_object in the true branch and false_object in the false
|
||||
# for the case of =, as in <= or >= we also do not check for zero
|
||||
def to_risc(compiler)
|
||||
builder = compiler.builder(compiler.source)
|
||||
operator = @operator # make accessible in block
|
||||
false_label = Risc.label("false" , "false")
|
||||
merge_label = Risc.label("merge" , "merge")
|
||||
result = Risc::RegisterValue.new(:result , :Object)
|
||||
builder.build do
|
||||
integer! << message[:receiver]
|
||||
integer.reduce_int
|
||||
integer_reg! << message[:arg1] #"other"
|
||||
integer_reg.reduce_int
|
||||
swap_names(:integer , :integer_reg) if(operator.to_s.start_with?('<') )
|
||||
integer.op :- , integer_reg
|
||||
left = message[:receiver].to_reg.reduce_int
|
||||
right = message[:arg1].to_reg.reduce_int
|
||||
|
||||
if(operator.to_s.start_with?('<') )
|
||||
right.op :- , left
|
||||
else
|
||||
left.op :- , right
|
||||
end
|
||||
if_minus false_label
|
||||
if_zero( false_label ) if operator.to_s.length == 1
|
||||
object! << Parfait.object_space.true_object
|
||||
add_code Risc::LoadConstant.new(to_s , Parfait.object_space.true_object, result)
|
||||
branch merge_label
|
||||
add_code false_label
|
||||
object << Parfait.object_space.false_object
|
||||
add_code Risc::LoadConstant.new(to_s , Parfait.object_space.false_object, result)
|
||||
add_code merge_label
|
||||
message[:return_value] << object
|
||||
message[:return_value] << result
|
||||
end
|
||||
return compiler
|
||||
end
|
||||
|
Reference in New Issue
Block a user