replace fake compiler with real

less room for error
This commit is contained in:
2020-02-28 12:54:17 +02:00
parent 393f0d9a60
commit 887d7b9bbb
10 changed files with 66 additions and 67 deletions

View File

@ -14,11 +14,11 @@ module SlotMachine
end
def pest_fail_on_right
load = SlotLoad.new( "test",[:message, :caller] , [:message ,:receiver,:type] )
assert_raises {load.to_risc(Risc::FakeCompiler.new)}
assert_raises {load.to_risc(Risc.test_compiler)}
end
def pest_fail_on_left_long
load = SlotLoad.new("test", [:message, :caller , :type , :type] , [:message,:type] )
assert_raises {load.to_risc(Risc::FakeCompiler.new)}
assert_raises {load.to_risc(Risc.test_compiler)}
end
end
end

View File

@ -6,34 +6,34 @@ module SlotMachine
def setup
Parfait.boot!(Parfait.default_test_options)
load = SlotLoad.new("test", [:message, :caller] , [:message,:type] )
@compiler = Risc::FakeCompiler.new
load.to_risc(@compiler)
@instructions = @compiler.instructions
compiler = Risc.test_compiler
load.to_risc(compiler)
@instructions = compiler.risc_instructions.next
end
def test_ins_class
assert_equal Risc::SlotToReg , @instructions[0].class
assert_equal Risc::SlotToReg , @instructions.class
end
def test_ins_next_class
assert_equal Risc::RegToSlot , @instructions[1].class
assert_equal Risc::RegToSlot , @instructions.next.class
end
def test_ins_arr
assert_equal :r0 , @instructions[0].array.symbol
assert_equal :r0 , @instructions.array.symbol
end
def test_ins_reg
assert_equal :r1 , @instructions[0].register.symbol
assert_equal :r2 , @instructions.register.symbol
end
def test_ins_index
assert_equal 0 , @instructions[0].index
assert_equal 0 , @instructions.index
end
def test_ins_next_reg
assert_equal :r1 , @instructions[1].register.symbol
assert_equal :r2 , @instructions.next.register.symbol
end
def test_ins_next_arr
assert_equal :r0 , @instructions[1].array.symbol
assert_equal :r0 , @instructions.next.array.symbol
end
def test_ins_next_index
assert_equal 6 , @instructions[1].index
assert_equal 6 , @instructions.next.index
end
end
end

View File

@ -5,50 +5,47 @@ module SlotMachine
def setup
Parfait.boot!(Parfait.default_test_options)
@compiler = Risc::FakeCompiler.new
compiler = Risc.test_compiler
load = SlotLoad.new( "test",[:message, :caller, :type] , [:message, :caller , :type] )
load.to_risc(@compiler)
@instructions = @compiler.instructions
load.to_risc(compiler)
@instructions = compiler.risc_instructions.next
end
def test_ins_next_classes
assert_equal Risc::SlotToReg , @instructions[0].class
assert_equal Risc::SlotToReg , @instructions[1].class
assert_equal Risc::SlotToReg , @instructions[2].class
assert_equal Risc::SlotToReg , @instructions.class
assert_equal Risc::SlotToReg , @instructions.next.class
assert_equal Risc::SlotToReg , @instructions.next(2).class
end
def test_ins_next_next_class
assert_equal Risc::RegToSlot , @instructions[3].class
assert_equal NilClass , @instructions[4].class
assert_equal Risc::RegToSlot , @instructions.next(3).class
assert_equal NilClass , @instructions.next(4).class
end
def test_ins_next_reg
assert_equal :r1 , @instructions[1].register.symbol
assert_equal :r2 , @instructions.next.register.symbol
end
def test_ins_next_arr
assert_equal :r1 , @instructions[1].array.symbol
assert_equal :r2 , @instructions.next.array.symbol
end
def test_ins_next_index
assert_equal 0 , @instructions[1].index
assert_equal 0 , @instructions.next.index
end
def test_ins_next_2_reg
assert_equal :r1 , @instructions[2].register.symbol
assert_equal :r3 , @instructions.next(2).register.symbol
end
def test_ins_next_2_arr
assert_equal :r0 , @instructions[2].array.symbol
assert_equal :r0 , @instructions.next(2).array.symbol
end
def test_ins_next_2_index
assert_equal 6 , @instructions[2].index
assert_equal 6 , @instructions.next(2).index
end
def test_ins_next_3_reg
assert_equal :r1 , @instructions[3].register.symbol
assert_equal :r2 , @instructions.next(3).register.symbol
end
def test_ins_next_3_arr
assert_equal :r1 , @instructions[3].array.symbol
assert_equal :r3 , @instructions.next(3).array.symbol
end
def test_ins_next_3_index
assert_equal 0 , @instructions[3].index
assert_equal 0 , @instructions.next(3).index
end
end
end

View File

@ -7,44 +7,44 @@ module SlotMachine
def setup
Parfait.boot!(Parfait.default_test_options)
method = make_method
@compiler = Risc::FakeCompiler.new
compiler = Risc.test_compiler
@cache_entry = Parfait::CacheEntry.new(method.frame_type, method)
load = SlotLoad.new("test", [@cache_entry , :cached_type] , [:message, :type] )
load.to_risc(@compiler)
@instructions = @compiler.instructions
load.to_risc(compiler)
@instructions = compiler.risc_instructions.next
end
def test_ins_next_class
assert_equal Risc::SlotToReg , @instructions[0].class
assert_equal Risc::LoadConstant, @instructions[1].class
assert_equal Risc::SlotToReg , @instructions.class
assert_equal Risc::LoadConstant, @instructions.next.class
end
def test_ins_next_class
assert_equal Risc::RegToSlot , @instructions[2].class
assert_equal NilClass , @instructions[3].class
assert_equal Risc::RegToSlot , @instructions.next(2).class
assert_equal NilClass , @instructions.next(3).class
end
def test_ins_load
assert_equal :r1 , @instructions[1].register.symbol
assert_equal Parfait::CacheEntry , @instructions[1].constant.class
assert_equal :r3 , @instructions.next.register.symbol
assert_equal Parfait::CacheEntry , @instructions.next.constant.class
end
def test_ins_next_reg
assert_equal :r1 , @instructions[0].register.symbol
assert_equal :r2 , @instructions.register.symbol
end
def test_ins_next_arr
assert_equal :r0 , @instructions[0].array.symbol
assert_equal :r0 , @instructions.array.symbol
end
def test_ins_next_index
assert_equal 0 , @instructions[0].index
assert_equal 0 , @instructions.index
end
def test_ins_next_2_reg
assert_equal :r1 , @instructions[2].register.symbol
assert_equal :r2 , @instructions.next(2).register.symbol
end
def test_ins_next_2_arr
assert_equal :r1 , @instructions[2].array.symbol
assert_equal :r3 , @instructions.next(2).array.symbol
end
def test_ins_next_2_index
assert_equal 1 , @instructions[2].index
assert_equal 1 , @instructions.next(2).index
end
end