class Tataru::InstructionHash

representation of a set of instructions

Public Class Methods

new(thehash) click to toggle source
# File lib/tataru/instruction_hash.rb, line 6
def initialize(thehash)
  @thehash = thehash
end

Public Instance Methods

init_instruction() click to toggle source
# File lib/tataru/instruction_hash.rb, line 42
def init_instruction
  init = Tataru::Instructions::InitInstruction.new

  inithash = @thehash[:init]
  if inithash
    %i[remote_ids outputs deleted rom labels].each do |member|
      init.send(:"#{member}=", inithash[member]) if inithash.key? member
    end
  end
  init
end
instruction_for(action) click to toggle source
# File lib/tataru/instruction_hash.rb, line 33
def instruction_for(action)
  instr_const = "#{action}_instruction".camelize
  unless Tataru::Instructions.const_defined? instr_const
    raise "Unknown instruction '#{action}'"
  end

  Tataru::Instructions.const_get(instr_const)
end
instruction_list() click to toggle source
# File lib/tataru/instruction_hash.rb, line 10
def instruction_list
  @instruction_list ||= instructions
end
instructions() click to toggle source
# File lib/tataru/instruction_hash.rb, line 18
def instructions
  return [] unless @thehash[:instructions]

  @thehash[:instructions].map do |action|
    if action == :init
      init_instruction
    elsif action.is_a? Hash
      # immediate mode instruction
      instruction_for(action.keys[0]).new(action.values[0])
    else
      instruction_for(action).new
    end
  end.to_a
end
to_h() click to toggle source
# File lib/tataru/instruction_hash.rb, line 14
def to_h
  @thehash
end