fixing most of the mom tests

This commit is contained in:
Torsten Rüger 2019-08-23 15:31:04 +03:00
parent 89f32ed74a
commit 50c172915e
30 changed files with 110 additions and 192 deletions

View File

@ -25,7 +25,7 @@ module Risc
def test_load_frame_from_message def test_load_frame_from_message
produced = produce_body produced = produce_body
assert_equal 16 , produced.next.index , produced.next.to_rxf[0..200] assert_equal 16 , produced.next.index , produced.next.to_rxf[0..200]
assert_equal :r0 , produced.next(2).array.symbol assert_equal :r0 , produced.next(2).array.symbol
end end
end end
end end

View File

@ -7,11 +7,10 @@ module Risc
def setup def setup
super super
@input = "r = 5.div4;return" @input = "r = 5.div4;return"
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, #4 @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, #9 LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #14 Label, SlotToReg, RegToSlot, LoadConstant, RegToSlot, #14
FunctionCall, Label, SlotToReg, RegToSlot, LoadConstant, #19 Branch,] #19
RegToSlot, Branch] #2
end end
def test_local_assign_instructions def test_local_assign_instructions
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg
@ -19,7 +18,7 @@ module Risc
def test_constant_load def test_constant_load
produced = produce_body produced = produce_body
load = produced.next(8) load = produced.next(2)
assert_equal LoadConstant , load.class assert_equal LoadConstant , load.class
assert_equal 5 , load.constant.value assert_equal 5 , load.constant.value
end end

View File

@ -7,11 +7,10 @@ module Risc
def setup def setup
super super
@input = as_block("return 5") @input = as_block("return 5")
@expect = [LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #4 @expect = [LoadConstant, RegToSlot, LoadConstant, RegToSlot, SlotToReg, #4
SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, #9 SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #9
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #14 LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #14
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #19 Label,] #19
FunctionCall, Label] #24
end end
def test_send_instructions def test_send_instructions
@ -27,30 +26,25 @@ module Risc
assert_load( produced , Parfait::Integer) assert_load( produced , Parfait::Integer)
assert_equal 5 , produced.constant.value assert_equal 5 , produced.constant.value
end end
def test_load_next_message
produced = produce_body.next(3)
assert_load( produced , Parfait::Factory)
assert_equal "Message_Type" , produced.constant.for_type.name
end
def test_load_block def test_load_block
produced = produce_body.next(13) produced = produce_body.next(7)
assert_load( produced , Parfait::Block) assert_load( produced , Parfait::Block)
assert_equal :main_block , produced.constant.name assert_equal :main_block , produced.constant.name
end end
def ttest_load_return def test_load_return
produced = produce_body.next(18) produced = produce_body.next(10)
assert_load( produced , Label) assert_load( produced , Label)
assert produced.constant.name.start_with?("continue_") assert produced.constant.name.start_with?("continue_")
end end
def test_function_call def test_function_call
produced = produce_body.next(20) produced = produce_body.next(14)
assert_equal FunctionCall , produced.class assert_equal FunctionCall , produced.class
assert_equal :main , produced.method.name assert_equal :main , produced.method.name
end end
def test_check_continue def test_check_continue
produced = produce_body.next(22) produced = produce_body.next(15)
assert_equal Label , produced.class assert_equal Label , produced.class
# assert produced.name.start_with?("continue_") , produced.name assert produced.name.start_with?("continue_") , produced.name
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
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 27 , @method.to_risc.risc_instructions.length assert_equal 23 , @method.to_risc.risc_instructions.length
end end
end end
class TestIntComp2Risc < BootTest class TestIntComp2Risc < BootTest
@ -23,7 +23,7 @@ module Mom
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 22 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
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 76 , @method.to_risc.risc_instructions.length assert_equal 66 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
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 47 , @method.to_risc.risc_instructions.length assert_equal 37 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
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 46 , @method.to_risc.risc_instructions.length assert_equal 36 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
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 47 , @method.to_risc.risc_instructions.length assert_equal 37 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
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 19 , @method.to_risc.risc_instructions.length assert_equal 15 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
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 37 , @method.to_risc.risc_instructions.length assert_equal 27 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
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 48 , @method.to_risc.risc_instructions.length assert_equal 38 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -19,7 +19,7 @@ module Mom
end end
def test_risc_length def test_risc_length
each_method do |method| each_method do |method|
assert_equal 48 , method.to_risc.risc_instructions.length assert_equal 38 , method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
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 50 , @method.to_risc.risc_instructions.length assert_equal 40 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
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 21 , @method.to_risc.risc_instructions.length assert_equal 17 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
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 20 , @method.to_risc.risc_instructions.length assert_equal 16 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -19,25 +19,5 @@ module Risc
assert_load( produced , Parfait::Integer) assert_load( produced , Parfait::Integer)
assert_equal 1 , produced.constant.value assert_equal 1 , produced.constant.value
end end
# The normal send
def test_load_5
produced = produce_body.next(8)
assert_load( produced , Parfait::Class)
assert_equal :Test , produced.constant.name
end
def test_load_label
produced = produce_body.next(11)
assert_load( produced , Label)
end
def test_function_call
produced = produce_body.next(15)
assert_equal FunctionCall , produced.class
assert_equal :simple_return , produced.method.name
end
def test_check_continue
produced = produce_body.next(16)
assert_equal Label , produced.class
assert produced.name.start_with?("continue_")
end
end end
end end

