And we are green again

After having over 600 failing tests at one point, this does feel good.
Even better, most of the risc/interpreter tests where i didn't change anything came gree without changing the tests. ie we have binary compatibility.
This commit is contained in:
2019-08-14 11:11:26 +03:00
parent c13a8ceb11
commit b2260d856d
14 changed files with 73 additions and 38 deletions

View File

@ -10,7 +10,7 @@ module Risc
@expect = [LoadConstant, SlotToReg, RegToSlot]
end
def test_send_instructions
assert_nil msg = check_nil(produce_block) , msg
assert_nil msg = check_nil(:main_block) , msg
end
def test_load_5
produced = produce_block.next

View File

@ -16,8 +16,14 @@ module Risc
end
def test_send_instructions
assert_nil msg = check_nil , msg
assert_nil msg = check_nil(:main) , msg
end
def test_load_5
produced = produce_block.next
assert_load( produced , Parfait::Integer)
assert_equal 5 , produced.constant.value
end
def test_load_5
produced = produce_body
assert_load( produced , Parfait::Integer)

View File

@ -11,7 +11,7 @@ module Mom
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 48 , @method.to_risc.risc_instructions.length
assert_equal 37 , @method.to_risc.risc_instructions.length
end
end
end

View File

@ -0,0 +1,43 @@
require_relative "../helper"
module Risc
class TestClassCallSimple < MiniTest::Test
include Statements
def setup
super
@class_input = "def self.simple_return; return 1 ; end;"
@input = "return Test.simple_return"
@expect = [LoadConstant, RegToSlot, Branch]
end
def test_send_instructions
assert_nil msg = check_nil(:simple_return) , msg
end
def test_load_simple
produced = produce_target(:simple_return).next(1)
assert_load( produced , Parfait::Integer)
assert_equal 1 , produced.constant.value
end
# The normal send
def test_load_5
produced = produce_body.next(8)
assert_load( produced , Parfait::Class)
assert_equal :Test , produced.constant.name
end
def test_load_label
produced = produce_body.next(11)
assert_load( produced , Label)
end
def test_function_call
produced = produce_body.next(15)
assert_equal FunctionCall , produced.class
assert_equal :simple_return , produced.method.name
end
def test_check_continue
produced = produce_body.next(16)
assert_equal Label , produced.class
assert produced.name.start_with?("continue_")
end
end
end

View File

@ -14,13 +14,8 @@ module Risc
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
SlotToReg , FunctionReturn, Label]
end
# test hack to in place change object type
def add_space_field(name,type)
class_type = Parfait.object_space.get_type_by_class_name(:Space)
class_type.send(:private_add_instance_variable, name , type)
end
def produce_body
produced = produce_instructions
produced = produce_main
preamble.each{ produced = produced.next }
produced
end
@ -29,28 +24,26 @@ module Risc
"#{method_input} ; self.main{|val| #{block_input}}"
end
def as_test_main
"class Test; def main(arg);#{@input};end;end"
"class Test; #{@class_input if @class_input};def main(arg);#{@input};end;end"
end
def to_target
assert @expect , "No output given"
RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_target(as_test_main,:interpreter)
end
def find_main
assert @expect , "No output given"
linker = to_target
linker.assemblers.find{|c| c.callable.name == :main and c.callable.self_type.object_class.name == :Test}
end
def produce_instructions
find_main.instructions
def produce_main
produce_target(:main)
end
def produce_block
produce_target(:main_block)
end
def produce_target(name = :main_block)
linker = to_target
block = linker.assemblers.find {|c| c.callable.name == :main_block}
block = linker.assemblers.find {|c| c.callable.name == name }
assert_equal Risc::Assembler , block.class
block.instructions
end
def check_nil( instructions = nil )
produced = instructions || produce_instructions
def check_nil( name = :main )
produced = produce_target( name )
compare_instructions( produced , @expect )
end
def check_return

View File

@ -8,10 +8,9 @@ module Risc
super
@input = "5.div4"
@expect = "something"
@produced = produce_instructions
end
def instruction(num) # 18 is the main, see length in test/mom/send/test_setup_simple.rb
@produced.next( 18 + num)
produce_main.next( 18 + num)
end
def test_postamble_classes
postamble.each_with_index do |ins , index|