2018-08-06 09:11:12 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class TestCompilerBuilder < MiniTest::Test
|
2019-09-13 13:07:12 +02:00
|
|
|
include Parfait::MethodHelper
|
2018-08-06 09:11:12 +02:00
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2019-09-13 13:07:12 +02:00
|
|
|
@method = Mom::MomCollection.compiler_for( :Space , :main,{},{}).callable
|
|
|
|
@compiler = Risc::MethodCompiler.new( @method , Mom::Label.new( "source_name", "return_label"))
|
|
|
|
@builder = @compiler.builder(@method)
|
2018-08-06 09:11:12 +02:00
|
|
|
end
|
|
|
|
def test_inserts_built
|
|
|
|
r1 = RegisterValue.new(:r1 , :Space)
|
2018-08-14 18:39:46 +02:00
|
|
|
@builder.build{ space! << r1 }
|
2018-08-06 09:11:12 +02:00
|
|
|
assert_equal Transfer , @compiler.risc_instructions.next.class
|
2018-08-08 19:53:06 +02:00
|
|
|
assert_equal RegisterValue , @builder.space.class
|
|
|
|
end
|
|
|
|
def test_loads
|
2018-08-14 18:39:46 +02:00
|
|
|
@builder.build{ space! << Parfait.object_space }
|
2018-08-08 19:53:06 +02:00
|
|
|
assert_equal LoadConstant , @compiler.risc_instructions.next.class
|
|
|
|
assert_equal RegisterValue , @builder.space.class
|
|
|
|
end
|
|
|
|
def test_two
|
2018-08-14 18:39:46 +02:00
|
|
|
@builder.build{ space! << Parfait.object_space ; integer! << 1}
|
2018-08-08 19:53:06 +02:00
|
|
|
assert_equal LoadConstant , @compiler.risc_instructions.next.class
|
|
|
|
assert_equal LoadData , @compiler.risc_instructions.next(2).class
|
|
|
|
end
|
|
|
|
def test_swap
|
|
|
|
test_two
|
|
|
|
@builder.swap_names( :space , :integer)
|
|
|
|
assert_equal :Integer , @builder.space.type.class_name
|
|
|
|
assert_equal :Space , @builder.integer.type.class_name
|
2018-08-06 09:11:12 +02:00
|
|
|
end
|
2018-11-24 21:40:22 +01:00
|
|
|
def test_prepare_int
|
|
|
|
int = @builder.prepare_int_return
|
|
|
|
assert_raises { @builder.integer_tmp}
|
|
|
|
end
|
2018-11-21 10:12:39 +01:00
|
|
|
def test_allocate_returns
|
|
|
|
int = @builder.allocate_int
|
|
|
|
assert_equal :r1 , int.symbol
|
|
|
|
end
|
|
|
|
def test_allocate_len
|
|
|
|
int = @builder.allocate_int
|
2019-08-23 18:25:02 +02:00
|
|
|
assert_equal 23 , @builder.compiler.risc_instructions.length
|
2018-11-21 10:12:39 +01:00
|
|
|
end
|
2018-08-06 09:11:12 +02:00
|
|
|
end
|
|
|
|
end
|