remove unused methods

and a whole lot more index fixes
This commit is contained in:
Torsten Ruger 2018-05-14 20:50:52 +03:00
parent 5d3c70da89
commit e237bc625a
10 changed files with 25 additions and 44 deletions

View File

@ -38,7 +38,6 @@ module Parfait
101.times { @next_integer = Integer.new(0,@next_integer) } 101.times { @next_integer = Integer.new(0,@next_integer) }
50.times do 50.times do
@first_message = Message.new message @first_message = Message.new message
#puts "INIT caller #{message.object_id} to #{@first_message.object_id}"
message.set_caller @first_message message.set_caller @first_message
message = @first_message message = @first_message
end end

View File

@ -65,8 +65,7 @@ module Parfait
# determine if method has a local variable or tmp (anonymous local) by given name # determine if method has a local variable or tmp (anonymous local) by given name
def has_local( name ) def has_local( name )
raise "has_local #{name}.#{name.class}" unless name.is_a? Symbol raise "has_local #{name}.#{name.class}" unless name.is_a? Symbol
index = frame_type.variable_index( name ) frame_type.variable_index( name )
index ? (index - 1) : index
end end
def add_local( name , type ) def add_local( name , type )
@ -75,18 +74,6 @@ module Parfait
@frame_type = @frame_type.add_instance_variable(name,type) @frame_type = @frame_type.add_instance_variable(name,type)
end 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 def rxf_reference_name
"Method: " + @name.to_s "Method: " + @name.to_s
end end

View File

@ -129,7 +129,7 @@ module Risc
{ Word: {char_length: :Integer} , { Word: {char_length: :Integer} ,
List: {indexed_length: :Integer} , List: {indexed_length: :Integer} ,
Message: { next_message: :Message, receiver: :Object, frame: :NamedList , 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 }, caller: :Message , name: :Word , arguments: :NamedList },
Integer: {next_integer: :Integer}, Integer: {next_integer: :Integer},
DataObject: {}, DataObject: {},

View File

@ -4,7 +4,7 @@ module Risc
module CompileHelper module CompileHelper
def compiler_for( type , method_name , arguments , locals = {}) 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 ) args = Parfait::NamedList.type_for( arguments )
Risc::MethodCompiler.create_method(type , method_name , args, frame ) Risc::MethodCompiler.create_method(type , method_name , args, frame )
end end

View File

@ -22,7 +22,7 @@ module Risc
@array = array @array = array
@index = index @index = index
@register = register @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 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 #{register}" unless RiscValue.look_like_reg(register)
raise "Not register #{array}" unless RiscValue.look_like_reg(array) raise "Not register #{array}" unless RiscValue.look_like_reg(array)

View File

