<commit_before>
module Register
  # This implements setting of the various slot variables the vm defines.
  # Basic mem moves, but have to shuffle the type nibbles (TODO!)

  class SetImplementation
    def run block
      block.codes.dup.each do |code|
        next unless code.is_a? Virtual::Set
        # need a temporay place because of indexed load/store
        tmp = Register.tmp_reg
        # for constants we have to "move" the constants value
        if( code.from.is_a?(Parfait::Value) or code.from.is_a?(Symbol))
          move1 = LoadConstant.new(code, code.from , tmp )
        else # while otherwise we "load"
          move1 = Register.get_slot(code, code.from.object_name , get_index(code.from) , tmp )
        end
        move2 = Register.set_slot( code , tmp , code.to.object_name , get_index(code.to) )
        block.replace(code , [move1,move2] )
      end
    end

    def get_index from
      case from
      when Virtual::Self , Virtual::NewSelf
        return Register.resolve_index( :message , :receiver)
      when Virtual::MessageName , Virtual::NewMessageName
        return Register.resolve_index( :message , :name)
      when Virtual::Return
        return Register.resolve_index( :message , :return_value)
      when Virtual::NewArgSlot
        puts "from: #{from.index}"
        return Register.resolve_index( :message , :name) + from.index
      else
        raise "not implemented for #{from.class}"
      end
    end
  end
  Virtual.machine.add_pass "Register::SetImplementation"
end
<commit_msg>add fixnum as constant (was buggy)<commit_after>
module Register
  # This implements setting of the various slot variables the vm defines.

  class SetImplementation
    def run block
      block.codes.dup.each do |code|
        next unless code.is_a? Virtual::Set
        # need a temporay place because of indexed load/store
        tmp = Register.tmp_reg
        # for constants we have to "move" the constants value
        if( code.from.is_a?(Parfait::Value) or code.from.is_a?(Symbol) or code.from.is_a?(Fixnum) )
          move1 = LoadConstant.new(code, code.from , tmp )
        else # while otherwise we "load"
          #puts "from #{code.from}"
          move1 = Register.get_slot(code, code.from.object_name , get_index(code.from) , tmp )
        end
        #puts "to #{code.to}"
        move2 = Register.set_slot( code , tmp , code.to.object_name , get_index(code.to) )
        block.replace(code , [move1,move2] )
      end
    end

    def get_index from
      case from
      when Virtual::Self , Virtual::NewSelf
        return Register.resolve_index( :message , :receiver)
      when Virtual::MessageName , Virtual::NewMessageName
        return Register.resolve_index( :message , :name)
      when Virtual::Return
        return Register.resolve_index( :message , :return_value)
      when Virtual::NewArgSlot
        #puts "from: #{from.index}"
        return Register.resolve_index( :message , :name) + from.index
      else
        raise "not implemented for #{from.class}"
      end
    end
  end
  Virtual.machine.add_pass "Register::SetImplementation"
end

{'fraction_non_alphanumeric': 0.0953757225433526, 'fraction_numerical': 0.0032113037893384713, 'mean_word_length': 2.677685950413223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7237056', 'n_tokens_mistral': 908, 'n_tokens_neox': 904, 'n_words': 266}