From e237bc625a867b352b3160cb4b1458eee648a02c Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 14 May 2018 20:50:52 +0300 Subject: [PATCH] remove unused methods and a whole lot more index fixes --- lib/parfait/space.rb | 1 - lib/parfait/typed_method.rb | 15 +---------- lib/risc/boot.rb | 2 +- lib/risc/builtin/compile_helper.rb | 2 +- lib/risc/instructions/getter.rb | 2 +- lib/risc/instructions/reg_to_slot.rb | 5 ---- test/parfait/test_typed_method.rb | 26 +++++++++---------- test/risc/interpreter/calling/test_plus.rb | 12 ++++----- test/vool/to_mom/send/test_send_args_send.rb | 2 +- .../to_mom/send/test_send_simple_string.rb | 2 +- 10 files changed, 25 insertions(+), 44 deletions(-) diff --git a/lib/parfait/space.rb b/lib/parfait/space.rb index f0fe7ddb..de6e77ab 100644 --- a/lib/parfait/space.rb +++ b/lib/parfait/space.rb @@ -38,7 +38,6 @@ module Parfait 101.times { @next_integer = Integer.new(0,@next_integer) } 50.times do @first_message = Message.new message - #puts "INIT caller #{message.object_id} to #{@first_message.object_id}" message.set_caller @first_message message = @first_message end diff --git a/lib/parfait/typed_method.rb b/lib/parfait/typed_method.rb index 4dcae2f8..8b5729d5 100644 --- a/lib/parfait/typed_method.rb +++ b/lib/parfait/typed_method.rb @@ -65,8 +65,7 @@ module Parfait # determine if method has a local variable or tmp (anonymous local) by given name def has_local( name ) raise "has_local #{name}.#{name.class}" unless name.is_a? Symbol - index = frame_type.variable_index( name ) - index ? (index - 1) : index + frame_type.variable_index( name ) end def add_local( name , type ) @@ -75,18 +74,6 @@ module Parfait @frame_type = @frame_type.add_instance_variable(name,type) end - def frame_length - frame_type.instance_length - 1 - end - - def locals_name( index ) - frame_type.names.get(index + 1) - end - - def locals_type( index ) - frame_type.types.get(index + 1) - end - def rxf_reference_name "Method: " + @name.to_s end diff --git a/lib/risc/boot.rb b/lib/risc/boot.rb index c247f24f..5dcfbb01 100644 --- a/lib/risc/boot.rb +++ b/lib/risc/boot.rb @@ -129,7 +129,7 @@ module Risc { Word: {char_length: :Integer} , List: {indexed_length: :Integer} , Message: { next_message: :Message, receiver: :Object, frame: :NamedList , - return_address: :Integer, return_value: :Integer, + return_address: :Integer, return_value: :Object, caller: :Message , name: :Word , arguments: :NamedList }, Integer: {next_integer: :Integer}, DataObject: {}, diff --git a/lib/risc/builtin/compile_helper.rb b/lib/risc/builtin/compile_helper.rb index e970e3e4..cab959d9 100644 --- a/lib/risc/builtin/compile_helper.rb +++ b/lib/risc/builtin/compile_helper.rb @@ -4,7 +4,7 @@ module Risc module CompileHelper def compiler_for( type , method_name , arguments , locals = {}) - frame = Parfait::NamedList.type_for( locals ) #TODO fix locals passing/ using in builtin + frame = Parfait::NamedList.type_for( locals ) args = Parfait::NamedList.type_for( arguments ) Risc::MethodCompiler.create_method(type , method_name , args, frame ) end diff --git a/lib/risc/instructions/getter.rb b/lib/risc/instructions/getter.rb index 6d615b5c..0d5cf8d8 100644 --- a/lib/risc/instructions/getter.rb +++ b/lib/risc/instructions/getter.rb @@ -22,7 +22,7 @@ module Risc @array = array @index = index @register = register - raise "index 0 " if index == 0 + raise "index #{index}" if index.is_a?(Numeric) and 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/instructions/reg_to_slot.rb b/lib/risc/instructions/reg_to_slot.rb index f9b455e8..ffe603bb 100644 --- a/lib/risc/instructions/reg_to_slot.rb +++ b/lib/risc/instructions/reg_to_slot.rb @@ -18,14 +18,9 @@ module Risc # (which are precisely the symbols :message or :new_message. or a register) # index resolves with resolve_to_index. def self.reg_to_slot( source , from_reg , to , index ) - no_rec = index != :receiver - puts "FROM #{from_reg}" - puts "TO #{to}" - puts "IN #{index}" from = resolve_to_register from_reg index = resolve_to_index( to , index) to = resolve_to_register to -# raise "HALLO " if index == 2 and no_rec RegToSlot.new( source, from , to , index) end diff --git a/test/parfait/test_typed_method.rb b/test/parfait/test_typed_method.rb index 47060a71..ac5fa672 100644 --- a/test/parfait/test_typed_method.rb +++ b/test/parfait/test_typed_method.rb @@ -57,40 +57,40 @@ module Parfait end def test_local1 - assert_equal 2 , @method.frame_length , @method.frame_type.inspect + assert_equal 3 , @method.frame_type.get_length , @method.frame_type.inspect assert_equal Symbol , @method.frame_type.names.first.class - assert_equal :local_bar , @method.locals_name(0) + assert_equal :local_bar , @method.frame_type.name_at(1) end def test_has_local - assert_equal 0 , @method.has_local(:local_bar) - assert_equal 1 , @method.has_local(:local_foo) + assert_equal 1 , @method.has_local(:local_bar) + assert_equal 2 , @method.has_local(:local_foo) end def test_add_local @method.add_local(:foo2 , :Object) - assert_equal 3 , @method.frame_length - assert_equal :foo2 , @method.locals_name(2) - assert_equal :Object , @method.locals_type(2) + assert_equal 4 , @method.frame_type.get_length + assert_equal :foo2 , @method.frame_type.name_at(3) + assert_equal :Object , @method.frame_type.type_at(3) end def test_get_locals_name1 index = @method.has_local(:local_bar) - assert_equal 0 , index - assert_equal :local_bar , @method.locals_name(index) + assert_equal 1 , index + assert_equal :local_bar , @method.frame_type.name_at(index) end def test_get_frame_type1 index = @method.has_local(:local_bar) - assert_equal :Integer , @method.locals_type(index) + assert_equal :Integer , @method.frame_type.type_at(index) end def test_get_locals_name2 index = @method.has_local(:local_foo) - assert_equal 1 , index - assert_equal :local_foo , @method.locals_name(index) + assert_equal 2 , index + assert_equal :local_foo , @method.frame_type.name_at(index) end def test_get_frame_type2 index = @method.has_local(:local_bar) - assert_equal :Integer , @method.locals_type(index) + assert_equal :Integer , @method.frame_type.type_at(index) end def test_created_with_binary assert @method.binary diff --git a/test/risc/interpreter/calling/test_plus.rb b/test/risc/interpreter/calling/test_plus.rb index 2c8d9754..9c5d8f21 100644 --- a/test/risc/interpreter/calling/test_plus.rb +++ b/test/risc/interpreter/calling/test_plus.rb @@ -37,21 +37,21 @@ module Risc sl = main_ticks( 31 ) assert_equal SlotToReg , sl.class assert_equal :r0 , sl.array.symbol #load from message - assert_equal 3 , sl.index + assert_equal 2 , sl.index assert_equal :r1 , sl.register.symbol end def test_slot_args #load args from message sl = main_ticks( 32 ) assert_equal SlotToReg , sl.class assert_equal :r0 , sl.array.symbol #load from message - assert_equal 9 , sl.index + assert_equal 8 , sl.index assert_equal :r2 , sl.register.symbol end def test_slot_arg #load arg 1, destructively from args sl = main_ticks( 33 ) assert_equal SlotToReg , sl.class assert_equal :r2 , sl.array.symbol #load from message - assert_equal 2 , sl.index + assert_equal 1 , sl.index assert_equal :r2 , sl.register.symbol end def test_slot_int1 #load int from object @@ -79,7 +79,7 @@ module Risc sl = main_ticks(38) assert_equal SlotToReg , sl.class assert_equal :r3 , sl.array.symbol #load from space - assert_equal 5 , sl.index + assert_equal 4 , sl.index assert_equal :r2 , sl.register.symbol assert_equal Parfait::Integer , @interpreter.get_register(:r2).class end @@ -87,7 +87,7 @@ module Risc sl = main_ticks(39) assert_equal SlotToReg , sl.class assert_equal :r2 , sl.array.symbol #load from next_int - assert_equal 2 , sl.index + assert_equal 1 , sl.index assert_equal :r4 , sl.register.symbol assert_equal Parfait::Integer , @interpreter.get_register(:r4).class end @@ -95,7 +95,7 @@ module Risc sl = main_ticks(40) assert_equal RegToSlot , sl.class assert_equal :r3 , sl.array.symbol #store to space - assert_equal 5 , sl.index + assert_equal 4 , sl.index assert_equal :r4 , sl.register.symbol end def test_sys diff --git a/test/vool/to_mom/send/test_send_args_send.rb b/test/vool/to_mom/send/test_send_args_send.rb index 5dc1923b..4cc6d8f4 100644 --- a/test/vool/to_mom/send/test_send_args_send.rb +++ b/test/vool/to_mom/send/test_send_args_send.rb @@ -27,7 +27,7 @@ module Vool left = @ins.next(1).arguments[0].left assert_equal Symbol, left.known_object.class assert_equal :message, left.known_object - assert_equal [:next_message, :arguments, 2], left.slots + assert_equal [:next_message, :arguments, 1], left.slots end end end diff --git a/test/vool/to_mom/send/test_send_simple_string.rb b/test/vool/to_mom/send/test_send_simple_string.rb index 21823e7f..8bec7915 100644 --- a/test/vool/to_mom/send/test_send_simple_string.rb +++ b/test/vool/to_mom/send/test_send_simple_string.rb @@ -18,7 +18,7 @@ module Vool def test_args_one_str assert_equal Mom::IntegerConstant, @ins.next.arguments[0].right.known_object.class assert_equal 1, @ins.next.arguments[0].right.known_object.value - assert_equal [:next_message, :arguments, 2], @ins.next.arguments[0].left.slots + assert_equal [:next_message, :arguments, 1], @ins.next.arguments[0].left.slots end end end