Class: Kumi::Core::Analyzer::Passes::ConstantFoldingPass

Inherits:
PassBase
  • Object
show all
Defined in:
lib/kumi/core/analyzer/passes/constant_folding_pass.rb

Constant Summary collapse

NAST =
Kumi::Core::NAST

Instance Method Summary collapse

Methods inherited from PassBase

#debug, #debug_enabled?, #initialize

Methods included from ErrorReporting

#inferred_location, #raise_localized_error, #raise_syntax_error, #raise_type_error, #report_enhanced_error, #report_error, #report_semantic_error, #report_syntax_error, #report_type_error

Constructor Details

This class inherits a constructor from Kumi::Core::Analyzer::Passes::PassBase

Instance Method Details

#run(_errors) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kumi/core/analyzer/passes/constant_folding_pass.rb', line 10

def run(_errors)
  nast_module = get_state(:nast_module, required: true)
  order = get_state(:evaluation_order, required: true)
  @registry = get_state(:registry, required: true)

  debug "\n[FOLD] Starting constant folding pass..."

  folder = Folder.new(self, nast_module, order, @registry)
  optimized_module, changed = folder.fold

  if changed
    debug "[FOLD] Pass made changes."
  else
    debug "[FOLD] Pass made no changes. Nothing to do."
  end

  # Always update the state, as the pass returns a new module object.
  state.with(:nast_module, optimized_module)
end