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
|
2020-03-09 18:22:02 +01:00
|
|
|
include HasCompiler
|
|
|
|
|
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-10-03 19:55:41 +02:00
|
|
|
@method = SlotMachine::SlotCollection.compiler_for( :Space , :main,{},{}).callable
|
|
|
|
@compiler = Risc::MethodCompiler.new( @method , SlotMachine::Label.new( "source_name", "return_label"))
|
2019-09-13 13:07:12 +02:00
|
|
|
@builder = @compiler.builder(@method)
|
2018-08-06 09:11:12 +02:00
|
|
|
end
|
2018-11-24 21:40:22 +01:00
|
|
|
def test_prepare_int
|
2020-03-02 12:48:21 +01:00
|
|
|
assert @builder.prepare_int_return
|
2018-11-24 21:40:22 +01:00
|
|
|
end
|
2018-11-21 10:12:39 +01:00
|
|
|
def test_allocate_returns
|
|
|
|
int = @builder.allocate_int
|
2020-03-02 19:38:36 +01:00
|
|
|
assert int.symbol.to_s.split(".").first.start_with?("id_")
|
2018-11-21 10:12:39 +01:00
|
|
|
end
|
|
|
|
def test_allocate_len
|
|
|
|
int = @builder.allocate_int
|
2020-03-09 18:22:02 +01:00
|
|
|
assert_equal 22 , @builder.compiler.risc_instructions.length
|
|
|
|
end
|
|
|
|
def test_allocate
|
|
|
|
int = @builder.allocate_int
|
|
|
|
assert_allocate
|
2018-11-21 10:12:39 +01:00
|
|
|
end
|
2020-03-25 17:58:10 +01:00
|
|
|
def test_compiler
|
|
|
|
int = @builder.allocate_int
|
|
|
|
assert int.compiler
|
|
|
|
assert int.symbol.to_s.start_with?("id_fac")
|
|
|
|
end
|
2018-08-06 09:11:12 +02:00
|
|
|
end
|
|
|
|
end
|