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(compiler_class, logging) ⇒ ASTCompiler

Returns a new instance of ASTCompiler.



28
29
30
31
# File 'lib/mirah/compiler.rb', line 28

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

Instance Attribute Details

#compiler_classObject

Returns the value of attribute compiler_class.



33
34
35
# File 'lib/mirah/compiler.rb', line 33

def compiler_class
  @compiler_class
end

#loggingObject

Returns the value of attribute logging.



33
34
35
# File 'lib/mirah/compiler.rb', line 33

def logging
  @logging
end

Instance Method Details

#compile_ast(ast, &block) ⇒ Object



47
48
49
50
51
# File 'lib/mirah/compiler.rb', line 47

def compile_ast(ast, &block)
  compiler = compiler_class.new
  ast.compile(compiler, false)
  compiler.generate(&block)
end

#compile_asts(nodes) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mirah/compiler.rb', line 35

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