Class: Kumi::Core::Analyzer::Passes::NormalizeToNASTPass

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

Constant Summary collapse

NAST =
Kumi::Core::NAST
SELECT_ID =
Kumi::RegistryV2::SELECT_ID

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



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

def run(errors)
  decls = get_state(:declarations)
  order = get_state(:evaluation_order)
  @index_table = get_state(:index_table)
  @registry = get_state(:registry)

  nast_decls = {}
  order.each do |name|
    ast = decls[name] or next
    body = normalize_expr(ast.expression, errors)
    nast_decls[name] = NAST::Declaration.new(name: name, body: body, loc: ast.loc, meta: { kind: ast.kind })
  end

  nast = NAST::Module.new(decls: nast_decls)
  debug "NAST decl keys: #{nast.decls.keys.inspect}"
  state.with(:nast_module, nast)
end