2018-07-02 22:20:54 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2019-08-10 20:30:00 +02:00
|
|
|
module Risc
|
2018-07-02 22:20:54 +02:00
|
|
|
class TestMomCompilerTranslate < MiniTest::Test
|
|
|
|
include MomCompile
|
|
|
|
|
|
|
|
def setup
|
2019-09-13 13:07:12 +02:00
|
|
|
@comp = compile_mom( "class Space ; def main(); main{return 'Ho'};return 'Hi'; end; end;")
|
2019-08-10 20:30:00 +02:00
|
|
|
@linker = @comp.to_risc.translate(:interpreter)
|
2018-07-02 22:20:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_translate_class
|
2019-08-10 20:30:00 +02:00
|
|
|
assert_equal Linker , @linker.class
|
2018-07-02 22:20:54 +02:00
|
|
|
end
|
2018-07-03 09:12:22 +02:00
|
|
|
def test_linker_has_constants
|
|
|
|
assert_equal Array , @linker.constants.class
|
|
|
|
end
|
|
|
|
def test_linker_constants_not_empty
|
|
|
|
assert !@linker.constants.empty?
|
|
|
|
end
|
|
|
|
def test_linker_constants_contains_hi
|
|
|
|
assert @linker.constants.include?("Hi")
|
|
|
|
end
|
2018-08-01 15:27:34 +02:00
|
|
|
def test_linker_constants_contains_ho
|
|
|
|
assert @linker.constants.include?("Ho")
|
|
|
|
end
|
2018-07-02 22:20:54 +02:00
|
|
|
def test_translate_platform
|
2019-08-10 20:30:00 +02:00
|
|
|
assert_kind_of Platform , @linker.platform
|
2018-07-02 22:20:54 +02:00
|
|
|
end
|
|
|
|
def test_translate_assemblers
|
2019-08-10 20:30:00 +02:00
|
|
|
assert_equal Assembler , @linker.assemblers.first.class
|
2018-07-02 22:20:54 +02:00
|
|
|
end
|
|
|
|
def test_assembler_code
|
2019-08-10 20:30:00 +02:00
|
|
|
assert_equal Label , @linker.assemblers.first.instructions.class
|
2018-07-02 22:20:54 +02:00
|
|
|
end
|
|
|
|
def test_assembler_assembled
|
2019-08-10 20:30:00 +02:00
|
|
|
assert_equal LoadConstant , @linker.assemblers.first.instructions.next.class
|
2018-07-02 22:20:54 +02:00
|
|
|
end
|
|
|
|
def test_no_loops_in_chain
|
|
|
|
@linker.assemblers.each do |asm|
|
|
|
|
all = []
|
|
|
|
asm.instructions.each do |ins|
|
2018-07-30 13:10:24 +02:00
|
|
|
assert !all.include?(ins) , "Double in #{asm.callable.name}:#{ins}"
|
2018-07-02 22:20:54 +02:00
|
|
|
all << ins
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_no_risc
|
|
|
|
@linker.position_all
|
|
|
|
@linker.create_binary
|
|
|
|
@linker.assemblers.each do |asm|
|
|
|
|
asm.instructions.each do |ins|
|
|
|
|
ins.assemble(Util::DevNull.new)
|
|
|
|
end # risc instruction don't have an assemble
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|