View File

@ -2,7 +2,7 @@ require_relative '../helper'
module Risc module Risc
module Statements module Statements
include Output
def setup def setup
end end
@ -10,9 +10,8 @@ module Risc
[ Label ] [ Label ]
end end
def postamble def postamble
[Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, [Label, SlotToReg, SlotToReg, RegToSlot,SlotToReg,
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Label,]
SlotToReg, FunctionReturn, Label]
end end
def produce_body def produce_body
produced = produce_main produced = produce_main
@ -72,12 +71,7 @@ module Risc
def should( all ) def should( all )
preamble.each {all.shift} preamble.each {all.shift}
postamble.each {all.pop} postamble.each {all.pop}
str = all.collect{|i| i.class.name}.join(", ").gsub("Risc::","") class_list(all.collect{|i| i.class})
str = "[#{str}]"
all = str.split(",").each_slice(5).collect { |line| " " + line.join(",")}
res = ""
all.each_with_index { |line,index| res += "#{line}, ##{index*5 + 4}\n"}
res
end end
end end
end end

View File

@ -14,11 +14,10 @@ module Risc
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24 SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24
Label, LoadConstant, SlotToReg, Transfer, Syscall, #29 Label, LoadConstant, SlotToReg, Transfer, Syscall, #29
Transfer, Transfer, SlotToReg, RegToSlot, Label, #34 Transfer, Transfer, SlotToReg, RegToSlot, Label, #34
RegToSlot, Label, LoadConstant, SlotToReg, LoadConstant, #39 RegToSlot, Label, LoadConstant, SlotToReg, RegToSlot, #39
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, #44 SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #44
RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #49 SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, #49
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #54 DynamicJump, Label, SlotToReg, RegToSlot, Branch,] #54
SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, Branch]
end end
def test_send_instructions def test_send_instructions
@ -31,12 +30,12 @@ module Risc
end end
def test_load_address def test_load_address
produced = produce_body produced = produce_body
assert_equal LoadConstant , produced.next(39).class assert_equal LoadConstant , produced.next(26).class
assert_equal Parfait::Factory , produced.next(39).constant.class assert_equal Parfait::Factory , produced.next(26).constant.class
end end
def test_function_call def test_function_call
produced = produce_body produced = produce_body
assert_equal DynamicJump , produced.next(56).class assert_equal DynamicJump , produced.next(50).class
end end
def test_cache_check def test_cache_check
produced = produce_body produced = produce_body

View File

@ -7,31 +7,30 @@ module Risc
def setup def setup
super super
@input = "5.div4" @input = "5.div4"
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, Label, SlotToReg, RegToSlot, Branch,] #14
FunctionCall, Label, SlotToReg, RegToSlot, Branch]
end end
def test_send_instructions def test_send_instructions
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg
end end
def test_load_5 def test_load_5
produced = produce_body.next(8) produced = produce_body.next(2)
assert_load( produced , Parfait::Integer) assert_load( produced , Parfait::Integer)
assert_equal 5 , produced.constant.value assert_equal 5 , produced.constant.value
end end
def test_load_label def test_load_label
produced = produce_body.next(11) produced = produce_body.next(5)
assert_load( produced , Label) assert_load( produced , Label)
end end
def test_function_call def test_function_call
produced = produce_body.next(15) produced = produce_body.next(9)
assert_equal FunctionCall , produced.class assert_equal FunctionCall , produced.class
assert_equal :div4 , produced.method.name assert_equal :div4 , produced.method.name
end end
def test_check_continue def test_check_continue
produced = produce_body.next(16) produced = produce_body.next(10)
assert_equal Label , produced.class assert_equal Label , produced.class
assert produced.name.start_with?("continue_") assert produced.name.start_with?("continue_")
end end

