From 9541712af8e8516b5a48e62f26de8128e5ac5753 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 30 Jun 2015 18:38:56 +0300 Subject: [PATCH] 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 --- lib/arm/passes/get_implementation.rb | 3 +-- lib/arm/passes/set_implementation.rb | 2 +- lib/register/builtin/kernel.rb | 12 +++++++----- lib/register/passes/frame_implementation.rb | 4 ++-- lib/register/passes/set_implementation.rb | 2 +- lib/register/register_reference.rb | 2 +- lib/virtual/passes/send_implementation.rb | 5 +++-- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/arm/passes/get_implementation.rb b/lib/arm/passes/get_implementation.rb index 7099178f..0e7e12bb 100644 --- a/lib/arm/passes/get_implementation.rb +++ b/lib/arm/passes/get_implementation.rb @@ -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 diff --git a/lib/arm/passes/set_implementation.rb b/lib/arm/passes/set_implementation.rb index 939b7e8f..200d78cd 100644 --- a/lib/arm/passes/set_implementation.rb +++ b/lib/arm/passes/set_implementation.rb @@ -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 diff --git a/lib/register/builtin/kernel.rb b/lib/register/builtin/kernel.rb index 6d1cf407..265467d2 100644 --- a/lib/register/builtin/kernel.rb +++ b/lib/register/builtin/kernel.rb @@ -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) diff --git a/lib/register/passes/frame_implementation.rb b/lib/register/passes/frame_implementation.rb index 604ad553..b0f5187a 100644 --- a/lib/register/passes/frame_implementation.rb +++ b/lib/register/passes/frame_implementation.rb @@ -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 ) diff --git a/lib/register/passes/set_implementation.rb b/lib/register/passes/set_implementation.rb index f66c02ae..8675fd83 100644 --- a/lib/register/passes/set_implementation.rb +++ b/lib/register/passes/set_implementation.rb @@ -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 diff --git a/lib/register/register_reference.rb b/lib/register/register_reference.rb index eb1fcbeb..a4f3020f 100644 --- a/lib/register/register_reference.rb +++ b/lib/register/register_reference.rb @@ -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. diff --git a/lib/virtual/passes/send_implementation.rb b/lib/virtual/passes/send_implementation.rb index 181cdfae..fec3254e 100644 --- a/lib/virtual/passes/send_implementation.rb +++ b/lib/virtual/passes/send_implementation.rb @@ -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