fix indexing when accessing locals or args

Was missing the offset of object variables
This commit is contained in:
Torsten Ruger 2015-10-22 11:02:46 +03:00
parent a44b88f570
commit ede0fe5f16
6 changed files with 16 additions and 35 deletions

View File

@ -28,5 +28,9 @@ module Parfait
class Frame < Object
attribute :next_frame
def self.offset
Space.object_space.get_class_by_name(:Frame).object_layout.object_instance_length
end
end
end

View File

@ -56,6 +56,10 @@ module Parfait
names
end
def object_instance_length
self.get_length - 2
end
alias :list_index :index_of
# private inheritance is something to think off, we don't really want the list api exported
def index_of name

View File

@ -29,35 +29,8 @@ module Parfait
get_at(index)
end
# def __send
# typ = get_type_for( :receiver )
# # TODO: this will obviously be recoded as case, once that is done :-)
# # depending on value type get method
# if( typ == Integer )
# method = Integer.get_method @method_name
# else
# if( typ != ObjectReference )
# raise "unimplemented case"
# else
# method = @receiver.get_singeton_method @method_name
# # Find the method for the given object (receiver) according to ruby dispatch rules:
# # - see if the receiver object has a (singleton) method by the name
# # - get receivers class and look for instance methods of the name
# # - go up inheritance tree
# # - start over with method_missing instead
# # -> guaranteed to end at object.method_missing
# unless method
# cl = @receiver.layout.object_class
# method = cl.get_instance_or_super_method @method_name
# end
# end
# end
# unless method
# message = Message.new( @receiver , :method_missing , [@method_name] + @args)
# message.send
# else
# method.call
# end
# end
def self.offset
Space.object_space.get_class_by_name(:Message).object_layout.object_instance_length
end
end
end

View File

@ -76,7 +76,7 @@ module Parfait
def get_layout()
l = internal_object_get(LAYOUT_INDEX)
#puts "get layout for #{self.class} returns #{l.class}"
raise "No layout #{self.object_id.to_s(16)}:#{self.class} " unless l
raise "No layout #{self.object_id}:#{self.class} " unless l
return l
end

View File

@ -11,14 +11,14 @@ module Phisol
code = nil
if( index = @method.has_arg(name))
# TODO, check type @method.arguments[index].type
code = Register.set_slot(statement , v , :message , index )
code = Register.set_slot(statement , v , :message , index + Parfait::Message.offset )
else # or a local so it is in the frame
index = @method.has_local( name )
if(index)
# TODO, check type @method.locals[index].type
frame = use_reg(:Frame)
@method.source.add_code Register.get_slot(statement , :message , :frame , frame )
code = Register.set_slot(statement , v , frame , index )
code = Register.set_slot(statement , v , frame , index + Parfait::Frame.offset )
end
end
if( code )

View File

@ -15,7 +15,7 @@ module Phisol
# either an argument, so it's stored in message
if( index = @method.has_arg(name))
ret = use_reg @method.arguments[index].type
@method.source.add_code Register.get_slot(statement , :message , index , ret )
@method.source.add_code Register.get_slot(statement , :message , index + Parfait::Message.offset , ret )
return ret
else # or a local so it is in the frame
index = @method.has_local( name )
@ -23,7 +23,7 @@ module Phisol
frame = use_reg :Frame
@method.source.add_code Register.get_slot(statement , :message , :frame , frame )
ret = use_reg @method.locals[index].type
@method.source.add_code Register.get_slot(statement , frame , index , ret )
@method.source.add_code Register.get_slot(statement , frame , index + Parfait::Frame.offset , ret )
return ret
end
end