Externalise register allocation into own class
On the way to the register allocation
This commit is contained in:
34
test/risc/test_allocator.rb
Normal file
34
test/risc/test_allocator.rb
Normal file
@ -0,0 +1,34 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestAllocator < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@allocator = Allocator.new
|
||||
end
|
||||
def tmp_reg
|
||||
Risc.tmp_reg(:Type)
|
||||
end
|
||||
def test_regs
|
||||
assert_equal Array , @allocator.regs.class
|
||||
end
|
||||
def test_empty
|
||||
assert @allocator.regs_empty?
|
||||
end
|
||||
def test_add_ok
|
||||
assert_equal Array, @allocator.add_reg(tmp_reg).class
|
||||
end
|
||||
def test_add_fail
|
||||
assert_raises{ @allocator.add_reg(1)}
|
||||
end
|
||||
def test_pop
|
||||
@allocator.add_reg(tmp_reg)
|
||||
assert_equal RegisterValue , @allocator.pop.class
|
||||
end
|
||||
def test_clear
|
||||
@allocator.clear_regs
|
||||
assert @allocator.regs_empty?
|
||||
end
|
||||
end
|
||||
end
|
@ -9,7 +9,32 @@ module Risc
|
||||
end
|
||||
end
|
||||
class TestCallableCompiler < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Parfait.boot!({})
|
||||
label = SlotMachine::Label.new("hi","ho")
|
||||
@compiler = CallableCompiler.new(FakeCallable.new , label)
|
||||
end
|
||||
def test_ok
|
||||
assert @compiler
|
||||
end
|
||||
def test_current
|
||||
assert @compiler.current
|
||||
end
|
||||
def test_current_label
|
||||
assert_equal Label , @compiler.current.class
|
||||
assert_equal "ho" , @compiler.current.name
|
||||
end
|
||||
def test_slot
|
||||
assert @compiler.risc_instructions
|
||||
end
|
||||
def test_const
|
||||
assert_equal Array , @compiler.constants.class
|
||||
end
|
||||
def test_use_reg
|
||||
@compiler.use_reg(:Type)
|
||||
end
|
||||
end
|
||||
class TestFakeCallableCompiler < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!({})
|
||||
label = SlotMachine::Label.new("hi","ho")
|
||||
|
Reference in New Issue
Block a user