replace fake compiler with real
less room for error
This commit is contained in:
parent
393f0d9a60
commit
887d7b9bbb
@ -11,8 +11,7 @@ module Risc
|
||||
class TestCallableCompiler < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!({})
|
||||
label = SlotMachine::Label.new("hi","ho")
|
||||
@compiler = CallableCompiler.new(FakeCallable.new , label)
|
||||
@compiler = Risc.test_compiler
|
||||
end
|
||||
def test_ok
|
||||
assert @compiler
|
||||
@ -22,7 +21,7 @@ module Risc
|
||||
end
|
||||
def test_current_label
|
||||
assert_equal Label , @compiler.current.class
|
||||
assert_equal "ho" , @compiler.current.name
|
||||
assert_equal "start_label" , @compiler.current.name
|
||||
end
|
||||
def test_slot
|
||||
assert @compiler.risc_instructions
|
||||
|
@ -7,7 +7,7 @@ module Risc
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@r0 = RegisterValue.new(:r0 , :Message)
|
||||
@r1 = RegisterValue.new(:r1 , :Space)
|
||||
@compiler = FakeCompiler.new
|
||||
@compiler = Risc.test_compiler
|
||||
end
|
||||
|
||||
def test_resolves_index_ok
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -5,10 +5,10 @@ module SlotMachine
|
||||
class TestSlotConstant < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
compiler = Risc::FakeCompiler.new
|
||||
compiler = Risc.test_compiler
|
||||
@slotted = Slotted.for(StringConstant.new("hi") , nil)
|
||||
register = @slotted.to_register(compiler , InstructionMock.new)
|
||||
@instruction = compiler.instructions.first
|
||||
@instruction = compiler.risc_instructions.next
|
||||
end
|
||||
def test_def_class
|
||||
assert_equal Risc::LoadConstant , @instruction.class
|
||||
@ -23,10 +23,10 @@ module SlotMachine
|
||||
class TestSlotConstantType < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@compiler = Risc::FakeCompiler.new
|
||||
compiler = Risc.test_compiler
|
||||
@slotted = Slotted.for(StringConstant.new("hi") , [:type])
|
||||
register = @slotted.to_register(@compiler , InstructionMock.new)
|
||||
@instruction = @compiler.instructions.first
|
||||
register = @slotted.to_register(compiler , InstructionMock.new)
|
||||
@instruction = compiler.risc_instructions.next
|
||||
end
|
||||
def test_def_class
|
||||
assert_equal Risc::LoadConstant , @instruction.class
|
||||
@ -41,10 +41,10 @@ module SlotMachine
|
||||
assert_equal "StringConstant.type" , @slotted.to_s
|
||||
end
|
||||
def test_def_register2
|
||||
assert_equal :r1 , @compiler.instructions[1].register.symbol
|
||||
assert_equal :r1 , @instruction.next.register.symbol
|
||||
end
|
||||
def test_def_next_index
|
||||
assert_equal 0 , @compiler.instructions[1].index
|
||||
assert_equal 0 , @instruction.next.index
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,10 +4,10 @@ module SlotMachine
|
||||
class TestSlottedMessage2 < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
compiler = Risc::FakeCompiler.new
|
||||
compiler = Risc.test_compiler
|
||||
slotted = SlottedMessage.new([:caller])
|
||||
@register = slotted.to_register(compiler , "fake source")
|
||||
@instruction = compiler.instructions.first
|
||||
@instruction = compiler.risc_instructions.next
|
||||
end
|
||||
def test_def_class
|
||||
assert_equal Risc::SlotToReg , @instruction.class
|
||||
@ -19,7 +19,7 @@ module SlotMachine
|
||||
assert_equal :r0 , @instruction.array.symbol
|
||||
end
|
||||
def test_def_register # to next free register r1
|
||||
assert_equal :r1 , @register.symbol
|
||||
assert_equal :r2 , @register.symbol
|
||||
end
|
||||
def test_def_index # at caller index 6
|
||||
assert_equal 6 , @instruction.index
|
||||
|
@ -5,10 +5,10 @@ module SlotMachine
|
||||
class TestSlottedObjectType < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@compiler = Risc::FakeCompiler.new
|
||||
compiler = Risc.test_compiler
|
||||
@slotted = Slotted.for(Parfait.object_space , [:type])
|
||||
register = @slotted.to_register(@compiler , InstructionMock.new)
|
||||
@instruction = @compiler.instructions.first
|
||||
register = @slotted.to_register(compiler , InstructionMock.new)
|
||||
@instruction = compiler.risc_instructions.next
|
||||
end
|
||||
def test_def_class
|
||||
assert_equal Risc::LoadConstant , @instruction.class
|
||||
@ -23,10 +23,10 @@ module SlotMachine
|
||||
assert_equal "Space.type" , @slotted.to_s
|
||||
end
|
||||
def test_def_register2
|
||||
assert_equal :r1 , @compiler.instructions[1].register.symbol
|
||||
assert_equal :r1 , @instruction.next.register.symbol
|
||||
end
|
||||
def test_def_next_index
|
||||
assert_equal 0 , @compiler.instructions[1].index
|
||||
assert_equal 0 , @instruction.next.index
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -7,6 +7,9 @@ module Risc
|
||||
:fake_name
|
||||
end
|
||||
end
|
||||
def self.test_compiler(label = SlotMachine::Label.new("start","start_label"))
|
||||
CallableCompiler.new( FakeCallable.new , label)
|
||||
end
|
||||
class FakeCompiler
|
||||
attr_reader :instructions
|
||||
def initialize
|
||||
|
Loading…
Reference in New Issue
Block a user