Class: Verneuil::Compiler

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

Overview

Compiles verneuil code into a program.

Defined Under Namespace

Classes: Visitor

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompiler

Returns a new instance of Compiler.



7
8
9
# File 'lib/verneuil/compiler.rb', line 7

def initialize
  @generator = Verneuil::Generator.new
end

Class Method Details

.compile(*args) ⇒ Object



15
16
17
18
# File 'lib/verneuil/compiler.rb', line 15

def self.compile(*args)
  new.
    tap { |compiler| compiler.compile(*args) }
end

Instance Method Details

#compile(code) ⇒ Object

Compiles a piece of code within the current program. This means that any method definitions that have already been encountered will be used to resolve method calls. Returns the program which can also be accessed using #program on the compiler instance.



25
26
27
28
29
30
31
32
33
34
# File 'lib/verneuil/compiler.rb', line 25

def compile(code)
  parser = RubyParser.new
  sexp = parser.parse(code)
  # pp sexp
  
  visitor   = Visitor.new(@generator, self)
  visitor.visit(sexp)
  
  @generator.program
end

#programObject



11
12
13
# File 'lib/verneuil/compiler.rb', line 11

def program
  @generator.program
end