Class: SFRP::Raw::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/sfrp/raw/set.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Set

Returns a new instance of Set.



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

def initialize(&block)
  @infixies = []
  @inits = []
  @prim_tconsts = []
  @output_node_strs = []
  @vconst_h = {}
  @func_h = {}
  @tconst_h = {}
  @node_h = {}
  block.call(self) if block
  vconst_refs.each { |vr| append_literal_vconst(vr.relative_name) }
end

Instance Method Details

#<<(element) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sfrp/raw/set.rb', line 33

def <<(element)
  case element
  when Function
    @func_h[element.absolute_name] = element
  when TConst
    @tconst_h[element.absolute_name] = element
    element.vconsts.each { |v| @vconst_h[v.absolute_name] = v }
  when PrimTConst
    @tconst_h[element.absolute_name] = element
    @prim_tconsts << element
  when Node
    @node_h[element.absolute_name] = element
  when Output
    self << element.convert
    @output_node_strs << element.absolute_name
  when Input
    self << element.convert
  when Infix
    @infixies << element
  when Init
    @inits << element
  else
    raise
  end
end

#func(ns, func_ref, sp) ⇒ Object



67
68
69
# File 'lib/sfrp/raw/set.rb', line 67

def func(ns, func_ref, sp)
  resolve(ns, func_ref, @func_h, sp)
end

#node(ns, node_ref, sp) ⇒ Object



75
76
77
# File 'lib/sfrp/raw/set.rb', line 75

def node(ns, node_ref, sp)
  resolve(ns, node_ref, @node_h, sp)
end

#tconst(ns, tconst_ref, sp) ⇒ Object



79
80
81
# File 'lib/sfrp/raw/set.rb', line 79

def tconst(ns, tconst_ref, sp)
  resolve(ns, tconst_ref, @tconst_h, sp)
end

#to_flatObject



23
24
25
26
27
28
29
30
31
# File 'lib/sfrp/raw/set.rb', line 23

def to_flat
  Flat::Set.new do |dest_set|
    [
      @func_h, @tconst_h, @vconst_h, @node_h
    ].flat_map(&:values).each { |e| e.gen_flat(self, dest_set) }
    @inits.each { |i| i.gen_flat(self, dest_set) }
    @output_node_strs.each { |s| dest_set.append_output_node_str(s) }
  end
end

#vconst(ns, vconst_ref, sp) ⇒ Object



71
72
73
# File 'lib/sfrp/raw/set.rb', line 71

def vconst(ns, vconst_ref, sp)
  resolve(ns, vconst_ref, @vconst_h, sp)
end

#weakest_op_position(ns, func_refs, sp) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/sfrp/raw/set.rb', line 59

def weakest_op_position(ns, func_refs, sp)
  ab_func_names = func_refs.map { |fr| func(ns, fr, sp).absolute_name }
  infix_h = Hash[@infixies.map { |i| [i.absolute_func_name(self), i] }]
  ab_func_names.each_with_index.map do |x, idx|
    [(infix_h.key?(x) ? infix_h[x].absolute_priority(idx) : [0, 0]), idx]
  end.min[1]
end