fixing most of the mom tests
This commit is contained in:
parent
89f32ed74a
commit
50c172915e
@ -25,7 +25,7 @@ module Risc
|
||||
def test_load_frame_from_message
|
||||
produced = produce_body
|
||||
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
|
||||
|
@ -7,11 +7,10 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "r = 5.div4;return"
|
||||
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, #4
|
||||
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, #9
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #14
|
||||
FunctionCall, Label, SlotToReg, RegToSlot, LoadConstant, #19
|
||||
RegToSlot, Branch] #2
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
|
||||
Label, SlotToReg, RegToSlot, LoadConstant, RegToSlot, #14
|
||||
Branch,] #19
|
||||
end
|
||||
def test_local_assign_instructions
|
||||
assert_nil msg = check_nil , msg
|
||||
@ -19,7 +18,7 @@ module Risc
|
||||
|
||||
def test_constant_load
|
||||
produced = produce_body
|
||||
load = produced.next(8)
|
||||
load = produced.next(2)
|
||||
assert_equal LoadConstant , load.class
|
||||
assert_equal 5 , load.constant.value
|
||||
end
|
||||
|
@ -7,11 +7,10 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = as_block("return 5")
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #4
|
||||
SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, #9
|
||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #14
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #19
|
||||
FunctionCall, Label] #24
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, RegToSlot, SlotToReg, #4
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #9
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #14
|
||||
Label,] #19
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
@ -27,30 +26,25 @@ module Risc
|
||||
assert_load( produced , Parfait::Integer)
|
||||
assert_equal 5 , produced.constant.value
|
||||
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
|
||||
produced = produce_body.next(13)
|
||||
produced = produce_body.next(7)
|
||||
assert_load( produced , Parfait::Block)
|
||||
assert_equal :main_block , produced.constant.name
|
||||
end
|
||||
def ttest_load_return
|
||||
produced = produce_body.next(18)
|
||||
def test_load_return
|
||||
produced = produce_body.next(10)
|
||||
assert_load( produced , Label)
|
||||
assert produced.constant.name.start_with?("continue_")
|
||||
end
|
||||
def test_function_call
|
||||
produced = produce_body.next(20)
|
||||
produced = produce_body.next(14)
|
||||
assert_equal FunctionCall , produced.class
|
||||
assert_equal :main , produced.method.name
|
||||
end
|
||||
def test_check_continue
|
||||
produced = produce_body.next(22)
|
||||
produced = produce_body.next(15)
|
||||
assert_equal Label , produced.class
|
||||
# assert produced.name.start_with?("continue_") , produced.name
|
||||
assert produced.name.start_with?("continue_") , produced.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 27 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 23 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntComp2Risc < BootTest
|
||||
@ -23,7 +23,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -19,7 +19,7 @@ module Mom
|
||||
end
|
||||
def test_risc_length
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -19,25 +19,5 @@ module Risc
|
||||
assert_load( produced , Parfait::Integer)
|
||||
assert_equal 1 , produced.constant.value
|
||||
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
|
||||
|
@ -2,7 +2,7 @@ require_relative '../helper'
|
||||
|
||||
module Risc
|
||||
module Statements
|
||||
|
||||
include Output
|
||||
def setup
|
||||
end
|
||||
|
||||
@ -10,9 +10,8 @@ module Risc
|
||||
[ Label ]
|
||||
end
|
||||
def postamble
|
||||
[Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
||||
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
|
||||
SlotToReg, FunctionReturn, Label]
|
||||
[Label, SlotToReg, SlotToReg, RegToSlot,SlotToReg,
|
||||
SlotToReg, SlotToReg, FunctionReturn, Label,]
|
||||
end
|
||||
def produce_body
|
||||
produced = produce_main
|
||||
@ -72,12 +71,7 @@ module Risc
|
||||
def should( all )
|
||||
preamble.each {all.shift}
|
||||
postamble.each {all.pop}
|
||||
str = all.collect{|i| i.class.name}.join(", ").gsub("Risc::","")
|
||||
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
|
||||
class_list(all.collect{|i| i.class})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -14,11 +14,10 @@ module Risc
|
||||
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24
|
||||
Label, LoadConstant, SlotToReg, Transfer, Syscall, #29
|
||||
Transfer, Transfer, SlotToReg, RegToSlot, Label, #34
|
||||
RegToSlot, Label, LoadConstant, SlotToReg, LoadConstant, #39
|
||||
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, #44
|
||||
RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #49
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #54
|
||||
SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, Branch]
|
||||
RegToSlot, Label, LoadConstant, SlotToReg, RegToSlot, #39
|
||||
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #44
|
||||
SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, #49
|
||||
DynamicJump, Label, SlotToReg, RegToSlot, Branch,] #54
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
@ -31,12 +30,12 @@ module Risc
|
||||
end
|
||||
def test_load_address
|
||||
produced = produce_body
|
||||
assert_equal LoadConstant , produced.next(39).class
|
||||
assert_equal Parfait::Factory , produced.next(39).constant.class
|
||||
assert_equal LoadConstant , produced.next(26).class
|
||||
assert_equal Parfait::Factory , produced.next(26).constant.class
|
||||
end
|
||||
def test_function_call
|
||||
produced = produce_body
|
||||
assert_equal DynamicJump , produced.next(56).class
|
||||
assert_equal DynamicJump , produced.next(50).class
|
||||
end
|
||||
def test_cache_check
|
||||
produced = produce_body
|
||||
|
@ -7,31 +7,30 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "5.div4"
|
||||
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
||||
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg,
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
|
||||
FunctionCall, Label, SlotToReg, RegToSlot, Branch]
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
|
||||
Label, SlotToReg, RegToSlot, Branch,] #14
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
def test_load_5
|
||||
produced = produce_body.next(8)
|
||||
produced = produce_body.next(2)
|
||||
assert_load( produced , Parfait::Integer)
|
||||
assert_equal 5 , produced.constant.value
|
||||
end
|
||||
def test_load_label
|
||||
produced = produce_body.next(11)
|
||||
produced = produce_body.next(5)
|
||||
assert_load( produced , Label)
|
||||
end
|
||||
def test_function_call
|
||||
produced = produce_body.next(15)
|
||||
produced = produce_body.next(9)
|
||||
assert_equal FunctionCall , produced.class
|
||||
assert_equal :div4 , produced.method.name
|
||||
end
|
||||
def test_check_continue
|
||||
produced = produce_body.next(16)
|
||||
produced = produce_body.next(10)
|
||||
assert_equal Label , produced.class
|
||||
assert produced.name.start_with?("continue_")
|
||||
end
|
||||
|
@ -7,11 +7,10 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "5.get_internal_word(1)"
|
||||
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, #4
|
||||
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, #9
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #14
|
||||
SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, #19
|
||||
SlotToReg, RegToSlot, Branch] #24
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
|
||||
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #9
|
||||
RegToSlot, SlotToReg, FunctionCall, Label, SlotToReg, #14
|
||||
RegToSlot, Branch,] #19
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
@ -19,11 +18,11 @@ module Risc
|
||||
end
|
||||
def test_load_5
|
||||
produced = produce_body
|
||||
assert_equal LoadConstant , produced.next(8).class
|
||||
assert_equal 5 , produced.next(8).constant.value
|
||||
assert_equal LoadConstant , produced.next(2).class
|
||||
assert_equal 5 , produced.next(2).constant.value
|
||||
end
|
||||
def base
|
||||
11
|
||||
5
|
||||
end
|
||||
def test_load_arg_const
|
||||
produced = produce_body
|
||||
|
@ -7,53 +7,23 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "return 5.div4"
|
||||
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
||||
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg,
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
|
||||
FunctionCall, Label, SlotToReg, RegToSlot, Branch]
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
|
||||
Label, SlotToReg, RegToSlot, Branch] #14
|
||||
@produced = produce_body
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
def pest_load_method
|
||||
def test_load_method
|
||||
method = @produced
|
||||
assert_load( method, Parfait::CallableMethod ,:r1)
|
||||
assert_equal :div4 , method.constant.name
|
||||
end
|
||||
def pest_load_space
|
||||
space = @produced.next(1)
|
||||
assert_load( space , Parfait::Factory , :r2 )
|
||||
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
|
||||
def test_store_method_in_message
|
||||
sl = @produced.next( 1 )
|
||||
assert_reg_to_slot( sl , :r1 , :r2 , 7 )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -15,7 +15,6 @@ module Risc
|
||||
def test_if_instructions
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
|
||||
def test_false_load
|
||||
produced = produce_body
|
||||
assert_equal Parfait::FalseClass , produced.next(2).constant.class
|
||||
|
@ -30,7 +30,7 @@ module Mom
|
||||
def test_compiles_all_risc
|
||||
compiler = in_test_vool().compilers.first.to_risc
|
||||
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
|
||||
|
@ -48,7 +48,7 @@ module Mom
|
||||
end
|
||||
def test_has_risc_instructions
|
||||
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
|
||||
|
@ -7,22 +7,21 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "return 5.div4"
|
||||
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, #4
|
||||
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, #9
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #14
|
||||
FunctionCall, Label, SlotToReg, RegToSlot, Branch] #19
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
|
||||
Label, SlotToReg, RegToSlot, Branch,] #14
|
||||
end
|
||||
|
||||
def test_return_instructions
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
def test_function_return
|
||||
produced = produce_body.next(19)
|
||||
produced = produce_body.next(13)
|
||||
assert_equal Branch , produced.class
|
||||
assert_equal "return_label" , produced.label.name
|
||||
end
|
||||
def test_load_5
|
||||
produced = produce_body.next(8)
|
||||
produced = produce_body.next(2)
|
||||
assert_equal LoadConstant , produced.class
|
||||
assert_equal 5 , produced.constant.value
|
||||
end
|
||||
|
@ -7,19 +7,17 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "return @a.div4"
|
||||
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #4
|
||||
@expect =[LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #4
|
||||
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #9
|
||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #14
|
||||
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #19
|
||||
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24
|
||||
Label, LoadConstant, SlotToReg, Transfer, Syscall, #29
|
||||
Transfer, Transfer, SlotToReg, RegToSlot, Label, #34
|
||||
RegToSlot, Label, LoadConstant, SlotToReg, LoadConstant, #39
|
||||
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, #44
|
||||
RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #49
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #54
|
||||
SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, #59
|
||||
Branch] #64
|
||||
RegToSlot, Label, LoadConstant, SlotToReg, RegToSlot, #39
|
||||
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #44
|
||||
SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, #49
|
||||
DynamicJump, Label, SlotToReg, RegToSlot, Branch,] #54
|
||||
end
|
||||
|
||||
def test_return_instructions
|
||||
@ -27,7 +25,7 @@ module Risc
|
||||
end
|
||||
def test_function_return
|
||||
produced = produce_body
|
||||
assert_equal Branch , produced.next(60).class
|
||||
assert_equal Branch , produced.next(54).class
|
||||
end
|
||||
def test_cache_check
|
||||
produced = produce_body
|
||||
|
@ -9,8 +9,8 @@ module Risc
|
||||
@input = "return 5.div4"
|
||||
@expect = "something"
|
||||
end
|
||||
def instruction(num) # 21 is the main, see length in test/mom/send/test_setup_simple.rb
|
||||
produce_main.next( 21 + num)
|
||||
def instruction(num) # 15 is the main, see length in support/risc_interpreter.rb main_at
|
||||
produce_main.next( 15 + num)
|
||||
end
|
||||
def test_postamble_classes
|
||||
postamble.each_with_index do |ins , index|
|
||||
@ -30,37 +30,23 @@ module Risc
|
||||
def test_save_ret
|
||||
assert_reg_to_slot( instruction( 3 ) , :r1 , :r2 , 5 )
|
||||
end
|
||||
|
||||
def test_load_space
|
||||
assert_load( instruction(4) , Parfait::Factory )
|
||||
end
|
||||
def test_get_next
|
||||
assert_slot_to_reg( instruction( 5 ) , :r3 , 2 , :r4 )
|
||||
assert_slot_to_reg( instruction( 4 ) , :r0 , 4 , :r3 )
|
||||
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
|
||||
assert_slot_to_reg( instruction( 8 ) , :r0 , 4 , :r1 )
|
||||
end
|
||||
def test_reduce_addr
|
||||
assert_slot_to_reg( instruction( 9 ) , :r1 , 2 , :r1 )
|
||||
assert_slot_to_reg( instruction( 5 ) , :r3 , 2 , :r3 )
|
||||
end
|
||||
def test_reduce_caller
|
||||
assert_slot_to_reg( instruction( 10 ) , :r0 , 6 , :r0 )
|
||||
assert_slot_to_reg( instruction( 6 ) , :r0 , 6 , :r0 )
|
||||
end
|
||||
def test_function_return
|
||||
ret = instruction(11)
|
||||
ret = instruction(7)
|
||||
assert_equal FunctionReturn , ret.class
|
||||
assert_equal :r1 , ret.register.symbol
|
||||
assert_equal :r3 , ret.register.symbol
|
||||
end
|
||||
def test_unreachable
|
||||
assert_equal Label , instruction(12).class
|
||||
assert_equal "unreachable" , instruction(12).name
|
||||
assert_equal Label , instruction(8).class
|
||||
assert_equal "unreachable" , instruction(8).name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -7,14 +7,12 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "while(5 > 0) ; @a = true; end;return"
|
||||
@expect = [Label, LoadConstant, LoadConstant, SlotToReg, SlotToReg, #4
|
||||
RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, #9
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #14
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #19
|
||||
Label, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #24
|
||||
LoadConstant, OperatorInstruction, IsZero, LoadConstant, SlotToReg, #29
|
||||
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #34
|
||||
Branch] #39
|
||||
@expect = [Label, LoadConstant, RegToSlot, LoadConstant, SlotToReg, #4
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #9
|
||||
SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, #14
|
||||
SlotToReg, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #19
|
||||
OperatorInstruction, IsZero, LoadConstant, SlotToReg, RegToSlot, #24
|
||||
Branch, Label, LoadConstant, RegToSlot, Branch,] #29
|
||||
end
|
||||
|
||||
def test_while_instructions
|
||||
@ -25,30 +23,30 @@ module Risc
|
||||
end
|
||||
def test_int_load_5
|
||||
produced = produce_body
|
||||
load = produced.next(9)
|
||||
load = produced.next(3)
|
||||
assert_equal Risc::LoadConstant , load.class
|
||||
assert_equal Parfait::Integer , load.constant.class
|
||||
assert_equal 5 , load.constant.value
|
||||
end
|
||||
def test_int_load_0
|
||||
produced = produce_body
|
||||
load = produced.next(12)
|
||||
load = produced.next(6)
|
||||
assert_equal Risc::LoadConstant , load.class
|
||||
assert_equal Parfait::Integer , load.constant.class
|
||||
assert_equal 0 , load.constant.value
|
||||
end
|
||||
def test_false_check
|
||||
produced = produce_body
|
||||
assert_equal Risc::IsZero , produced.next(24).class
|
||||
assert produced.next(24).label.name.start_with?("merge_label") , produced.next(24).label.name
|
||||
assert_equal Risc::IsZero , produced.next(18).class
|
||||
assert produced.next(18).label.name.start_with?("merge_label") , produced.next(18).label.name
|
||||
end
|
||||
def test_nil_load
|
||||
produced = produce_body
|
||||
assert_equal Risc::LoadConstant , produced.next(28).class
|
||||
assert_equal Parfait::TrueClass , produced.next(28).constant.class
|
||||
assert_equal Risc::LoadConstant , produced.next(22).class
|
||||
assert_equal Parfait::TrueClass , produced.next(22).constant.class
|
||||
end
|
||||
|
||||
def test_back_jump # should jump back to condition label
|
||||
def ttest_back_jump # should jump back to condition label
|
||||
produced = produce_body
|
||||
assert_equal Risc::Branch , produced.next(31).class
|
||||
assert_equal produced.name , produced.next(31).label.name
|
||||
|
11
test/support/output.rb
Normal file
11
test/support/output.rb
Normal 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
|
@ -5,6 +5,7 @@ require_relative "compiling"
|
||||
module Risc
|
||||
module Ticker
|
||||
include ScopeHelper
|
||||
include Output
|
||||
|
||||
def setup
|
||||
compiler = RubyX::RubyXCompiler.new(RubyX.interpreter_test_options)
|
||||
@ -41,7 +42,7 @@ module Risc
|
||||
# how many instruction up until the main starts, ie
|
||||
# ticks(main_at) will be the label for main
|
||||
def main_at
|
||||
19
|
||||
13
|
||||
end
|
||||
|
||||
def get_return
|
||||
@ -131,15 +132,7 @@ module Risc
|
||||
end
|
||||
|
||||
def output_classes(classes)
|
||||
str = " ["
|
||||
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}"
|
||||
puts class_list(classes)
|
||||
exit(1)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user