fixing all the indexes

with the type word and layout
but the list starting at 1, indexes still need 1 added
and for arm x 4.
Tried to get all that into one function, resolve_index
This commit is contained in:
Torsten Ruger 2015-06-30 18:38:56 +03:00
parent 88f45cbf15
commit 9541712af8
7 changed files with 16 additions and 14 deletions

View File

@ -5,8 +5,7 @@ module Arm
block.codes.dup.each do |code|
next unless code.is_a? Register::GetSlot
# times 4 because arm works in bytes, but vm in words
# + 1 because of the type word
load = ArmMachine.ldr( code.register , code.array , 4 * (code.index + 1) )
load = ArmMachine.ldr( code.register , code.array , 4 * code.index )
block.replace(code , load )
end
end

View File

@ -6,7 +6,7 @@ module Arm
next unless code.is_a? Register::SetSlot
# times 4 because arm works in bytes, but vm in words
# + 1 because of the type word
store = ArmMachine.str( code.register , code.array , 4 * (code.index + 1) )
store = ArmMachine.str( code.register , code.array , 4 * code.index )
block.replace(code , store )
end
end

View File

@ -56,21 +56,23 @@ module Register
# TODO : fix this to use global (later per thread) variable
def save_message(function)
space_tmp = Register.tmp_reg
ind = Parfait::Space.object_space.get_layout().index_of( :syscall_message )
raise "index not found for :syscall_message" unless ind
ind = Register.resolve_index( :space , :syscall_message )
function.info.add_code LoadConstant.new( Parfait::Space.object_space , space_tmp)
function.info.add_code SetSlot.new( Register.message_reg , space_tmp , ind)
end
def restore_message(function)
# get the sys return out of the way
return_tmp = Register.tmp_reg
function.info.add_code RegisterTransfer.new( Register.message_reg , return_tmp )
# load the space into the base register
function.info.add_code RegisterTransfer.new( return_tmp , Register.message_reg )
function.info.add_code LoadConstant.new(Parfait::Space.object_space ,Register.message_reg)
# find the stored message
ind = Parfait::Space.object_space.get_layout().index_of( :syscall_message )
raise "index not found for #{kind}.#{kind.class}" unless ind
ind = Register.resolve_index( :space , :syscall_message )
# and load it into the base RegisterMachine
function.info.add_code Register.get_slot :message , ind , :message
# save the return value into the message
function.info.add_code Register.set_slot( return_tmp , :message , :return_value )
# and "unroll" self and frame
function.info.add_code Register.get_slot(:message , :receiver, :self )
function.info.add_code Register.get_slot(:message , :frame , :frame)

View File

@ -42,9 +42,9 @@ module Register
frame_tmp = space_tmp.next_reg_use
# get the next_frame
from = Parfait::Space.object_space.send( kind )
kind_index = from.get_layout().index_of( kind )
kind_index = from.get_layout().index_of( kind ) + 1 # should be resolve_index to hide the +1
raise "index not found for #{kind}.#{kind.class}" unless kind_index
new_codes << GetSlot.new( Register.frame_reg , kind_index , frame_tmp) # 2 index of next_frame
new_codes << GetSlot.new( Register.frame_reg , kind_index , frame_tmp)
# save next frame into space
new_codes << SetSlot.new( frame_tmp , space_tmp , space_index)
block.replace(code , new_codes )

View File

@ -28,7 +28,7 @@ module Register
return Register.resolve_index( :message , :name)
when Virtual::NewArgSlot
puts "from: #{from.index}"
return Register.resolve_index( :message , :name) + 1 + from.index
return Register.resolve_index( :message , :name) + from.index
else
raise "not implemented for #{from.class}"
end

View File

@ -97,7 +97,7 @@ module Register
raise "Class name not given #{real_name}" unless clazz
index = clazz.object_layout.index_of( instance_name )
raise "Instance name=#{instance_name} not found on #{real_name}" unless index.is_a?(Numeric)
return index
return index + 1 # one for the type word that is at index 0
end
# if a symbol is given, it may be one of the four objects that the vm knows.

View File

@ -40,10 +40,11 @@ module Virtual
#find method and call
clazz = ref.type.of_class
begin
method = clazz.resolve_method code.name
method = clazz.resolve_method code.name
rescue
raise "No method found #{code.name} for #{clazz.name} in #{clazz.method_names}" unless method
raise "No method found #{code.name} for #{clazz.name} in #{clazz.method_names}" unless method
end
#puts "CALL is #{method.name}"
new_codes << MethodCall.new( method )
else
# must defer send to run-time