2018-05-17 08:31:36 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class TestInterpreterPlatform < MiniTest::Test
|
|
|
|
def setup
|
|
|
|
@inter = Platform.for("Interpreter")
|
|
|
|
end
|
|
|
|
def test_platform_class
|
|
|
|
assert_equal Risc::InterpreterPlatform , @inter.class
|
|
|
|
end
|
|
|
|
def test_platform_translator_class
|
|
|
|
assert_equal Risc::IdentityTranslator , @inter.translator.class
|
|
|
|
end
|
|
|
|
def test_platform_loaded_class
|
|
|
|
assert_equal Fixnum , @inter.loaded_at.class
|
|
|
|
end
|
|
|
|
def test_translator
|
|
|
|
assert IdentityTranslator.new
|
|
|
|
end
|
|
|
|
end
|
2018-05-17 08:49:01 +02:00
|
|
|
class TestIdentityTranslator < MiniTest::Test
|
2018-05-17 08:31:36 +02:00
|
|
|
|
|
|
|
def setup
|
|
|
|
@machine = Risc.machine.boot
|
|
|
|
@translator = IdentityTranslator.new
|
|
|
|
end
|
|
|
|
|
2018-05-24 18:20:06 +02:00
|
|
|
def test_load_translates_label
|
2018-05-29 19:26:00 +02:00
|
|
|
label = Risc.label("test" , "test",nil)
|
2018-05-24 18:20:06 +02:00
|
|
|
load = Risc.load_constant("source" , label , :r1)
|
|
|
|
translated = @translator.translate(load)
|
|
|
|
assert label != translated.constant
|
|
|
|
end
|
2018-05-23 17:06:55 +02:00
|
|
|
def test_translate_first_label
|
2018-05-17 08:31:36 +02:00
|
|
|
label = Parfait.object_space.get_main.risc_instructions
|
|
|
|
assert_equal "Space_Type.main" ,label.to_cpu(@translator).name , label
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_translate_space
|
|
|
|
assert @machine.translate(:interpreter)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_loops_in_chain
|
|
|
|
@machine.translate(:interpreter)
|
|
|
|
@machine.position_all
|
|
|
|
init = Parfait.object_space.get_init
|
|
|
|
all = []
|
|
|
|
init.cpu_instructions.each do |ins|
|
|
|
|
assert !all.include?(ins)
|
|
|
|
all << ins
|
|
|
|
end
|
|
|
|
end
|
2018-05-17 08:49:01 +02:00
|
|
|
def test_no_risc
|
2018-05-17 08:31:36 +02:00
|
|
|
@machine.translate(:interpreter)
|
|
|
|
@machine.position_all
|
|
|
|
@machine.create_binary
|
2018-06-15 08:18:39 +02:00
|
|
|
@machine.object_positions.each do | method , position|
|
2018-05-17 08:31:36 +02:00
|
|
|
next unless method.is_a? Parfait::TypedMethod
|
|
|
|
method.cpu_instructions.each do |ins|
|
|
|
|
ins.assemble(DevNull.new)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|