fix argument indexing
good old index bug, off by one this time forgot about parfait 1-indexing
This commit is contained in:
parent
b997f01236
commit
ee8b9469af
@ -68,8 +68,8 @@ module Vool
|
|||||||
mom_receive = @receiver.slot_definition(in_method)
|
mom_receive = @receiver.slot_definition(in_method)
|
||||||
arg_target = [:message , :next_message , :arguments]
|
arg_target = [:message , :next_message , :arguments]
|
||||||
args = []
|
args = []
|
||||||
@arguments.each_with_index do |arg , index| # +1 because of type
|
@arguments.each_with_index do |arg , index| # +1 because of type, + 1 beacuse 1-indexed
|
||||||
args << Mom::SlotLoad.new( arg_target + [index+1] , arg.slot_definition(in_method))
|
args << Mom::SlotLoad.new( arg_target + [index+1+1] , arg.slot_definition(in_method))
|
||||||
end
|
end
|
||||||
setup << Mom::ArgumentTransfer.new( mom_receive , args )
|
setup << Mom::ArgumentTransfer.new( mom_receive , args )
|
||||||
end
|
end
|
||||||
|
@ -42,9 +42,6 @@ module Risc
|
|||||||
test = Parfait.object_space.get_class_by_name :Test
|
test = Parfait.object_space.get_class_by_name :Test
|
||||||
test.instance_type.get_method :main
|
test.instance_type.get_method :main
|
||||||
end
|
end
|
||||||
def real_index(index)
|
|
||||||
index - preamble.length
|
|
||||||
end
|
|
||||||
def compare_instructions( instruction , expect )
|
def compare_instructions( instruction , expect )
|
||||||
index = 0
|
index = 0
|
||||||
all = instruction.to_arr
|
all = instruction.to_arr
|
||||||
@ -52,9 +49,9 @@ module Risc
|
|||||||
#full_expect = expect
|
#full_expect = expect
|
||||||
begin
|
begin
|
||||||
should = full_expect[index]
|
should = full_expect[index]
|
||||||
return "No instruction at #{real_index(index)}\n#{should(all)[0..100]}" unless should
|
return "No instruction at #{index-1}\n#{should(all)[0..100]}" unless should
|
||||||
return "Expected at #{real_index(index)}\n#{should(all)} was #{instruction.to_s[0..100]}" unless instruction.class == should
|
return "Expected at #{index-1}\n#{should(all)} was #{instruction.to_s[0..100]}" unless instruction.class == should
|
||||||
#puts instruction.to_s if (index > preamble.length) and (index + postamble.length <= full_expect.length)
|
#puts "#{index-1}:#{instruction.to_s}" if (index > preamble.length) and (index + postamble.length <= full_expect.length)
|
||||||
index += 1
|
index += 1
|
||||||
instruction = instruction.next
|
instruction = instruction.next
|
||||||
end while( instruction )
|
end while( instruction )
|
||||||
|
@ -22,11 +22,61 @@ module Risc
|
|||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal 5 , produced.next(16).constant.value
|
assert_equal 5 , produced.next(16).constant.value
|
||||||
end
|
end
|
||||||
|
def test_load_arg_const
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal LoadConstant , produced.next(19).class
|
||||||
|
assert_equal Mom::IntegerConstant , produced.next(19).constant.class
|
||||||
|
assert_equal 1 , produced.next(19).constant.value
|
||||||
|
end
|
||||||
|
def test_load_next_m
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal SlotToReg , produced.next(20).class
|
||||||
|
assert_equal :r2 , produced.next(20).register.symbol
|
||||||
|
assert_equal :r0 , produced.next(20).array.symbol
|
||||||
|
assert_equal 2 , produced.next(20).index
|
||||||
|
end
|
||||||
|
def test_load_args
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal SlotToReg , produced.next(21).class
|
||||||
|
assert_equal :r3 , produced.next(21).register.symbol
|
||||||
|
assert_equal :r2 , produced.next(21).array.symbol
|
||||||
|
assert_equal 9 , produced.next(21).index
|
||||||
|
end
|
||||||
|
def test_store_arg_at
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal RegToSlot , produced.next(22).class
|
||||||
|
assert_equal :r1 , produced.next(22).register.symbol
|
||||||
|
assert_equal :r3 , produced.next(22).array.symbol
|
||||||
|
assert_equal 2 , produced.next(22).index , "first arg must have index 1"
|
||||||
|
end
|
||||||
def test_load_label
|
def test_load_label
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal LoadConstant , produced.next(23).class
|
assert_equal LoadConstant , produced.next(23).class
|
||||||
assert_equal Label , produced.next(23).constant.class
|
assert_equal Label , produced.next(23).constant.class
|
||||||
end
|
end
|
||||||
|
def test_load_some
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal SlotToReg , produced.next(24).class
|
||||||
|
assert_equal :r0 , produced.next(24).array.symbol
|
||||||
|
assert_equal :r3 , produced.next(24).register.symbol
|
||||||
|
assert_equal 2 , produced.next(24).index
|
||||||
|
end
|
||||||
|
def test_store_
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal RegToSlot , produced.next(25).class
|
||||||
|
assert_equal :r3 , produced.next(25).array.symbol
|
||||||
|
assert_equal :r2 , produced.next(25).register.symbol
|
||||||
|
assert_equal 5 , produced.next(25).index
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_swap_messages
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal SlotToReg , produced.next(26).class
|
||||||
|
assert_equal :r0 , produced.next(26).array.symbol
|
||||||
|
assert_equal :r0 , produced.next(26).register.symbol
|
||||||
|
assert_equal 2 , produced.next(26).index
|
||||||
|
end
|
||||||
|
|
||||||
def test_function_call
|
def test_function_call
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal FunctionCall , produced.next(28).class
|
assert_equal FunctionCall , produced.next(28).class
|
||||||
|
@ -21,6 +21,7 @@ module Vool
|
|||||||
def test_args_one_str
|
def test_args_one_str
|
||||||
assert_equal Mom::IntegerConstant, @ins.next.arguments[0].right.known_object.class
|
assert_equal Mom::IntegerConstant, @ins.next.arguments[0].right.known_object.class
|
||||||
assert_equal 1, @ins.next.arguments[0].right.known_object.value
|
assert_equal 1, @ins.next.arguments[0].right.known_object.value
|
||||||
|
assert_equal [:next_message, :arguments, 2], @ins.next.arguments[0].left.slots
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user