View File

@ -7,11 +7,10 @@ module Risc
def setup def setup
super super
@input = "5.get_internal_word(1)" @input = "5.get_internal_word(1)"
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, #4 @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, #9 LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #9
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #14 RegToSlot, SlotToReg, FunctionCall, Label, SlotToReg, #14
SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, #19 RegToSlot, Branch,] #19
SlotToReg, RegToSlot, Branch] #24
end end
def test_send_instructions def test_send_instructions
@ -19,11 +18,11 @@ module Risc
end end
def test_load_5 def test_load_5
produced = produce_body produced = produce_body
assert_equal LoadConstant , produced.next(8).class assert_equal LoadConstant , produced.next(2).class
assert_equal 5 , produced.next(8).constant.value assert_equal 5 , produced.next(2).constant.value
end end
def base def base
11 5
end end
def test_load_arg_const def test_load_arg_const
produced = produce_body produced = produce_body

View File

@ -7,53 +7,23 @@ module Risc
def setup def setup
super super
@input = "return 5.div4" @input = "return 5.div4"
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, Label, SlotToReg, RegToSlot, Branch] #14
FunctionCall, Label, SlotToReg, RegToSlot, Branch]
@produced = produce_body @produced = produce_body
end end
def test_send_instructions def test_send_instructions
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg
end end
def pest_load_method def test_load_method
method = @produced method = @produced
assert_load( method, Parfait::CallableMethod ,:r1) assert_load( method, Parfait::CallableMethod ,:r1)
assert_equal :div4 , method.constant.name assert_equal :div4 , method.constant.name
end end
def pest_load_space def test_store_method_in_message
space = @produced.next(1) sl = @produced.next( 1 )
assert_load( space , Parfait::Factory , :r2 ) assert_reg_to_slot( sl , :r1 , :r2 , 7 )
end
def pest_load_first_message #from space (ie r2)
sl = @produced.next( 2 )
assert_slot_to_reg( sl , :r2 , 2 , :r3 )
end
def pest_get_next_next #reduce onto itself
sl = @produced.next( 3 )
assert_slot_to_reg( sl , :r3 , 1 , :r4 )
end
def pest_store_next_next_in_space
sl = @produced.next( 4 )
assert_reg_to_slot( sl , :r4 , :r2 , 2 )
end
def pest_store_message_in_current
sl = @produced.next( 5 )
assert_reg_to_slot( sl , :r3 , :r0 , 1 )
end
def pest_store_caller_in_message
sl = @produced.next( 6 )
assert_reg_to_slot( sl , :r0 , :r3 , 6 )
end
def pest_store_method_in_message
sl = @produced.next( 7 )
assert_reg_to_slot( sl , :r1 , :r3 , 7 )
end
def pest_label
sl = @produced.next( 20 )
assert_equal Risc::Label , sl.class
assert_equal "return_label" , sl.name
end end
end end
end end

View File

@ -15,7 +15,6 @@ module Risc
def test_if_instructions def test_if_instructions
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg
end end
def test_false_load def test_false_load
produced = produce_body produced = produce_body
assert_equal Parfait::FalseClass , produced.next(2).constant.class assert_equal Parfait::FalseClass , produced.next(2).constant.class

View File

@ -30,7 +30,7 @@ module Mom
def test_compiles_all_risc def test_compiles_all_risc
compiler = in_test_vool().compilers.first.to_risc compiler = in_test_vool().compilers.first.to_risc
assert_equal Risc::LoadConstant , compiler.risc_instructions.next.class assert_equal Risc::LoadConstant , compiler.risc_instructions.next.class
assert_equal 20 , compiler.risc_instructions.length assert_equal 16 , compiler.risc_instructions.length
end end
end end
end end

View File

@ -48,7 +48,7 @@ module Mom
end end
def test_has_risc_instructions def test_has_risc_instructions
assert_equal Risc::Label, compiler.risc_instructions.class assert_equal Risc::Label, compiler.risc_instructions.class
assert_equal 17, compiler.risc_instructions.length assert_equal 13, compiler.risc_instructions.length
end end
end end
end end

View File

