misc little test fixes

This commit is contained in:
Torsten Ruger 2018-07-03 10:12:40 +03:00
parent bb1d1495db
commit cab6bc389f
7 changed files with 30 additions and 34 deletions

View File

@ -19,8 +19,8 @@ module Elf
in_space("def main(arg);#{input};end") in_space("def main(arg);#{input};end")
end end
def check(input, file) def check(input, file)
RubyX::RubyXCompiler.new(input).ruby_to_binary( :arm ) linker = RubyX::RubyXCompiler.new(input).ruby_to_binary( :arm )
writer = Elf::ObjectWriter.new(Risc.machine) writer = Elf::ObjectWriter.new(linker)
writer.save "test/#{file}.o" writer.save "test/#{file}.o"
end end

View File

@ -27,7 +27,7 @@ module Parfait
assert_equal Parfait::Space , space.class assert_equal Parfait::Space , space.class
type = space.get_type type = space.get_type
assert_equal Parfait::Type , type.class assert_equal Parfait::Type , type.class
assert_equal 8 , type.names.get_length assert_equal 12 , type.names.get_length
assert_equal type.object_class.class , Parfait::Class assert_equal type.object_class.class , Parfait::Class
assert_equal type.object_class.name , :Space assert_equal type.object_class.name , :Space
end end

View File

@ -82,7 +82,7 @@ module Risc
sl = main_ticks(base + 7) sl = main_ticks(base + 7)
assert_equal SlotToReg , sl.class assert_equal SlotToReg , sl.class
assert_equal :r3 , sl.array.symbol #load from space assert_equal :r3 , sl.array.symbol #load from space
assert_equal 4 , sl.index assert_equal 5 , sl.index
assert_equal :r2 , sl.register.symbol assert_equal :r2 , sl.register.symbol
assert_equal Parfait::Integer , @interpreter.get_register(:r2).class assert_equal Parfait::Integer , @interpreter.get_register(:r2).class
end end
@ -98,7 +98,7 @@ module Risc
sl = main_ticks(base + 9) sl = main_ticks(base + 9)
assert_equal RegToSlot , sl.class assert_equal RegToSlot , sl.class
assert_equal :r3 , sl.array.symbol #store to space assert_equal :r3 , sl.array.symbol #store to space
assert_equal 4 , sl.index assert_equal 5 , sl.index
assert_equal :r4 , sl.register.symbol assert_equal :r4 , sl.register.symbol
end end
def test_sys def test_sys

View File

@ -6,7 +6,7 @@ module Risc
def setup def setup
Parfait.boot! Parfait.boot!
@binary = Parfait::BinaryCode.new(1) @binary = Parfait::BinaryCode.new(1)
@bin_pos = CodeListener.init(@binary).set(0) @bin_pos = CodeListener.init(@binary,:interpreter).set(0)
@label = Label.new("HI","ho" , FakeAddress.new(2)) @label = Label.new("HI","ho" , FakeAddress.new(2))
@branch = DummyBranch.new( "Dummy" , @label ) @branch = DummyBranch.new( "Dummy" , @label )
@branch.insert @label @branch.insert @label

View File

@ -11,6 +11,11 @@ module Risc
def test_class def test_class
assert_equal Risc::Interpreter , Interpreter.new(@linker).class assert_equal Risc::Interpreter , Interpreter.new(@linker).class
end end
def test_starts
interpreter = Interpreter.new(@linker)
@linker.position_all
assert_equal 0 , interpreter.start_program
end
def test_starts_stopped def test_starts_stopped
assert_equal :stopped , Interpreter.new(@linker).state assert_equal :stopped , Interpreter.new(@linker).state
end end
@ -27,15 +32,10 @@ module Risc
@string_input = as_main("return 5") @string_input = as_main("return 5")
super super
end end
def test_starts
assert_equal 0 , @interpreter.start_program
end
def test_started def test_started
@interpreter.start_program
assert_equal :running , @interpreter.state assert_equal :running , @interpreter.state
end end
def test_pos def test_pos
@interpreter.start_program
assert_equal 1 , @interpreter.clock assert_equal 1 , @interpreter.clock
end end
end end
@ -44,7 +44,6 @@ module Risc
def setup def setup
@string_input = as_main("return 5") @string_input = as_main("return 5")
super super
@interpreter.start_program
end end
def test_tick1 def test_tick1
assert_equal 2 , @interpreter.tick assert_equal 2 , @interpreter.tick

