Class: SFRP::Mono::Set

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Set

Returns a new instance of Set.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sfrp/mono/set.rb', line 14

def initialize(&block)
  @func_h = {}
  @node_h = {}
  @type_h = {}
  @vconst_h = {}
  @output_node_strs = []
  @init_func_strs = []
  @type_alias_h = {}
  @constructor_alias_h = {}
  block.call(self) if block
end

Instance Method Details

#<<(element) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sfrp/mono/set.rb', line 62

def <<(element)
  case element
  when Function
    @func_h[element.str] = element
  when Node
    @node_h[element.str] = element
  when Type
    @type_h[element.str] = element
  when VConst
    @vconst_h[element.str] = element
  else
    raise
  end
end

#append_init_func_str(init_func_str) ⇒ Object



81
82
83
# File 'lib/sfrp/mono/set.rb', line 81

def append_init_func_str(init_func_str)
  @init_func_strs << init_func_str
end

#append_output_node_str(output_node_str) ⇒ Object



77
78
79
# File 'lib/sfrp/mono/set.rb', line 77

def append_output_node_str(output_node_str)
  @output_node_strs << output_node_str
end

#checkObject



41
42
43
44
# File 'lib/sfrp/mono/set.rb', line 41

def check
  # TODO: Check that all init_func does not waste any memory.
  # TODO: Check completeness of pattern matchings.
end

#func(func_str) ⇒ Object



85
86
87
88
# File 'lib/sfrp/mono/set.rb', line 85

def func(func_str)
  raise func_str unless @func_h.key?(func_str)
  @func_h[func_str]
end

#funcsObject



105
106
107
# File 'lib/sfrp/mono/set.rb', line 105

def funcs
  @func_h.values
end

#memory(type_str) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sfrp/mono/set.rb', line 46

def memory(type_str)
  @memory ||= begin
    to_init_nodes = nodes.reduce(Memory.empty) do |m, node|
      m.and(node.memory_used_to_init_node(self))
    end
    to_hold_memoized_nodes = nodes.reduce(Memory.empty) do |m, node|
      node.initialized? ? m.and(node.memory_used_to_hold_node(self)) : m
    end
    to_eval_nodes = nodes.reduce(Memory.empty) do |m, node|
      m.and(node.memory_used_to_eval_node(self))
    end
    to_hold_memoized_nodes.and(to_eval_nodes).or(to_init_nodes)
  end
  @memory.count(type_str)
end

#node(node_str) ⇒ Object



90
91
92
93
# File 'lib/sfrp/mono/set.rb', line 90

def node(node_str)
  raise node_str unless @node_h.key?(node_str)
  @node_h[node_str]
end

#nodesObject



109
110
111
# File 'lib/sfrp/mono/set.rb', line 109

def nodes
  @node_h.values
end

#to_low(include_file_strs = []) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sfrp/mono/set.rb', line 26

def to_low(include_file_strs = [])
  Low::Set.new do |low_set|
    include_file_strs.each { |s| low_set << L.include_dq(s) }
    @type_alias_h.each do |alias_str, original_str|
      low_set << type(original_str).low_typedef_for_alias(alias_str)
    end
    @constructor_alias_h.each do |alias_str, original_str|
      low_set << vconst(original_str).low_macro_for_alias(alias_str)
    end
    @func_h.values.each { |func| func.gen(self, low_set) }
    @type_h.values.each { |type| type.gen(self, low_set) }
    gen_main_func(low_set)
  end
end

#type(type_str) ⇒ Object



95
96
97
98
# File 'lib/sfrp/mono/set.rb', line 95

def type(type_str)
  raise type_str unless @type_h.key?(type_str)
  @type_h[type_str]
end

#typesObject



113
114
115
# File 'lib/sfrp/mono/set.rb', line 113

def types
  @type_h.values
end

#vconst(vconst_str) ⇒ Object



100
101
102
103
# File 'lib/sfrp/mono/set.rb', line 100

def vconst(vconst_str)
  raise vconst_str unless @vconst_h.key?(vconst_str)
  @vconst_h[vconst_str]
end

#vconstsObject



117
118
119
# File 'lib/sfrp/mono/set.rb', line 117

def vconsts
  @vconst_h.values
end