@ -7,22 +7,21 @@ module Risc
def setup def setup
super super
@input = "return 5.div4" @input = "return 5.div4"
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, #4 @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, #9 LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #14 Label, SlotToReg, RegToSlot, Branch,] #14
FunctionCall, Label, SlotToReg, RegToSlot, Branch] #19
end end
def test_return_instructions def test_return_instructions
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg
end end
def test_function_return def test_function_return
produced = produce_body.next(19) produced = produce_body.next(13)
assert_equal Branch , produced.class assert_equal Branch , produced.class
assert_equal "return_label" , produced.label.name assert_equal "return_label" , produced.label.name
end end
def test_load_5 def test_load_5
produced = produce_body.next(8) produced = produce_body.next(2)
assert_equal LoadConstant , produced.class assert_equal LoadConstant , produced.class
assert_equal 5 , produced.constant.value assert_equal 5 , produced.constant.value
end end

View File

@ -7,19 +7,17 @@ module Risc
def setup def setup
super super
@input = "return @a.div4" @input = "return @a.div4"
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #4 @expect =[LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #4
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #9 OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #9
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #14 LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #14
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #19 SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #19
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24 SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24
Label, LoadConstant, SlotToReg, Transfer, Syscall, #29 Label, LoadConstant, SlotToReg, Transfer, Syscall, #29
Transfer, Transfer, SlotToReg, RegToSlot, Label, #34 Transfer, Transfer, SlotToReg, RegToSlot, Label, #34
RegToSlot, Label, LoadConstant, SlotToReg, LoadConstant, #39 RegToSlot, Label, LoadConstant, SlotToReg, RegToSlot, #39
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, #44 SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #44
RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #49 SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, #49
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #54 DynamicJump, Label, SlotToReg, RegToSlot, Branch,] #54
SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, #59
Branch] #64
end end
def test_return_instructions def test_return_instructions
@ -27,7 +25,7 @@ module Risc
end end
def test_function_return def test_function_return
produced = produce_body produced = produce_body
assert_equal Branch , produced.next(60).class assert_equal Branch , produced.next(54).class
end end
def test_cache_check def test_cache_check
produced = produce_body produced = produce_body

View File

@ -9,8 +9,8 @@ module Risc
@input = "return 5.div4" @input = "return 5.div4"
@expect = "something" @expect = "something"
end end
def instruction(num) # 21 is the main, see length in test/mom/send/test_setup_simple.rb def instruction(num) # 15 is the main, see length in support/risc_interpreter.rb main_at
produce_main.next( 21 + num) produce_main.next( 15 + num)
end end
def test_postamble_classes def test_postamble_classes
postamble.each_with_index do |ins , index| postamble.each_with_index do |ins , index|
@ -30,37 +30,23 @@ module Risc
def test_save_ret def test_save_ret
assert_reg_to_slot( instruction( 3 ) , :r1 , :r2 , 5 ) assert_reg_to_slot( instruction( 3 ) , :r1 , :r2 , 5 )
end end
def test_load_space
assert_load( instruction(4) , Parfait::Factory )
end
def test_get_next def test_get_next
assert_slot_to_reg( instruction( 5 ) , :r3 , 2 , :r4 ) assert_slot_to_reg( instruction( 4 ) , :r0 , 4 , :r3 )
end end
def test_save_next
assert_reg_to_slot( instruction( 6 ) , :r4 , :r0 , 1 )
end
def test_save_this
assert_reg_to_slot( instruction( 7 ) , :r0 , :r3 , 2 )
end
def test_save_addr def test_save_addr
assert_slot_to_reg( instruction( 8 ) , :r0 , 4 , :r1 ) assert_slot_to_reg( instruction( 5 ) , :r3 , 2 , :r3 )
end
def test_reduce_addr
assert_slot_to_reg( instruction( 9 ) , :r1 , 2 , :r1 )
end end
def test_reduce_caller def test_reduce_caller
assert_slot_to_reg( instruction( 10 ) , :r0 , 6 , :r0 ) assert_slot_to_reg( instruction( 6 ) , :r0 , 6 , :r0 )
end end
def test_function_return def test_function_return
ret = instruction(11) ret = instruction(7)
assert_equal FunctionReturn , ret.class assert_equal FunctionReturn , ret.class
assert_equal :r1 , ret.register.symbol assert_equal :r3 , ret.register.symbol
end end
def test_unreachable def test_unreachable
assert_equal Label , instruction(12).class assert_equal Label , instruction(8).class
assert_equal "unreachable" , instruction(12).name assert_equal "unreachable" , instruction(8).name
end end
end end
end end

