Class: Mirah::Compiler::ASTCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/mirah/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, compiler_class, logging) ⇒ ASTCompiler

Returns a new instance of ASTCompiler.



19
20
21
22
23
# File 'lib/mirah/compiler.rb', line 19

def initialize(config, compiler_class, logging)
  @config = config
  @compiler_class = compiler_class
  @logging = logging
end

Instance Attribute Details

#compilerObject

Returns the value of attribute compiler.



25
26
27
# File 'lib/mirah/compiler.rb', line 25

def compiler
  @compiler
end

#compiler_classObject

Returns the value of attribute compiler_class.



25
26
27
# File 'lib/mirah/compiler.rb', line 25

def compiler_class
  @compiler_class
end

#loggingObject

Returns the value of attribute logging.



25
26
27
# File 'lib/mirah/compiler.rb', line 25

def logging
  @logging
end

Instance Method Details

#compile_ast(ast, scoper, typer, &block) ⇒ Object



39
40
41
42
43
# File 'lib/mirah/compiler.rb', line 39

def compile_ast(ast, scoper, typer, &block)
  @compiler = compiler_class.new(@config, scoper, typer)
  compiler.visit(ast, nil)
  compiler.generate(&block)
end

#compile_asts(nodes, scoper, typer) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mirah/compiler.rb', line 27

def compile_asts(nodes, scoper, typer)
  results = []
  puts "Compiling..." if logging
  nodes.each do |ast|
    puts "  #{ast.position.source.name}" if logging
    compile_ast(ast, scoper, typer) do |filename, builder|
      results << CompilerResult.new(filename, builder.class_name, builder.generate)
    end
  end
  results
end