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")
end
def check(input, file)
RubyX::RubyXCompiler.new(input).ruby_to_binary( :arm )
writer = Elf::ObjectWriter.new(Risc.machine)
linker = RubyX::RubyXCompiler.new(input).ruby_to_binary( :arm )
writer = Elf::ObjectWriter.new(linker)
writer.save "test/#{file}.o"
end

View File

@ -27,7 +27,7 @@ module Parfait
assert_equal Parfait::Space , space.class
type = space.get_type
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.name , :Space
end

View File

@ -82,7 +82,7 @@ module Risc
sl = main_ticks(base + 7)
assert_equal SlotToReg , sl.class
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 Parfait::Integer , @interpreter.get_register(:r2).class
end
@ -98,7 +98,7 @@ module Risc
sl = main_ticks(base + 9)
assert_equal RegToSlot , sl.class
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
end
def test_sys

View File

@ -6,7 +6,7 @@ module Risc
def setup
Parfait.boot!
@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))
@branch = DummyBranch.new( "Dummy" , @label )
@branch.insert @label

View File

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

View File

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

View File

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