Class: SFRP::Mono::Node

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

Defined Under Namespace

Classes: NodeRef

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str, type_str, node_refs, eval_func_str, init_func_str = nil) ⇒ Node

Returns a new instance of Node.



8
9
10
11
12
13
14
15
16
# File 'lib/sfrp/mono/node.rb', line 8

def initialize(
  str, type_str, node_refs, eval_func_str, init_func_str = nil
)
  @str = str
  @type_str = type_str
  @node_refs = node_refs
  @eval_func_str = eval_func_str
  @init_func_str = init_func_str
end

Instance Attribute Details

#strObject (readonly)

Returns the value of attribute str.



6
7
8
# File 'lib/sfrp/mono/node.rb', line 6

def str
  @str
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
# File 'lib/sfrp/mono/node.rb', line 22

def ==(other)
  comp == other.comp
end

#compObject



18
19
20
# File 'lib/sfrp/mono/node.rb', line 18

def comp
  [@str, @type_str, @node_refs, @eval_func_str, @init_func_str]
end

#gen_evaluate_stmt(set, stmts) ⇒ Object

Generate ststement to evaluate this node.



85
86
87
88
89
90
91
92
# File 'lib/sfrp/mono/node.rb', line 85

def gen_evaluate_stmt(set, stmts)
  arg_exps = @node_refs.map do |node_ref|
    n = set.node(node_ref.node_str)
    node_ref.last ? n.low_node_ref_last_str : n.low_node_ref_current_str
  end
  call_exp = set.func(@eval_func_str).low_call_exp(arg_exps)
  stmts << L.stmt("#{low_node_ref_current_str} = #{call_exp}")
end

#gen_initialize_stmt(set, stmts) ⇒ Object

Generate a statement of initialization if needed.



71
72
73
74
75
# File 'lib/sfrp/mono/node.rb', line 71

def gen_initialize_stmt(set, stmts)
  return unless initialized?
  call_exp = set.func(@init_func_str).low_call_exp([])
  stmts << L.stmt("#{low_node_str}[l] = #{call_exp}")
end

#gen_node_var_declaration(set, stmts) ⇒ Object

Generate declaration for variable to hold value of node.



78
79
80
81
82
# File 'lib/sfrp/mono/node.rb', line 78

def gen_node_var_declaration(set, stmts)
  type = set.type(@type_str)
  size = (initialized? ? '2' : '1')
  stmts << L.stmt("#{type.low_type_str} #{low_node_str}[#{size}]")
end

#gen_node_var_mark_stmt(set, stmts) ⇒ Object

Generate statement to mark node.



95
96
97
98
99
100
# File 'lib/sfrp/mono/node.rb', line 95

def gen_node_var_mark_stmt(set, stmts)
  return unless initialized?
  return unless set.type(@type_str).need_mark?(set)
  mark_func_str = set.type(@type_str).low_mark_func_str
  stmts << L.stmt("#{mark_func_str}(#{low_node_str}[l])")
end

#initialized?Boolean

Is this node initialized?

Returns:

  • (Boolean)


27
28
29
# File 'lib/sfrp/mono/node.rb', line 27

def initialized?
  @init_func_str
end

#low_node_ref_current_strObject

Return referrence name of current evaluated value of this node.



50
51
52
53
# File 'lib/sfrp/mono/node.rb', line 50

def low_node_ref_current_str
  index = (initialized? ? 'c' : '0')
  "#{low_node_str}[#{index}]"
end

#low_node_ref_last_strObject

Return referrence name of last evaluated value of this node.



56
57
58
# File 'lib/sfrp/mono/node.rb', line 56

def low_node_ref_last_str
  "#{low_node_str}[l]"
end

#low_node_strObject

Name of variable to hold current and last evaluated value of this node.



32
33
34
# File 'lib/sfrp/mono/node.rb', line 32

def low_node_str
  @str
end

#memory_used_to_eval_node(set) ⇒ Object



36
37
38
# File 'lib/sfrp/mono/node.rb', line 36

def memory_used_to_eval_node(set)
  set.func(@eval_func_str).memory(set)
end

#memory_used_to_hold_node(set) ⇒ Object



45
46
47
# File 'lib/sfrp/mono/node.rb', line 45

def memory_used_to_hold_node(set)
  set.type(@type_str).memory(set)
end

#memory_used_to_init_node(set) ⇒ Object



40
41
42
43
# File 'lib/sfrp/mono/node.rb', line 40

def memory_used_to_init_node(set)
  return Memory.empty unless initialized?
  set.func(@init_func_str).memory(set)
end

#sorted_node_strs(set) ⇒ Object

Return a list of nodes sorted by evaluation-order including this node. The list includes only nodes (recursively) depended by this node. So if you want to get a list including all nodes, you must call this method for an output node.



64
65
66
67
68
# File 'lib/sfrp/mono/node.rb', line 64

def sorted_node_strs(set)
  cur = current_referred_node_strs(set)
  last = last_referred_node_strs(set)
  cur + (last - cur)
end