Class: MilkTea::ControlFlow::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/milk_tea/core/control_flow/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(ignore_name: nil, binding_resolution: nil, strict_binding_ids: false, local_decl_without_initializer_writes: false) ⇒ Builder

Returns a new instance of Builder.



6
7
8
9
10
11
# File 'lib/milk_tea/core/control_flow/builder.rb', line 6

def initialize(ignore_name: nil, binding_resolution: nil, strict_binding_ids: false, local_decl_without_initializer_writes: false)
  @ignore_name = ignore_name || ->(_name) { false }
  @binding_resolution = binding_resolution
  @strict_binding_ids = strict_binding_ids
  @local_decl_without_initializer_writes = local_decl_without_initializer_writes
end

Instance Method Details

#build(stmts) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/milk_tea/core/control_flow/builder.rb', line 13

def build(stmts)
  @graph = Graph.new
  @graph.exit_id = @graph.add_node(kind: :exit)
  @graph.entry_id = build_block(stmts || [], @graph.exit_id, break_target: nil, continue_target: nil)
  @graph
ensure
  @graph = nil
end

#build_loop_body(stmts) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/milk_tea/core/control_flow/builder.rb', line 22

def build_loop_body(stmts)
  @graph = Graph.new
  @graph.exit_id  = @graph.add_node(kind: :exit)         # fall-through (back-edge)
  break_exit_id   = @graph.add_node(kind: :break_exit)   # break target
  @graph.entry_id = build_block(stmts || [], @graph.exit_id, break_target: break_exit_id, continue_target: @graph.exit_id)
  @graph
ensure
  @graph = nil
end

#build_loop_branch(stmts) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/milk_tea/core/control_flow/builder.rb', line 32

def build_loop_branch(stmts)
  @graph = Graph.new
  @graph.exit_id       = @graph.add_node(kind: :exit)
  break_exit_id        = @graph.add_node(kind: :break_exit)
  continue_exit_id     = @graph.add_node(kind: :continue_exit)
  @graph.entry_id      = build_block(
    stmts || [],
    @graph.exit_id,
    break_target:   break_exit_id,
    continue_target: continue_exit_id,
  )
  @graph
ensure
  @graph = nil
end