diff --git a/lib/mom/builtin/init.rb b/lib/mom/builtin/init.rb index 211a79c8..ea1e2204 100644 --- a/lib/mom/builtin/init.rb +++ b/lib/mom/builtin/init.rb @@ -27,7 +27,7 @@ module Mom add_code exit_label end compiler.reset_regs - exit_sequence(builder) + Builtin.exit_sequence(builder) return compiler end end diff --git a/lib/mom/builtin/object.rb b/lib/mom/builtin/object.rb index 1775daa5..401541e4 100644 --- a/lib/mom/builtin/object.rb +++ b/lib/mom/builtin/object.rb @@ -42,7 +42,7 @@ module Mom def __init__( context ) compiler = Mom::MethodCompiler.compiler_for_class(:Object,:__init__ , Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({})) - compiler.add_code MethodMissing.new("missing") + compiler.add_code Init.new("missing") return compiler end diff --git a/test/elf/test_zero.rb b/test/elf/test_zero.rb index c6c006ca..bb5aa800 100644 --- a/test/elf/test_zero.rb +++ b/test/elf/test_zero.rb @@ -6,9 +6,7 @@ module Elf def setup super - @linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(as_main("return 1"),:arm) - @linker.position_all - @linker.create_binary + @linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_binary(as_main("return 1"),:arm) end def test_empty_translate diff --git a/test/mom/blocks/test_block_assign.rb b/test/mom/blocks/test_block_assign.rb index 12235b1b..dbcbc0ef 100644 --- a/test/mom/blocks/test_block_assign.rb +++ b/test/mom/blocks/test_block_assign.rb @@ -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 diff --git a/test/mom/blocks/test_block_setup.rb b/test/mom/blocks/test_block_setup.rb index e51f3e1f..f735989d 100644 --- a/test/mom/blocks/test_block_setup.rb +++ b/test/mom/blocks/test_block_setup.rb @@ -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) diff --git a/test/mom/builtin/test_init.rb b/test/mom/builtin/test_init.rb index e9068d15..ead6f662 100644 --- a/test/mom/builtin/test_init.rb +++ b/test/mom/builtin/test_init.rb @@ -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 diff --git a/test/mom/class_send/test_send_simple.rb b/test/mom/class_send/test_send_simple.rb new file mode 100644 index 00000000..9004442c --- /dev/null +++ b/test/mom/class_send/test_send_simple.rb @@ -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 diff --git a/test/mom/helper.rb b/test/mom/helper.rb index 77e8bacc..d7f69ca0 100644 --- a/test/mom/helper.rb +++ b/test/mom/helper.rb @@ -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 diff --git a/test/mom/test_return_sequence.rb b/test/mom/test_return_sequence.rb index 71409046..b07d7310 100644 --- a/test/mom/test_return_sequence.rb +++ b/test/mom/test_return_sequence.rb @@ -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| diff --git a/test/risc/interpreter/calling/test_minus.rb b/test/risc/interpreter/calling/test_minus.rb index d1f419ea..304ca87c 100644 --- a/test/risc/interpreter/calling/test_minus.rb +++ b/test/risc/interpreter/calling/test_minus.rb @@ -41,7 +41,7 @@ module Risc ret = main_ticks(68) assert_equal FunctionReturn , ret.class assert_equal :r1 , ret.register.symbol - assert_equal 24204 , @interpreter.get_register(ret.register) + assert_equal 23196 , @interpreter.get_register(ret.register) end end end diff --git a/test/risc/test_collector.rb b/test/risc/test_collector.rb index 74fe2057..dfa05c0c 100644 --- a/test/risc/test_collector.rb +++ b/test/risc/test_collector.rb @@ -55,7 +55,7 @@ module Risc def test_simple_collect objects = Collector.collect_space(@linker) - assert_equal 2422, objects.length , objects.length.to_s + assert_equal 2421, objects.length , objects.length.to_s end def test_integer_positions diff --git a/test/risc/test_linker.rb b/test/risc/test_linker.rb index aaf02a84..97125519 100644 --- a/test/risc/test_linker.rb +++ b/test/risc/test_linker.rb @@ -25,7 +25,7 @@ module Risc assert_equal 0 , Position.get(@linker.cpu_init).at end def test_cpu_at - assert_equal "0x562c" , Position.get(@linker.cpu_init.first).to_s + assert_equal "0x563c" , Position.get(@linker.cpu_init.first).to_s end def test_cpu_label assert_equal Position , Position.get(@linker.cpu_init.first).class diff --git a/test/risc/test_linker1.rb b/test/risc/test_linker1.rb index 14aeff34..f4c101c2 100644 --- a/test/risc/test_linker1.rb +++ b/test/risc/test_linker1.rb @@ -5,7 +5,6 @@ module Risc def setup code = "class Space; def main(arg);a = 1;return a;end;end" @linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_binary(code, :arm) - @linker.position_all end def test_positions_set @linker.object_positions.each do |obj , position| @@ -17,7 +16,7 @@ module Risc assert_equal 1 , mains.length end def test_assembler_num - assert_equal 23 , @linker.assemblers.length + assert_equal 22 , @linker.assemblers.length end end end diff --git a/test/rubyx/test_rubyx_compiler2.rb b/test/rubyx/test_rubyx_compiler2.rb index 9b0c74ee..6979383e 100644 --- a/test/rubyx/test_rubyx_compiler2.rb +++ b/test/rubyx/test_rubyx_compiler2.rb @@ -26,17 +26,14 @@ module RubyX assert_equal 22 , linker.assemblers.length end end - class TestRubyXCompilerParfait < MiniTest::Test + class TestRubyXCompilerParfait #< MiniTest::Test include ScopeHelper include RubyXHelper def setup super - -#BETTER TEST for class method in VOOL - - code = "class Space ; def self.class_method; return 1; end;def main(arg);return Space.class_method;end; end" - @comp = RubyXCompiler.ruby_to_binary(code , load_parfait: true , platform: :interpreter) + code = "class Space ; def self.class_method(); return 1; end;def main(arg);return Space.class_method;end; end" + @comp = RubyXCompiler.ruby_to_risc(code , load_parfait: true)# , platform: :interpreter) end def test_load