Module: Tataru::RomReader

Included in:
Instructions::RescmpInstruction, Instructions::ValueRomInstruction
Defined in:
lib/tataru/rom_reader.rb

Overview

Reads Rom values

Instance Method Summary collapse

Instance Method Details

#resolve(object) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tataru/rom_reader.rb', line 10

def resolve(object)
  case object[:type]
  when :literal
    object[:value]
  when :hash
    resolve_hash(object)
  when :array
    resolve_array(object)
  when :output
    resolve_output(object)
  end
end

#resolve_array(object) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/tataru/rom_reader.rb', line 23

def resolve_array(object)
  result = []
  object[:references].each do |k, v|
    result[k] = resolve(rom[v])
  end
  result
end

#resolve_hash(object) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/tataru/rom_reader.rb', line 31

def resolve_hash(object)
  result = {}
  object[:references].each do |k, v|
    result[k] = resolve(rom[v])
  end
  result
end

#resolve_output(object) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/tataru/rom_reader.rb', line 39

def resolve_output(object)
  if object[:output] == :remote_id
    memory.hash[:remote_ids][object[:resource]]
  else
    memory.hash[:outputs][object[:resource]][object[:output]]
  end
end

#romObject



6
7
8
# File 'lib/tataru/rom_reader.rb', line 6

def rom
  memory.hash[:rom]
end