diff --git a/lib/mom/instruction/message_setup.rb b/lib/mom/instruction/message_setup.rb index cc8a2fef..01989063 100644 --- a/lib/mom/instruction/message_setup.rb +++ b/lib/mom/instruction/message_setup.rb @@ -22,6 +22,7 @@ module Mom attr_reader :method_source def initialize(method_source) + raise "no nil" unless method_source @method_source = method_source end diff --git a/lib/mom/instruction/resolve_method.rb b/lib/mom/instruction/resolve_method.rb index f10bbd1c..4698046b 100644 --- a/lib/mom/instruction/resolve_method.rb +++ b/lib/mom/instruction/resolve_method.rb @@ -65,7 +65,7 @@ module Mom # temporary, need to raise really. factory! << Parfait.object_space.get_factory_for(:Integer) integer_tmp! << factory[:reserve] - Risc::Builtin::Object.emit_syscall( builder , :exit ) #uses integer_tmp + Mom::Builtin.emit_syscall( builder , :exit ) #uses integer_tmp add_code ok_label cache_entry[:cached_method] << callable_method diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index f75fb9fc..45726432 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -9,7 +9,7 @@ module Risc # space << Parfait.object_space # load constant # message[:receiver] << space #make current message's (r0) receiver the space # See http://ruby-x.org/rubyx/builder.html for details - # + # class Builder attr_reader :built , :compiler diff --git a/lib/risc/position/position.rb b/lib/risc/position/position.rb index e3159454..d3c4e915 100644 --- a/lib/risc/position/position.rb +++ b/lib/risc/position/position.rb @@ -186,7 +186,7 @@ module Risc # populate the position caches (forward and revese) with the given position # forward caches object -> position # reverse caches position.at > position - # Labels do not participatein reverse cache + # Labels do not participate in reverse cache def self.set_cache( position , to) postest = Position.positions[position.object] unless to < 0 raise "Mismatch #{position}" if postest and postest != position diff --git a/lib/rubyx/rubyx_compiler.rb b/lib/rubyx/rubyx_compiler.rb index c3f28ce3..b41bf585 100644 --- a/lib/rubyx/rubyx_compiler.rb +++ b/lib/rubyx/rubyx_compiler.rb @@ -1,5 +1,14 @@ module RubyX - # The RubyXCompiler provides the main interface to create binaries + # The RubyXCompiler provides the main interface to create binaries, and also + # give helper functions to create any intermediate layer. + # Layers are: + # - ruby , always needed as input, string + # - vool - intermediate language layer + # - mom - intermediate machine layer + # - risc - "last" intermediate machine layer + # - target - arm or interpreter binary code + # - binary - "linked" code, everything need to create an elf binary + # # # There are methods to go from ruby to any of the layers in the system # (mainly for testing). ruby_to_binary creates actual binary code @@ -38,42 +47,59 @@ module RubyX to_binary(platform) end - # Process previously stored vool source to binary. - # Binary code is generated byu calling to_risc, then positioning and calling - # create_binary on the linker. The linker may then be used to creat a binary file. - # The biary the method name refers to is binary code in memory, or in BinaryCode - # objects to be precise. - def to_binary(platform) - linker = to_risc - linker.position_all - linker.create_binary(platform) - linker + # ruby_to_target creates Target instructions (but does not link) + # + # After creating vool, we call to_target + # Return a Linker + def ruby_to_target(ruby) + ruby_to_vool(ruby) + to_target() end - # ruby_to_risc creates Risc instructions (as the name implies), but also - # translates those to the platform given + # ruby_to_risc creates Risc instructions # # After creating vool, we call to_risc + # Return a RiscCollection def ruby_to_risc(ruby) ruby_to_vool(ruby) to_risc() end - # Process previously stored vool source. First to mom, then to risc. - def to_risc() - mom = to_mom - mom.to_risc() - end - - # ruby_to_mom does exactly that, it transform the incoming ruby source (string) - # to mom - # The vool is stored using ruby_to_vool, and if there was previous source, - # this will also be momed + # Transform the incoming ruby source (string) to mom + # + # The vool is stored using ruby_to_vool,the to_mom is called + # Return Mom Statement def ruby_to_mom(ruby) ruby_to_vool(ruby) to_mom end + # Process previously stored vool source to binary. + # Binary code is generated by calling to_risc, then positioning and calling + # create_binary on the linker. The linker may then be used to creat a binary file. + # The biary the method name refers to is binary code in memory, or in BinaryCode + # objects to be precise. + def to_binary(platform) + linker = to_target(platform) + linker.position_all + linker.create_binary + linker + end + + # transform stored vool to target code + # return a linker + def to_target(platform) + collection = to_risc + collection.translate(platform) + end + + # Process previously stored vool source to risc. + # return a Risc::RiscCollection , a collection of MethodCompilers + def to_risc() + mom = to_mom + mom.to_risc() + end + # return mom for the previously stored vool source. def to_mom @vool.to_mom(nil) diff --git a/test/mom/instruction/test_slot_load.rb b/test/mom/instruction/test_slot_load.rb index 83de985c..600daabd 100644 --- a/test/mom/instruction/test_slot_load.rb +++ b/test/mom/instruction/test_slot_load.rb @@ -4,17 +4,17 @@ module Mom class TestSlotLoadBasics < MiniTest::Test def test_ins_ok - assert SlotLoad.new( [:message, :caller] , [:receiver,:type] ) + assert SlotLoad.new("test", [:message, :caller] , [:receiver,:type] ) end def test_ins_fail1 - assert_raises {SlotLoad.new( [:message, :caller] , nil )} + assert_raises {SlotLoad.new( "test",[:message, :caller] , nil )} end def test_fail_on_right - @load = SlotLoad.new( [:message, :caller] , [:receiver,:type] ) + @load = SlotLoad.new( "test",[:message, :caller] , [:receiver,:type] ) assert_raises {@load.to_risc(Risc::FakeCompiler.new)} end def test_fail_on_left_long - @load = SlotLoad.new( [:message, :caller , :type] , [:receiver,:type] ) + @load = SlotLoad.new("test", [:message, :caller , :type] , [:receiver,:type] ) assert_raises {@load.to_risc(Risc::FakeCompiler.new)} end end diff --git a/test/mom/instruction/test_slot_load1.rb b/test/mom/instruction/test_slot_load1.rb index 66e9fbb0..a3ce9139 100644 --- a/test/mom/instruction/test_slot_load1.rb +++ b/test/mom/instruction/test_slot_load1.rb @@ -5,7 +5,7 @@ module Mom def setup Parfait.boot!(Parfait.default_test_options) - load = SlotLoad.new( [:message, :caller] , [:message,:type] ) + load = SlotLoad.new("test", [:message, :caller] , [:message,:type] ) @compiler = Risc::FakeCompiler.new load.to_risc(@compiler) @instructions = @compiler.instructions diff --git a/test/mom/instruction/test_slot_load2.rb b/test/mom/instruction/test_slot_load2.rb index 3f8f3dd3..4a4aa637 100644 --- a/test/mom/instruction/test_slot_load2.rb +++ b/test/mom/instruction/test_slot_load2.rb @@ -6,7 +6,7 @@ module Mom def setup Parfait.boot!(Parfait.default_test_options) @compiler = Risc::FakeCompiler.new - load = SlotLoad.new( [:message, :caller, :type] , [:message, :caller , :type] ) + load = SlotLoad.new( "test",[:message, :caller, :type] , [:message, :caller , :type] ) load.to_risc(@compiler) @instructions = @compiler.instructions end diff --git a/test/mom/test_class_statement.rb b/test/mom/test_class_statement.rb index ed378d36..55e24d3f 100644 --- a/test/mom/test_class_statement.rb +++ b/test/mom/test_class_statement.rb @@ -2,7 +2,7 @@ require_relative "helper" module Vool - class TestClassStatement < MiniTest::Test + class TestClassStatementMom < MiniTest::Test include MomCompile def setup diff --git a/test/mom/test_mom_compiler.rb b/test/mom/test_mom_compiler.rb deleted file mode 100644 index 5ba6c0c3..00000000 --- a/test/mom/test_mom_compiler.rb +++ /dev/null @@ -1,40 +0,0 @@ -require_relative "helper" - -module Mom - class TestMomCompiler < MiniTest::Test - include MomCompile - - def setup - Parfait.boot!(Parfait.default_test_options) - @comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;") - end - - def test_class - assert_equal MomCompiler , @comp.class - end - def test_compilers - assert_equal 23 , @comp.compilers.length - end - def test_boot_compilers - assert_equal 22 , @comp.boot_compilers.length - end - def test_compilers_bare - assert_equal 22 , MomCompiler.new.compilers.length - end - def test_returns_constants - assert_equal Array , @comp.constants.class - end - def test_has_constant - assert_equal "Hi" , @comp.constants[1].to_string - end - def test_has_translate - assert @comp.translate(:interpreter) - end - def test_append_class - assert_equal MomCompiler, (@comp.append @comp).class - end - def test_append_length - assert_equal 2 , @comp.append(@comp).method_compilers.length - end - end -end diff --git a/test/parfait/test_space2.rb b/test/parfait/test_space2.rb index 0b08895d..4b1b519c 100644 --- a/test/parfait/test_space2.rb +++ b/test/parfait/test_space2.rb @@ -4,11 +4,11 @@ module Parfait class TestMethods < ParfaitTest def setup super - Risc::Builtin.boot_functions + Mom.boot! end def test_integer int = Parfait.object_space.get_class_by_name :Integer - assert_equal 14, int.instance_type.method_names.get_length + assert_equal 13, int.instance_type.method_names.get_length end def test_methods_booted word = @space.get_type_by_class_name(:Word) diff --git a/test/risc/interpreter/builtin/test_int_cmp.rb b/test/risc/interpreter/builtin/test_int_cmp.rb index af8b66da..e9024ee6 100644 --- a/test/risc/interpreter/builtin/test_int_cmp.rb +++ b/test/risc/interpreter/builtin/test_int_cmp.rb @@ -1,9 +1,9 @@ -require_relative "helper" +require_relative "../helper" # TODO move these to interpreter dir -module Mom +module Risc module Builtin - class IntCmp < BuiltinTest + class IntCmp < Minitest::Test include Ticker def setup end diff --git a/test/risc/interpreter/builtin/test_int_math.rb b/test/risc/interpreter/builtin/test_int_math.rb index c22cc652..514e947e 100644 --- a/test/risc/interpreter/builtin/test_int_math.rb +++ b/test/risc/interpreter/builtin/test_int_math.rb @@ -1,8 +1,8 @@ -require_relative "helper" +require_relative "../helper" -module Mom +module Risc module Builtin - class IntMath < BuiltinTest + class IntMath < Minitest::Test include Ticker def setup end diff --git a/test/risc/position/test_code_listener1.rb b/test/risc/position/test_code_listener1.rb index dccfdb5f..bb528e3d 100644 --- a/test/risc/position/test_code_listener1.rb +++ b/test/risc/position/test_code_listener1.rb @@ -5,7 +5,7 @@ module Risc def setup Parfait.boot!(Parfait.default_test_options) Risc.boot! - @linker = Mom::MomCompiler.new.translate(:interpreter) + @linker = Mom::MomCollection.new.to_risc.translate(:interpreter) @binary = Parfait::BinaryCode.new(1) @method = Parfait.object_space.types.values.first.methods @label = Risc.label("hi","ho") diff --git a/test/risc/position/test_position3.rb b/test/risc/position/test_position3.rb index 5a4060fe..b41a4a55 100644 --- a/test/risc/position/test_position3.rb +++ b/test/risc/position/test_position3.rb @@ -4,8 +4,9 @@ module Risc class TestMachinePositions < MiniTest::Test def setup_for(platform) Parfait.boot!(Parfait.default_test_options) + Mom.boot! Risc.boot! - @linker = Mom::MomCompiler.new.translate(platform) + @linker = Mom::MomCollection.new.to_risc.translate(platform) @linker.position_all end def test_cpu_init diff --git a/test/risc/test_builder.rb b/test/risc/test_builder.rb index e0fcf969..6bf06c2a 100644 --- a/test/risc/test_builder.rb +++ b/test/risc/test_builder.rb @@ -5,9 +5,10 @@ module Risc def setup Parfait.boot!(Parfait.default_test_options) + Mom.boot! Risc.boot! init = Parfait.object_space.get_init - @builder = Risc::MethodCompiler.new( init ).builder(init) + @builder = Risc::MethodCompiler.new( init ,Mom::Label.new( "source_name", "return_label")).builder(init) @label = Risc.label("source","name") @start = @builder.compiler.current end diff --git a/test/risc/test_builder1.rb b/test/risc/test_builder1.rb index c132fb5c..74ee6633 100644 --- a/test/risc/test_builder1.rb +++ b/test/risc/test_builder1.rb @@ -5,9 +5,10 @@ module Risc def setup Parfait.boot!(Parfait.default_test_options) + Mom.boot! Risc.boot! @init = Parfait.object_space.get_init - @compiler = Risc::MethodCompiler.new( @init ) + @compiler = Risc::MethodCompiler.new( @init , Mom::Label.new( "source_name", "return_label")) @builder = @compiler.builder(@init) end def test_inserts_built @@ -42,7 +43,7 @@ module Risc end def test_allocate_len int = @builder.allocate_int - assert_equal 41 , @builder.compiler.risc_instructions.length + assert_equal 28 , @builder.compiler.risc_instructions.length end end end diff --git a/test/risc/test_builder2.rb b/test/risc/test_builder2.rb index 8f6feb15..0f61bba2 100644 --- a/test/risc/test_builder2.rb +++ b/test/risc/test_builder2.rb @@ -5,9 +5,10 @@ module Risc def setup Parfait.boot!(Parfait.default_test_options) + Mom.boot! Risc.boot! @init = Parfait.object_space.get_init - @compiler = Risc::MethodCompiler.new( @init ) + @compiler = Risc::MethodCompiler.new( @init, Mom::Label.new( "source_name", "return_label") ) @builder = @compiler.builder(@init) end def test_list diff --git a/test/risc/test_collector.rb b/test/risc/test_collector.rb index bd45435d..74fe2057 100644 --- a/test/risc/test_collector.rb +++ b/test/risc/test_collector.rb @@ -6,12 +6,12 @@ module Risc def setup Parfait.boot!(Parfait.default_test_options) Risc.boot! - @linker = Mom::MomCompiler.new.translate(:arm) + @linker = Mom::MomCollection.new.to_risc.translate(:arm) end def test_simple_collect objects = Collector.collect_space(@linker) - assert_equal 600 , objects.length , objects.length.to_s + assert_equal 621 , objects.length , objects.length.to_s end def test_collect_all_types @@ -47,15 +47,15 @@ module Risc def setup opt = Parfait.default_test_options - opt[:factory] = 4000 + opt[:factory] = 400 Parfait.boot!(opt) Risc.boot! - @linker = Mom::MomCompiler.new.translate(:arm) + @linker = Mom::MomCollection.new.to_risc.translate(:arm) end def test_simple_collect objects = Collector.collect_space(@linker) - assert_equal 20329, objects.length , objects.length.to_s + assert_equal 2422, objects.length , objects.length.to_s end def test_integer_positions diff --git a/test/risc/test_interpreter.rb b/test/risc/test_interpreter.rb index 8e77f8c2..67e9d436 100644 --- a/test/risc/test_interpreter.rb +++ b/test/risc/test_interpreter.rb @@ -4,8 +4,9 @@ module Risc class TestInterpreterBasics < MiniTest::Test def setup Parfait.boot!(Parfait.default_test_options) + Mom.boot! Risc.boot! - @linker = Mom::MomCompiler.new.translate(:interpreter) + @linker = Mom::MomCollection.new.to_risc.translate(:interpreter) end def test_class @@ -54,7 +55,7 @@ module Risc end def test_pc1 @interpreter.tick - assert_equal 23672 , @interpreter.pc + assert_equal 22856 , @interpreter.pc end def test_tick2 @interpreter.tick @@ -68,7 +69,7 @@ module Risc def test_pc2 @interpreter.tick @interpreter.tick - assert_equal 23676 , @interpreter.pc + assert_equal 22860 , @interpreter.pc end def test_tick_14_jump 14.times {@interpreter.tick} diff --git a/test/risc/test_linker.rb b/test/risc/test_linker.rb index fb506201..aaf02a84 100644 --- a/test/risc/test_linker.rb +++ b/test/risc/test_linker.rb @@ -6,7 +6,7 @@ module Risc def setup Parfait.boot!(Parfait.default_test_options) Risc.boot! - @linker = Mom::MomCompiler.new.translate(:arm) + @linker = Mom::MomCollection.new.to_risc.translate(:arm) end def test_objects objects = @linker.object_positions @@ -25,7 +25,7 @@ module Risc assert_equal 0 , Position.get(@linker.cpu_init).at end def test_cpu_at - assert_equal "0x569c" , Position.get(@linker.cpu_init.first).to_s + assert_equal "0x562c" , 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 8d846477..14aeff34 100644 --- a/test/risc/test_linker1.rb +++ b/test/risc/test_linker1.rb @@ -4,7 +4,7 @@ module Risc class TestMachinePos < MiniTest::Test def setup code = "class Space; def main(arg);a = 1;return a;end;end" - @linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(code,:arm) + @linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_binary(code, :arm) @linker.position_all end def test_positions_set diff --git a/test/risc/test_text_writer.rb b/test/risc/test_text_writer.rb index fe6c931a..42e3b5d6 100644 --- a/test/risc/test_text_writer.rb +++ b/test/risc/test_text_writer.rb @@ -6,7 +6,7 @@ module Risc def setup Parfait.boot!(Parfait.default_test_options) Risc.boot! - @linker = Mom::MomCompiler.new.translate(:arm) + @linker = Mom::MomCollection.new.to_risc.translate(:arm) end def test_init @text_writer = TextWriter.new(@linker) @@ -21,7 +21,7 @@ module Risc def setup Parfait.boot!(Parfait.default_test_options) Risc.boot! - @linker = Mom::MomCompiler.new.translate(:arm) + @linker = Mom::MomCollection.new.to_risc.translate(:arm) @linker.position_all @linker.create_binary @text_writer = TextWriter.new(@linker)