@ -18,14 +18,9 @@ module Risc
# (which are precisely the symbols :message or :new_message. or a register) # (which are precisely the symbols :message or :new_message. or a register)
# index resolves with resolve_to_index. # index resolves with resolve_to_index.
def self.reg_to_slot( source , from_reg , 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 from = resolve_to_register from_reg
index = resolve_to_index( to , index) index = resolve_to_index( to , index)
to = resolve_to_register to to = resolve_to_register to
# raise "HALLO " if index == 2 and no_rec
RegToSlot.new( source, from , to , index) RegToSlot.new( source, from , to , index)
end end

View File

@ -57,40 +57,40 @@ module Parfait
end end
def test_local1 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 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 end
def test_has_local def test_has_local
assert_equal 0 , @method.has_local(:local_bar) assert_equal 1 , @method.has_local(:local_bar)
assert_equal 1 , @method.has_local(:local_foo) assert_equal 2 , @method.has_local(:local_foo)
end end
def test_add_local def test_add_local
@method.add_local(:foo2 , :Object) @method.add_local(:foo2 , :Object)
assert_equal 3 , @method.frame_length assert_equal 4 , @method.frame_type.get_length
assert_equal :foo2 , @method.locals_name(2) assert_equal :foo2 , @method.frame_type.name_at(3)
assert_equal :Object , @method.locals_type(2) assert_equal :Object , @method.frame_type.type_at(3)
end end
def test_get_locals_name1 def test_get_locals_name1
index = @method.has_local(:local_bar) index = @method.has_local(:local_bar)
assert_equal 0 , index assert_equal 1 , index
assert_equal :local_bar , @method.locals_name(index) assert_equal :local_bar , @method.frame_type.name_at(index)
end end
def test_get_frame_type1 def test_get_frame_type1
index = @method.has_local(:local_bar) index = @method.has_local(:local_bar)
assert_equal :Integer , @method.locals_type(index) assert_equal :Integer , @method.frame_type.type_at(index)
end end
def test_get_locals_name2 def test_get_locals_name2
index = @method.has_local(:local_foo) index = @method.has_local(:local_foo)
assert_equal 1 , index assert_equal 2 , index
assert_equal :local_foo , @method.locals_name(index) assert_equal :local_foo , @method.frame_type.name_at(index)
end end
def test_get_frame_type2 def test_get_frame_type2
index = @method.has_local(:local_bar) index = @method.has_local(:local_bar)
assert_equal :Integer , @method.locals_type(index) assert_equal :Integer , @method.frame_type.type_at(index)
end end
def test_created_with_binary def test_created_with_binary
assert @method.binary assert @method.binary

View File

@ -37,21 +37,21 @@ module Risc
sl = main_ticks( 31 ) sl = main_ticks( 31 )
assert_equal SlotToReg , sl.class assert_equal SlotToReg , sl.class
assert_equal :r0 , sl.array.symbol #load from message 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 assert_equal :r1 , sl.register.symbol
end end
def test_slot_args #load args from message def test_slot_args #load args from message
sl = main_ticks( 32 ) sl = main_ticks( 32 )
assert_equal SlotToReg , sl.class assert_equal SlotToReg , sl.class
assert_equal :r0 , sl.array.symbol #load from message 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 assert_equal :r2 , sl.register.symbol
end end
def test_slot_arg #load arg 1, destructively from args def test_slot_arg #load arg 1, destructively from args
sl = main_ticks( 33 ) sl = main_ticks( 33 )
assert_equal SlotToReg , sl.class assert_equal SlotToReg , sl.class
assert_equal :r2 , sl.array.symbol #load from message 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 assert_equal :r2 , sl.register.symbol
end end
def test_slot_int1 #load int from object def test_slot_int1 #load int from object
@ -79,7 +79,7 @@ module Risc
sl = main_ticks(38) sl = main_ticks(38)
assert_equal SlotToReg , sl.class assert_equal SlotToReg , sl.class
assert_equal :r3 , sl.array.symbol #load from space 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 :r2 , sl.register.symbol
assert_equal Parfait::Integer , @interpreter.get_register(:r2).class assert_equal Parfait::Integer , @interpreter.get_register(:r2).class
end end
@ -87,7 +87,7 @@ module Risc
sl = main_ticks(39) sl = main_ticks(39)
assert_equal SlotToReg , sl.class assert_equal SlotToReg , sl.class
assert_equal :r2 , sl.array.symbol #load from next_int 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 :r4 , sl.register.symbol
assert_equal Parfait::Integer , @interpreter.get_register(:r4).class assert_equal Parfait::Integer , @interpreter.get_register(:r4).class
end end
@ -95,7 +95,7 @@ module Risc
sl = main_ticks(40) sl = main_ticks(40)
assert_equal RegToSlot , sl.class assert_equal RegToSlot , sl.class
assert_equal :r3 , sl.array.symbol #store to space 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 assert_equal :r4 , sl.register.symbol
end end
def test_sys def test_sys

View File

@ -27,7 +27,7 @@ module Vool
left = @ins.next(1).arguments[0].left left = @ins.next(1).arguments[0].left
assert_equal Symbol, left.known_object.class assert_equal Symbol, left.known_object.class
assert_equal :message, left.known_object 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 end
end end

View File

@ -18,7 +18,7 @@ module Vool
def test_args_one_str def test_args_one_str
assert_equal Mom::IntegerConstant, @ins.next.arguments[0].right.known_object.class 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 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 end
end end