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| block.codes.dup.each do |code|
next unless code.is_a? Register::GetSlot next unless code.is_a? Register::GetSlot
# times 4 because arm works in bytes, but vm in words # 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 )
load = ArmMachine.ldr( code.register , code.array , 4 * (code.index + 1) )
block.replace(code , load ) block.replace(code , load )
end end
end end

View File

@ -6,7 +6,7 @@ module Arm
next unless code.is_a? Register::SetSlot next unless code.is_a? Register::SetSlot
# times 4 because arm works in bytes, but vm in words # times 4 because arm works in bytes, but vm in words
# + 1 because of the type word # + 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 ) block.replace(code , store )
end end
end end

View File

@ -56,21 +56,23 @@ module Register
# TODO : fix this to use global (later per thread) variable # TODO : fix this to use global (later per thread) variable
def save_message(function) def save_message(function)
space_tmp = Register.tmp_reg space_tmp = Register.tmp_reg
ind = Parfait::Space.object_space.get_layout().index_of( :syscall_message ) ind = Register.resolve_index( :space , :syscall_message )
raise "index not found for :syscall_message" unless ind
function.info.add_code LoadConstant.new( Parfait::Space.object_space , space_tmp) function.info.add_code LoadConstant.new( Parfait::Space.object_space , space_tmp)
function.info.add_code SetSlot.new( Register.message_reg , space_tmp , ind) function.info.add_code SetSlot.new( Register.message_reg , space_tmp , ind)
end end
def restore_message(function) def restore_message(function)
# get the sys return out of the way # get the sys return out of the way
return_tmp = Register.tmp_reg return_tmp = Register.tmp_reg
function.info.add_code RegisterTransfer.new( Register.message_reg , return_tmp )
# load the space into the base register # 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 # find the stored message
ind = Parfait::Space.object_space.get_layout().index_of( :syscall_message ) ind = Register.resolve_index( :space , :syscall_message )
raise "index not found for #{kind}.#{kind.class}" unless ind
# and load it into the base RegisterMachine # and load it into the base RegisterMachine
function.info.add_code Register.get_slot :message , ind , :message 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 # and "unroll" self and frame
function.info.add_code Register.get_slot(:message , :receiver, :self ) function.info.add_code Register.get_slot(:message , :receiver, :self )
function.info.add_code Register.get_slot(:message , :frame , :frame) 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 frame_tmp = space_tmp.next_reg_use
# get the next_frame # get the next_frame
from = Parfait::Space.object_space.send( kind ) 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 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 # save next frame into space
new_codes << SetSlot.new( frame_tmp , space_tmp , space_index) new_codes << SetSlot.new( frame_tmp , space_tmp , space_index)
block.replace(code , new_codes ) block.replace(code , new_codes )

View File

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

View File

@ -97,7 +97,7 @@ module Register
raise "Class name not given #{real_name}" unless clazz raise "Class name not given #{real_name}" unless clazz
index = clazz.object_layout.index_of( instance_name ) index = clazz.object_layout.index_of( instance_name )
raise "Instance name=#{instance_name} not found on #{real_name}" unless index.is_a?(Numeric) 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 end
# if a symbol is given, it may be one of the four objects that the vm knows. # if a symbol is given, it may be one of the four objects that the vm knows.

View File

@ -44,6 +44,7 @@ module Virtual
rescue 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 end
#puts "CALL is #{method.name}"
new_codes << MethodCall.new( method ) new_codes << MethodCall.new( method )
else else
# must defer send to run-time # must defer send to run-time