Class: Tataru::InstructionHash
- Inherits:
-
Object
- Object
- Tataru::InstructionHash
- Defined in:
- lib/tataru/instruction_hash.rb
Overview
representation of a set of instructions
Instance Method Summary collapse
- #init_instruction ⇒ Object
-
#initialize(thehash) ⇒ InstructionHash
constructor
A new instance of InstructionHash.
- #instruction_for(action) ⇒ Object
- #instruction_list ⇒ Object
- #instructions ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(thehash) ⇒ InstructionHash
Returns a new instance of InstructionHash.
6 7 8 |
# File 'lib/tataru/instruction_hash.rb', line 6 def initialize(thehash) @thehash = thehash end |
Instance Method Details
#init_instruction ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# 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) ⇒ Object
33 34 35 36 37 38 39 40 |
# 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 ⇒ Object
10 11 12 |
# File 'lib/tataru/instruction_hash.rb', line 10 def instruction_list @instruction_list ||= instructions end |
#instructions ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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 ⇒ Object
14 15 16 |
# File 'lib/tataru/instruction_hash.rb', line 14 def to_h @thehash end |