<commit_before>require './lib/actionmap'

class Action

  attr_reader :callon, :op, :block

  def initialize callon, op, &block
    @callon, @op = callon, op
    @block = block
  end

  def run
    @block.call( @callon )
  end

end

class ActionSet < Array

  attr_reader :vm, :setup_done

  def initialize( vm )
    @vm = vm
    @setup_done = false
  end

  def actionsetup( key, &block )
    self << Action.new( @vm, key, &block )
  end

  def setup!
    ACTIONMAP.each_pair do |key, block|
      actionsetup( key, &block )
    end

    @setup_done = true
  end

  def run opcode
    raise "ActionSet was not setup!" unless @setup_done

    operation = ByteCode.opcodes_inverted[ opcode & ByteCode.op_mask ]
    action = self.find() { |action| action.op == operation }
    if action.nil?
      puts "An Error: operation: \"#{operation}\", opcode: \"#{opcode}\""
      raise VirtualMachine::InvalidProgram, "Don't understand the opcode %b" % opcode
    else
      action.run() 
    end
  end
end<commit_msg>shortened<commit_after>require './lib/actionmap'

class Action

  attr_reader :callon, :op, :block

  def initialize callon, op, &block
    @callon, @op = callon, op
    @block = block
  end

  def run
    @block.call( @callon )
  end

end

class ActionSet < Array

  attr_reader :vm, :setup_done

  def initialize( vm )
    @vm = vm
    @setup_done = false
  end

  def setup!
    ACTIONMAP.each_pair { |key, block| self << Action.new( @vm, key, &block ) }
    @setup_done = true
  end

  def run opcode
    raise "ActionSet was not setup!" unless @setup_done

    operation = ByteCode.opcodes_inverted[ opcode & ByteCode.op_mask ]
    action = self.find() { |action| action.op == operation }
    if action.nil?
      puts "An Error: operation: \"#{operation}\", opcode: \"#{opcode}\""
      raise VirtualMachine::InvalidProgram, "Don't understand the opcode %b" % opcode
    else
      action.run() 
    end
  end
end
{'fraction_non_alphanumeric': 0.11728074727555786, 'fraction_numerical': 0.0, 'mean_word_length': 2.848303393213573, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2826441', 'n_tokens_mistral': 662, 'n_tokens_neox': 649, 'n_words': 197}