Fix comparison macro
which leaves a definite need for instruction level testing
This commit is contained in:
parent
2af953e1d2
commit
3688c967d3
@ -65,10 +65,13 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
# reduce integer to fixnum and add instruction if compiler is used
|
# reduce integer to fixnum and add instruction if compiler is used
|
||||||
|
# TODO: checck type of self, should be integer
|
||||||
|
# TODO: find a type for the result, maybe fixnum , or data ?
|
||||||
|
# TODO also check types on reg_to_slot
|
||||||
def reduce_int
|
def reduce_int
|
||||||
reduce = Risc::SlotToReg.new( "int -> fix" , self , Parfait::Integer.integer_index , self)
|
reduce = Risc::SlotToReg.new( "int -> fix" , self , Parfait::Integer.integer_index , self)
|
||||||
compiler.add_code(reduce) if compiler
|
compiler.add_code(reduce) if compiler
|
||||||
reduce
|
reduce.register
|
||||||
end
|
end
|
||||||
|
|
||||||
# when following variables in resolve_and_add, get a new RegisterValue
|
# when following variables in resolve_and_add, get a new RegisterValue
|
||||||
|
@ -69,7 +69,6 @@ module SlotMachine
|
|||||||
while( instruction )
|
while( instruction )
|
||||||
raise "whats this a #{instruction}" unless instruction.is_a?(SlotMachine::Instruction)
|
raise "whats this a #{instruction}" unless instruction.is_a?(SlotMachine::Instruction)
|
||||||
#puts "adding slot #{instruction.to_s}:#{instruction.next.to_s}"
|
#puts "adding slot #{instruction.to_s}:#{instruction.next.to_s}"
|
||||||
risc_compiler.reset_regs
|
|
||||||
instruction.to_risc( risc_compiler )
|
instruction.to_risc( risc_compiler )
|
||||||
#puts "adding risc #{risc.to_s}:#{risc.next.to_s}"
|
#puts "adding risc #{risc.to_s}:#{risc.next.to_s}"
|
||||||
instruction = instruction.next
|
instruction = instruction.next
|
||||||
|
@ -3,26 +3,36 @@ module SlotMachine
|
|||||||
attr_reader :operator
|
attr_reader :operator
|
||||||
def initialize(name , operator)
|
def initialize(name , operator)
|
||||||
super(name)
|
super(name)
|
||||||
|
#TODO check operator to be in valid range
|
||||||
@operator = operator.value
|
@operator = operator.value
|
||||||
end
|
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)
|
def to_risc(compiler)
|
||||||
builder = compiler.builder(compiler.source)
|
builder = compiler.builder(compiler.source)
|
||||||
operator = @operator # make accessible in block
|
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
|
builder.build do
|
||||||
integer! << message[:receiver]
|
left = message[:receiver].to_reg.reduce_int
|
||||||
integer.reduce_int
|
right = message[:arg1].to_reg.reduce_int
|
||||||
integer_reg! << message[:arg1] #"other"
|
|
||||||
integer_reg.reduce_int
|
if(operator.to_s.start_with?('<') )
|
||||||
swap_names(:integer , :integer_reg) if(operator.to_s.start_with?('<') )
|
right.op :- , left
|
||||||
integer.op :- , integer_reg
|
else
|
||||||
|
left.op :- , right
|
||||||
|
end
|
||||||
if_minus false_label
|
if_minus false_label
|
||||||
if_zero( false_label ) if operator.to_s.length == 1
|
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
|
branch merge_label
|
||||||
add_code false_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
|
add_code merge_label
|
||||||
message[:return_value] << object
|
message[:return_value] << result
|
||||||
end
|
end
|
||||||
return compiler
|
return compiler
|
||||||
end
|
end
|
||||||
|
@ -5,9 +5,9 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@r0 = RegisterValue.new(:message , :Message)
|
|
||||||
@r1 = RegisterValue.new(:id_1234 , :Space)
|
|
||||||
@compiler = Risc.test_compiler
|
@compiler = Risc.test_compiler
|
||||||
|
@r0 = RegisterValue.new(:message , :Message).set_compiler(@compiler)
|
||||||
|
@r1 = RegisterValue.new(:id_1234 , :Space).set_compiler(@compiler)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_resolves_index_ok
|
def test_resolves_index_ok
|
||||||
@ -18,8 +18,10 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_reduce_int
|
def test_reduce_int
|
||||||
ins = @r0.reduce_int
|
ins = @r0.reduce_int
|
||||||
assert_equal SlotToReg , ins.class
|
assert_equal RegisterValue , ins.class
|
||||||
assert_equal Parfait::Integer.integer_index , ins.index
|
assert_equal SlotToReg , @compiler.current.class
|
||||||
|
assert_equal Parfait::Integer.integer_index , @compiler.current.index
|
||||||
|
assert_equal :message , ins.symbol
|
||||||
end
|
end
|
||||||
def test_get_new_left_0
|
def test_get_new_left_0
|
||||||
assert_equal RegisterValue , @r0.get_new_left(:caller , @compiler).class
|
assert_equal RegisterValue , @r0.get_new_left(:caller , @compiler).class
|
||||||
|
@ -14,22 +14,23 @@ module SlotMachine
|
|||||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||||
end
|
end
|
||||||
def test_risc_length
|
def test_risc_length
|
||||||
assert_equal 26 , @method.to_risc.risc_instructions.length
|
assert_equal 25 , @method.to_risc.risc_instructions.length
|
||||||
end
|
end
|
||||||
|
#TODO, check the actual instructions, at least by class
|
||||||
end
|
end
|
||||||
class TestIntComp2Risc < BootTest
|
class TestIntComp2Risc < BootTest
|
||||||
def setup
|
def setup
|
||||||
@method = get_compiler("Integer",:gt)
|
@method = get_compiler("Integer",:ge)
|
||||||
end
|
end
|
||||||
def test_slot_length
|
def test_slot_length
|
||||||
assert_equal :> , @method.callable.name
|
assert_equal :>= , @method.callable.name
|
||||||
assert_equal 7 , @method.slot_instructions.length
|
assert_equal 7 , @method.slot_instructions.length
|
||||||
end
|
end
|
||||||
def test_compile
|
def test_compile
|
||||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||||
end
|
end
|
||||||
def test_risc_length
|
def test_risc_length
|
||||||
assert_equal 26 , @method.to_risc.risc_instructions.length
|
assert_equal 24 , @method.to_risc.risc_instructions.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user