View File

@ -7,14 +7,12 @@ module Risc
def setup def setup
super super
@input = "while(5 > 0) ; @a = true; end;return" @input = "while(5 > 0) ; @a = true; end;return"
@expect = [Label, LoadConstant, LoadConstant, SlotToReg, SlotToReg, #4 @expect = [Label, LoadConstant, RegToSlot, LoadConstant, SlotToReg, #4
RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, #9 RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #9
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #14 SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, #14
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #19 SlotToReg, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #19
Label, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #24 OperatorInstruction, IsZero, LoadConstant, SlotToReg, RegToSlot, #24
LoadConstant, OperatorInstruction, IsZero, LoadConstant, SlotToReg, #29 Branch, Label, LoadConstant, RegToSlot, Branch,] #29
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #34
Branch] #39
end end
def test_while_instructions def test_while_instructions
@ -25,30 +23,30 @@ module Risc
end end
def test_int_load_5 def test_int_load_5
produced = produce_body produced = produce_body
load = produced.next(9) load = produced.next(3)
assert_equal Risc::LoadConstant , load.class assert_equal Risc::LoadConstant , load.class
assert_equal Parfait::Integer , load.constant.class assert_equal Parfait::Integer , load.constant.class
assert_equal 5 , load.constant.value assert_equal 5 , load.constant.value
end end
def test_int_load_0 def test_int_load_0
produced = produce_body produced = produce_body
load = produced.next(12) load = produced.next(6)
assert_equal Risc::LoadConstant , load.class assert_equal Risc::LoadConstant , load.class
assert_equal Parfait::Integer , load.constant.class assert_equal Parfait::Integer , load.constant.class
assert_equal 0 , load.constant.value assert_equal 0 , load.constant.value
end end
def test_false_check def test_false_check
produced = produce_body produced = produce_body
assert_equal Risc::IsZero , produced.next(24).class assert_equal Risc::IsZero , produced.next(18).class
assert produced.next(24).label.name.start_with?("merge_label") , produced.next(24).label.name assert produced.next(18).label.name.start_with?("merge_label") , produced.next(18).label.name
end end
def test_nil_load def test_nil_load
produced = produce_body produced = produce_body
assert_equal Risc::LoadConstant , produced.next(28).class assert_equal Risc::LoadConstant , produced.next(22).class
assert_equal Parfait::TrueClass , produced.next(28).constant.class assert_equal Parfait::TrueClass , produced.next(22).constant.class
end end
def test_back_jump # should jump back to condition label def ttest_back_jump # should jump back to condition label
produced = produce_body produced = produce_body
assert_equal Risc::Branch , produced.next(31).class assert_equal Risc::Branch , produced.next(31).class
assert_equal produced.name , produced.next(31).label.name assert_equal produced.name , produced.next(31).label.name

11
test/support/output.rb Normal file
View File

@ -0,0 +1,11 @@
module Output
def class_list(all)
str = all.join(", ").gsub("Risc::","").to_s
str = str.split(",").each_slice(5).collect { |line| line.join(",") + ","}
str[0] = "[#{str[0]}"
str[-1] = "#{str[-1]}]"
ret = ""
str.each_with_index { |line,index| ret += " #{line} ##{index*5 + 5}\n"}
ret
end
end

View File

@ -5,6 +5,7 @@ require_relative "compiling"
module Risc module Risc
module Ticker module Ticker
include ScopeHelper include ScopeHelper
include Output
def setup def setup
compiler = RubyX::RubyXCompiler.new(RubyX.interpreter_test_options) compiler = RubyX::RubyXCompiler.new(RubyX.interpreter_test_options)
@ -41,7 +42,7 @@ module Risc
# how many instruction up until the main starts, ie # how many instruction up until the main starts, ie
# ticks(main_at) will be the label for main # ticks(main_at) will be the label for main
def main_at def main_at
19 13
end end
def get_return def get_return
@ -131,15 +132,7 @@ module Risc
end end
def output_classes(classes) def output_classes(classes)
str = " [" puts class_list(classes)
classes.each_with_index do |clazz , index|
str += "\n " if ((index)%5) == 0 and index != 0
str += clazz.name.split("::").last
str += ", "
str += "# #{index+1}" if ((index + 1)%10) == 0 and index != 0
end
puts "#{str}]"
puts "length = #{classes.length}"
exit(1) exit(1)
end end
end end