View File

@ -9,13 +9,15 @@ module Risc
end end
def in_test_vool(str) def in_test_vool(str)
input = in_Test(str) vool = RubyX::RubyXCompiler.new(in_Test(str)).ruby_to_vool
vool = RubyX::RubyXCompiler.new(input).ruby_to_vool
vool.to_mom(nil) vool.to_mom(nil)
vool vool
end end
def create_method def in_test_mom(str)
vool = in_test_vool("def meth; @ivar = 5;end") RubyX::RubyXCompiler.new(in_Test(str)).ruby_to_mom()
end
def create_method(body = "@ivar = 5")
in_test_vool("def meth; #{body};end")
test = Parfait.object_space.get_class_by_name(:Test) test = Parfait.object_space.get_class_by_name(:Test)
test.get_method(:meth) test.get_method(:meth)
end end
@ -48,42 +50,37 @@ module Risc
end end
def test_method_statement_has_class def test_method_statement_has_class
input = in_Test("def meth; @ivar = 5;end") vool = in_test_vool("def meth; @ivar = 5;end")
vool = RubyX::RubyXCompiler.new(input).ruby_to_vool
clazz = vool.to_mom(nil)
assert vool.body.first.clazz assert vool.body.first.clazz
end end
def test_parfait_class_creation def test_parfait_class_creation
input = in_Test("def meth; @ivar = 5;end") vool = in_test_vool("def meth; @ivar = 5;end")
vool = RubyX::RubyXCompiler.new(input).ruby_to_vool
clazz = vool.to_mom(nil)
assert_equal Parfait::Class , vool.body.first.clazz.class assert_equal Parfait::Class , vool.body.first.clazz.class
end end
def test_typed_method_instance_type def test_typed_method_instance_type
vool = in_test_vool("def meth; @ivar = 5; @ibar = 4;end") in_test_vool("def meth; @ivar = 5; @ibar = 4;end")
test = Parfait.object_space.get_class_by_name(:Test) test = Parfait.object_space.get_class_by_name(:Test)
method = test.instance_type.get_method(:meth) method = test.instance_type.get_method(:meth)
assert_equal 1, method.for_type.variable_index(:ivar) assert_equal 1, method.for_type.variable_index(:ivar)
assert_equal 2, method.for_type.variable_index(:ibar) assert_equal 2, method.for_type.variable_index(:ibar)
end end
def test_typed_method_has_one_local
def test_vool_method_has_one_local in_test_vool("def meth; local = 5 ; a = 6;end")
vool = in_test_vool("def meth; local = 5 ; a = 6;end")
test = Parfait.object_space.get_class_by_name(:Test) test = Parfait.object_space.get_class_by_name(:Test)
method = test.get_method(:meth) method = test.get_method(:meth)
assert_equal 3 , method.frame_type.instance_length assert_equal 3 , method.frame_type.instance_length
assert_equal 1 , method.frame_type.variable_index(:local) assert_equal 1 , method.frame_type.variable_index(:local)
assert_equal 2 , method.frame_type.variable_index(:a) assert_equal 2 , method.frame_type.variable_index(:a)
end end
def test_has_constant
def test_typed_method_has_one_local input = in_Test("def meth; return 'Hi';end")
vool = in_test_vool("def meth; local = 5 ; a = 6;end") mom = RubyX::RubyXCompiler.new(input).ruby_to_mom
test = Parfait.object_space.get_class_by_name(:Test) assert_equal Mom::MomCompiler , mom.class
method = test.instance_type.get_method(:meth) compiler = mom.method_compilers.last
assert_equal 3 , method.frame_type.instance_length assert_equal MethodCompiler , compiler.class
assert_equal 1 , method.frame_type.variable_index(:local) assert compiler.constants.include?("Hi")
end end
end end

View File

@ -4,7 +4,7 @@ module Risc
class TestPadding < MiniTest::Test class TestPadding < MiniTest::Test
def setup def setup
Risc.machine.boot Parfait.boot!
end end
def test_small def test_small