diff --git a/Gemfile b/Gemfile index 4d21399b..236f8ff3 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,8 @@ gem "rubyx" , :path => "." gem "rake" gem "rye" -gem "rx-file" , :git => "https://github.com/ruby-x/rx-file" +gem "rx-file" , git: "https://github.com/ruby-x/rx-file" +#gem "rx-file" , path: "../rx-file" group :test do gem "codeclimate-test-reporter" , require: false diff --git a/Gemfile.lock b/Gemfile.lock index 6646d17b..8242caa3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -104,4 +104,4 @@ DEPENDENCIES thor (= 0.19.1) BUNDLED WITH - 1.15.4 + 1.16.1 diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index be617179..806a53ad 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -24,12 +24,12 @@ module Elf # for debug add labels for labels Parfait.object_space.each_type do |type| - type.each_method do |f| - f.cpu_instructions.each do |label| + type.each_method do |meth| + meth.cpu_instructions.each do |label| next unless label.is_a?(Risc::Label) - add_symbol "#{type.name}@#{f.name}:#{label.name}" , Risc::Position.get(label).at + add_symbol "#{type.name}@#{meth.name}:Label=#{label.name}" , Risc::Position.get(label).at end - f.binary.each do |code| + meth.binary.each do |code| label = "BinaryCode@#{Risc::Position.get(code).method.name}" add_symbol label , Risc::Position.get(code).at end @@ -38,8 +38,8 @@ module Elf @machine.objects.each do |id,slot| next if slot.is_a?(Parfait::BinaryCode) - if( slot.respond_to? :sof_reference_name ) - label = "#{slot.sof_reference_name}" + if( slot.respond_to? :rxf_reference_name ) + label = "#{slot.rxf_reference_name}" else label = "#{slot.class.name}::#{Risc::Position.get(slot)}" end diff --git a/lib/parfait/binary_code.rb b/lib/parfait/binary_code.rb index e0b1d0de..0767c802 100644 --- a/lib/parfait/binary_code.rb +++ b/lib/parfait/binary_code.rb @@ -13,7 +13,7 @@ module Parfait super() extend_to(total_size) #puts "Init with #{total_size} for #{object_id}" - (1..(data_length+1)).each{ |index| set_word(index , 0) } + (0 ..(data_length)).each{ |index| set_word(index , 0) } end def extend_to(total_size) if total_size > self.data_length @@ -26,7 +26,7 @@ module Parfait #puts "extending #{total_size - data_length} in #{self}" Risc::Position.reset(self) if Risc::Position.set?(self) end - + def each( &block ) block.call( self ) @next.each( &block ) if @next @@ -37,13 +37,13 @@ module Parfait end def each_word - index = 1 - while( index <= data_length) + index = 0 + while( index < data_length) yield get_word(index) index += 1 end end - #16 - 2 -1 , two instance varaibles and one for the jump + #16 - 2 -1 , two instance variables and one for the jump def data_length 13 end @@ -51,8 +51,8 @@ module Parfait 4*data_length end def set_word(index , word) - raise "invalid index #{index}" if index < 1 - if index > data_length + 1 + raise "invalid index #{index}" if index < 0 + if index > data_length #raise "invalid index #{index}" unless @next extend_to( index ) @next.set_word( index - data_length , word) @@ -60,7 +60,7 @@ module Parfait set_internal_word(index + 2 , word) end def get_word(index) - raise "invalid index #{index}" if index < 1 + raise "invalid index #{index}" if index < 0 if index > data_length + 1 raise "invalid index #{index}" unless @next return @next.get_word( index - data_length) diff --git a/lib/parfait/list.rb b/lib/parfait/list.rb index cbeee83c..88148b38 100644 --- a/lib/parfait/list.rb +++ b/lib/parfait/list.rb @@ -266,7 +266,7 @@ module Parfait array = [] index = 0 while( index < self.get_length) - array[index - 1] = get(index) + array[index] = get(index) index = index + 1 end array diff --git a/lib/risc/boot.rb b/lib/risc/boot.rb index 0fea24a4..9bc87690 100644 --- a/lib/risc/boot.rb +++ b/lib/risc/boot.rb @@ -40,7 +40,7 @@ module Risc # # The way out is to build empty shell objects and stuff the neccessary data into them # (not use the normal initialize way) - # (PPS: The "real" solution is to read a sof graph and not do this by hand + # (PPS: The "real" solution is to read a rx-file graph and not do this by hand # That graph can be programatically built and written (with this to boot that process :-)) # There are some helpers below, but the roadmap is something like: @@ -60,7 +60,7 @@ module Risc Parfait.set_object_space( space ) #puts Sof.write(space) - boot_functions( space ) + #boot_functions( space ) end # types is where the snake bites its tail. Every chain ends at a type and then it @@ -98,7 +98,8 @@ module Risc classes = Parfait::Dictionary.new type_names.each do |name , vars| super_c = super_class_names[name] || :Object - classes[name] = Parfait::Class.new(name , super_c , types[name] ) + clazz = Parfait::Class.new(name , super_c , types[name] ) + classes[name] = clazz end classes end diff --git a/lib/risc/collector.rb b/lib/risc/collector.rb index 6b27df8e..15d1efcc 100644 --- a/lib/risc/collector.rb +++ b/lib/risc/collector.rb @@ -45,8 +45,8 @@ module Risc def self.message(object , depth) msg = "adding #{depth}#{' ' * depth}:" - if( object.respond_to?(:sof_reference_name)) - msg + object.sof_reference_name.to_s + if( object.respond_to?(:rxf_reference_name)) + msg + object.rxf_reference_name.to_s else msg + object.class.name end diff --git a/lib/risc/instructions/label.rb b/lib/risc/instructions/label.rb index 7d5e30a5..4cd7f1c4 100644 --- a/lib/risc/instructions/label.rb +++ b/lib/risc/instructions/label.rb @@ -22,7 +22,7 @@ module Risc class_source "#{@name} (next: #{self.next.class.name.split("::").last})" end - def sof_reference_name + def rxf_reference_name @name end diff --git a/lib/risc/instructions/load_constant.rb b/lib/risc/instructions/load_constant.rb index 33e35621..982e92d5 100644 --- a/lib/risc/instructions/load_constant.rb +++ b/lib/risc/instructions/load_constant.rb @@ -24,8 +24,8 @@ module Risc when String , Symbol @constant.to_s else - if( @constant.respond_to? :sof_reference_name ) - constant.sof_reference_name + if( @constant.respond_to? :rxf_reference_name ) + constant.rxf_reference_name else constant.class.name.to_s end diff --git a/lib/risc/instructions/setter.rb b/lib/risc/instructions/setter.rb index 97100ba1..a86c45bc 100644 --- a/lib/risc/instructions/setter.rb +++ b/lib/risc/instructions/setter.rb @@ -21,7 +21,7 @@ module Risc @register = register @array = array @index = index - raise "index 0 " if index == 0 + raise "index 0 " if index < 0 raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RiscValue.look_like_reg(index) raise "Not register #{register}" unless RiscValue.look_like_reg(register) raise "Not register #{array}" unless RiscValue.look_like_reg(array) diff --git a/lib/risc/position/instruction_position.rb b/lib/risc/position/instruction_position.rb index 1c02d977..3ac2e455 100644 --- a/lib/risc/position/instruction_position.rb +++ b/lib/risc/position/instruction_position.rb @@ -24,7 +24,7 @@ module Risc end def init(at) diff = at - Position.get(@binary).at - if( diff % 60 == 13*4) + if( diff % 60 == 12*4) @binary.extend_one unless @binary.next @binary = @binary.next raise "end of line " unless @binary diff --git a/lib/risc/risc_value.rb b/lib/risc/risc_value.rb index b716202c..1fd1d4cd 100644 --- a/lib/risc/risc_value.rb +++ b/lib/risc/risc_value.rb @@ -52,7 +52,7 @@ module Risc RiscValue.new( sym , type, value) end - def sof_reference_name + def rxf_reference_name @symbol end diff --git a/lib/risc/text_writer.rb b/lib/risc/text_writer.rb index dda7cd30..6d3c5b64 100644 --- a/lib/risc/text_writer.rb +++ b/lib/risc/text_writer.rb @@ -16,8 +16,6 @@ module Risc include Logging log_level :info - MARKER = 0xBAD4C0DE - def initialize(machine) @machine = machine end @@ -134,7 +132,6 @@ module Risc end def write_object_variables(object) - @stream.write_signed_int_32( MARKER ) written = 0 # compensate for the "secret" marker object.get_instance_variables.each do |var| inst = object.get_instance_variable(var) @@ -147,7 +144,6 @@ module Risc end def write_data4( code ) - @stream.write_signed_int_32( MARKER ) write_ref_for( code.get_type ) log.debug "Data4 witten stream 0x#{@stream.length.to_s(16)}" end @@ -160,7 +156,6 @@ module Risc end def write_BinaryCode( code ) - @stream.write_signed_int_32( MARKER ) write_ref_for( code.get_type ) write_ref_for( code.next ) code.each_word do |word| @@ -180,7 +175,6 @@ module Risc end def write_checked_string(string, str) - @stream.write_signed_int_32( MARKER ) write_ref_for( string.get_type ) #ref @stream.write_signed_int_32( str.length ) #int @stream.write str @@ -210,7 +204,7 @@ module Risc # pad_after is always in bytes and pads (writes 0's) up to the next 8 word boundary def pad_after( length ) before = stream_position - pad = Padding.padding_for(length) - 4 # four is for the MARKER we write + pad = Padding.padding_for(length) pad.times do @stream.write_unsigned_int_8(0) end diff --git a/test/mom/assign/test_assign_arg_const.rb b/test/mom/assign/test_assign_arg_const.rb index 51fe3d3e..7b61645c 100644 --- a/test/mom/assign/test_assign_arg_const.rb +++ b/test/mom/assign/test_assign_arg_const.rb @@ -25,7 +25,7 @@ module Risc def test_load_args_from_message produced = produce_body assert_equal :r0 , produced.next.array.symbol , produced.next.to_rxf - assert_equal 9 , produced.next.index , produced.next.to_rxf + assert_equal 8 , produced.next.index , produced.next.to_rxf end end diff --git a/test/mom/assign/test_assign_local_false.rb b/test/mom/assign/test_assign_local_false.rb index 5908f71b..7a542131 100644 --- a/test/mom/assign/test_assign_local_false.rb +++ b/test/mom/assign/test_assign_local_false.rb @@ -21,12 +21,12 @@ module Risc def test_frame_load produced = produce_body assert_equal :Message , produced.next(1).array.type - assert_equal 4 , produced.next(1).index # 4 is frame + assert_equal 3 , produced.next(1).index # 3 is frame end def test_value_load produced = produce_body assert_equal produced.next(2).register , produced.register - assert_equal 2 , produced.next(2).index #type == 1 , r == 2 + assert_equal 1 , produced.next(2).index #type == 0 , r == 1 end end diff --git a/test/mom/assign/test_assign_local_int.rb b/test/mom/assign/test_assign_local_int.rb index 8c6cd83f..fc305355 100644 --- a/test/mom/assign/test_assign_local_int.rb +++ b/test/mom/assign/test_assign_local_int.rb @@ -21,12 +21,12 @@ module Risc def test_frame_load produced = produce_body assert_equal :Message , produced.next(1).array.type - assert_equal 4 , produced.next(1).index # 4 is frame + assert_equal 3 , produced.next(1).index # 4 is frame end def test_value_load produced = produce_body assert_equal produced.next(2).register , produced.register - assert_equal 2 , produced.next(2).index #type == 1 , r == 2 + assert_equal 1 , produced.next(2).index #type == 1 , r == 2 end end diff --git a/test/parfait/test_binary_code.rb b/test/parfait/test_binary_code.rb index 9b1f2d20..8f41aab6 100644 --- a/test/parfait/test_binary_code.rb +++ b/test/parfait/test_binary_code.rb @@ -53,7 +53,7 @@ module Parfait end def test_nilled assert_equal 0 , @code.get_word(1) - assert_equal 0 , @code.get_word(14) + assert_equal 0 , @code.get_word(13) end def test_get_set_self @code.set_word(10,1) @@ -86,11 +86,11 @@ module Parfait assert_equal 13 , len end def test_each_set - (1..13).each{|i| @code.set_word(i,i)} + (0..12).each{|i| @code.set_word(i,i)} all = [] @code.each_word{ |w| all << w} - assert_equal 1 , all.first - assert_equal 13 , all.last + assert_equal 0 , all.first + assert_equal 12 , all.last end def test_set_word assert_equal 1 , @code.set_word(1 , 1) diff --git a/test/parfait/test_list.rb b/test/parfait/test_list.rb index 162471ed..d682cd29 100644 --- a/test/parfait/test_list.rb +++ b/test/parfait/test_list.rb @@ -180,5 +180,10 @@ module Parfait end assert_equal 2 , counter end + def test_to_a + arr = @list.to_a + assert_equal Array , arr.class + assert_equal 3 , arr.length + end end end